You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS集成Firebase Auth微软提供商遇about:blank重定向空白页问题求助

解决iOS 13.2 Firebase微软认证后卡在about:blank的问题

我之前也碰到过iOS 13.x版本上Firebase集成微软OAuth认证后,重定向时卡在about:blank无法返回应用的问题,结合你的配置和代码情况,给你几个针对性的排查和解决方向:

1. 确保URL Scheme与回调处理正确配置

这是最常见的触发原因,Firebase OAuth需要应用正确处理重定向回来的请求:

  • 配置URL Scheme:在项目的Info.plist中,添加CFBundleURLTypes数组,其中包含Firebase项目对应的URL Scheme。格式为com.googleusercontent.apps.你的Firebase项目ID,这个值可以在Firebase控制台的「认证」→「登录方法」→「微软」配置页面找到。
  • 实现回调方法:
    如果你用的是AppDelegate,添加以下代码:
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        if Auth.auth().canHandle(url) {
            return Auth.auth().handleOpen(url, options: options)
        }
        return false
    }
    
    如果你用的是iOS 13+的SceneDelegate,则添加:
    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        guard let url = URLContexts.first?.url else { return }
        if Auth.auth().canHandle(url) {
            Auth.auth().handleOpen(url)
        }
    }
    
    没有正确实现这个回调,Firebase就无法接收认证后的凭证,导致页面卡在about:blank。

2. 修正Azure AD的重定向配置

检查Azure Active Directory中的应用配置:

  • 确保添加的重定向URI是Firebase提供的完整handler地址:https://你的项目ID.firebaseapp.com/__/auth/handler,而不是仅填写*.firebaseapp.com。
  • 在Azure AD应用的「移动和桌面应用」选项中,勾选「允许公共客户端流」——iOS应用属于公共客户端,开启这个选项才能完成OAuth流程的闭环。

3. 优化Firebase认证代码逻辑

你的代码中存在重复的登录与链接操作,可能导致状态混乱:

// 优化后的代码:先判断当前用户状态,再决定登录或链接
if let currentUser = Auth.auth().currentUser {
    // 当前已有用户,链接微软凭证
    currentUser.link(with: credential!) { authResult, error in
        if let error = error {
            print("链接失败:\(error.localizedDescription)")
            return
        }
        print("微软凭证链接成功")
    }
} else {
    // 无当前用户,直接用微软凭证登录
    Auth.auth().signIn(with: credential!) { authResult, error in
        if let error = error {
            print("登录失败:\(error.localizedDescription)")
            return
        }
        print("登录成功,用户信息:\(authResult?.additionalUserInfo?.profile ?? [:])")
    }
}

4. 尝试MSAL直接集成方案

如果Firebase自带的OAuthProvider仍有适配问题,可以直接用MSAL获取token后关联Firebase:

  1. 集成MSAL并完成认证,获取accessToken和idToken
  2. 手动创建Firebase OAuth凭证:
    let credential = OAuthProvider.credential(withProviderID: "microsoft.com", idToken: msalIdToken, accessToken: msalAccessToken)
    
  3. 用这个凭证执行登录或链接操作,这样绕开Firebase的跳转流程,利用MSAL对iOS 13+的更好适配来解决问题。

内容的提问来源于stack exchange,提问作者angri bird

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 07:52:46