swift - 尝试在 macOS 催化剂上执行 oauth 时应用程序失败,在 iOS 和 iPadOS 上运行良好
问题描述
我有一个通过 FirebaseAuth 使用身份验证的应用程序,在登录时,它会访问 github 上的身份验证网站(我的应用程序在其中注册)以进行身份验证。回调在 iOS 和 iPadOS 上都能完美运行。我也可以在 MacOS 上编译和运行该应用程序,但是,当我单击登录时,Safari 浏览器会启动,询问权限
"Do you want to allow this page to open <my app name>".
我单击“允许”,但随后我被带回到我在 MacOS 上运行的应用程序,该应用程序弹出一个对话框说
Error, the interaction was cancelled by the user.
好奇是否有人对此有经验以及我需要做什么才能使我的应用程序可以在所有 3 个平台上处理 oauth。
初始化代码如下所示。
import FirebaseAuth
import Firebase
import FirebaseFirestoreSwift
import Alamofire
struct LoginScreen: View {
@Binding var isLoggedIn : Bool
@State var showErrorAlert = false
@State var errorMessage : String = ""
var db = Firestore.firestore()
var provider = OAuthProvider(providerID: "github.com")
var body: some View {
VStack {
Spacer()
Image("octocat").resizable()
.aspectRatio(contentMode: .fit).frame(maxWidth: 150)
.alert(isPresented: $showErrorAlert, content: {
Alert(title: Text("Error"), message: Text(errorMessage), dismissButton: .default(Text("OK")))
})
Spacer()
HStack {
Spacer()
Button {
provider.getCredentialWith(nil) { credential, error in
if let error = error {
errorMessage = error.localizedDescription
showErrorAlert = true
请求 github auth URL 后立即触发此错误。
想知道我是否需要授权我的应用程序以某种方式进行此 URL 调用?
解决方案
推荐阅读
- r - 将 dplyr 代码转换为接受列作为参数的函数
- javascript - 加空格生成新行JS
- docker - Docker 在 Windows 上运行,并且仅在两个 Linux 系统之一上运行
- docker - 如何将本地 postgreSQL 连接到 docker (CVAT)
- r - 如何在不重复的情况下附加新函数并更新 .R 文件中的现有函数
- python - MYSQL 中未定义错误名称值 在系统寄存器中使用 Python
- regex - 正则表达式仅在引号内匹配变量
- visual-studio-code - 如何触发`editor.gotoNextSymbolFromResult`?
- excel - 仅当单元格以某些字符开头时,VBA才会根据字符位置替换字符串的多个部分
- javascript - 为什么 onload 使用远程图像而不是本地图像触发?