【问题标题】:Swift - Firebase Auth with Microsoft Graph (Redirect URL Problem)Swift - 带有 Microsoft Graph 的 Firebase 身份验证(重定向 URL 问题)
【发布时间】:2019-09-06 06:37:52
【问题描述】:

我在 iOS 应用中将 Firebase 与 Microsoft Auth 集成时遇到问题。

登录页面已启动,我可以使用Office365帐户登录,但由于以下错误无法完成登录验证:

"AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application:[app-id]"

我确实检查了 Firebase 中的设置,以下是我在 Azure Active Directory 的应用程序中添加的设置:

  1. 网页重定向网址:“*.firebaseapp.com/__/auth/handler”
  2. 支持的帐户类型:“任何组织目录中的帐户(任何 Azure AD 目录多租户)”

这是我实现的快速代码:

provider = OAuthProvider(providerID: "microsoft.com")
provider?.customParameters = ["prompt": "consent", 
                              "login_hint": "Login Hint"]

provider?.scopes = ["mail.read", "calendars.read"]

provider?.getCredentialWith(_: nil){ (credential, error) in

    if let credential = credential {

        Auth.auth().signIn(with: credential) { (authResult, error) in
            if let error = error {
                print(error.localizedDescription)
            }
        }
    }
}   

有没有人知道如何解决这个问题或遇到同样的问题?

【问题讨论】:

  • 与您的回复 URL 问题无关(您已经在下面得到了答案):您应该包含 prompt=consent 自定义参数。这会给您的应用程序带来问题。
  • @PhilippeSignoret 如果我包含prompt=consent 会导致什么样的问题? (例如,强制用户提供同意?)
  • 在许多组织中,不允许用户同意。在这些组织中,管理员将代表所有用户同意。但即使管理员已经代表所有用户同意,如果您强制同意 prompt=consent 用户将被阻止(因为不允许他们同意,并且您的应用程序会强制他们重新同意)。只有当您确定您的应用所需的权限尚未被授予时,您才应该使用prompt=consent
  • @PhilippeSignoret 已注意,以后使用时会小心!!非常感谢你提醒我。

标签: ios swift firebase firebase-authentication azure-active-directory


【解决方案1】:

向这些提供商注册应用时,请务必注册 *.firebaseapp.com 域为您的项目作为您应用的重定向域。

您是否已将 * 替换为您的项目名称?您可以在 firebase 控制台的 Authorized Domains 下找到您的授权域。重定向 uri 应该类似于

https://yourFirebaseApp.firebaseapp.com/__/auth/handler

【讨论】:

  • 我确实用我的项目名称替换了 Azure 中的 https://[project_name].firebaseapp.com/__/auth/handler,我可以找到 [project_name].firebaseapp.com在 Firebase 控制台的授权域中,但它不起作用。
  • @LilingChen 能抓到请求的url吗?您将在授权端点中找到 redirect_uri。在这里参考我的回答stackoverflow.com/a/57476562/10504999
  • 我试过了,我确实得到了 redirect_url 的会话如下https://[project_name].firebaseapp.com/__/auth/handler?code=[encoded_info]&state=12345&session_state=[session_state]。这只是我设置的一个,但我的应用程序签名时仍然遇到同样的问题。
  • 我重新开始搭建整个项目,按照你提供的方式确认,成功搞定!!我非常感谢您提供的故障排除方式。
猜你喜欢
  • 2019-11-23
  • 1970-01-01
  • 1970-01-01
  • 2020-04-18
  • 1970-01-01
  • 1970-01-01
  • 2022-08-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多