首页 > 解决方案 > 尝试在 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 调用?

标签: swiftmacosoauthmac-catalystipados

解决方案


推荐阅读