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

Flutter中Firebase Apple登录iOS正常,Android报invalid-credential错误

Android Firebase Apple登录 invalid-credential 错误排查方案

问题重现

使用以下Flutter代码触发Apple登录:

Future<UserCredential> signInWithApple() async {
 final appleProvider = AppleAuthProvider();
 appleProvider.addScope('email');
 // appleProvider.setCustomParameters({
 //   'client_id': 'com......firebase', // service ID
 // }); // client_id is reserved
 return await FirebaseAuth.instance.signInWithProvider(appleProvider);
}

在Android设备上登录流程看似正常完成,但返回App后抛出FirebaseAuthException,错误码为invalid-credential,错误信息包含HttpMetadata{status=400...}。已核对Apple开发者后台的密钥、服务配置,以及Firebase的回调域名,但问题持续存在。取消登录时的web-context-canceled为正常现象。

可能的解决步骤

  • 严格匹配Apple服务ID的回调URL
    确保Apple开发者后台中服务ID的“返回URL”与Firebase提供的OAuth回调地址完全一致,格式为https://<你的项目ID>.firebaseapp.com/__/auth/handler,注意大小写、斜杠等细节,不能有任何差异。
  • 验证Apple登录密钥配置
    检查Firebase控制台Apple登录配置中,上传的密钥是否开启了“Sign in with Apple”权限,密钥ID、团队ID需与Apple开发者后台完全匹配,无拼写错误。
  • 完善AndroidManifest.xml配置
    添加正确的intent-filter处理回调,确保scheme与应用包名一致:
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="com.你的应用包名" />
    </intent-filter>
    
    同时在Apple开发者后台的服务ID配置中,关联该应用包名。
  • 显式配置自定义参数
    取消注释setCustomParameters代码,传入正确的Apple服务ID和Firebase回调地址:
    appleProvider.setCustomParameters({
      'client_id': '你的Apple服务ID',
      'redirect_uri': 'https://<你的项目ID>.firebaseapp.com/__/auth/handler',
    });
    
    部分场景下,显式传递这些参数可解决凭证验证失败问题。
  • 清除缓存
    清除应用数据以及Chrome浏览器缓存,避免旧认证信息残留导致的异常。
  • 检查Firebase OAuth客户端配置
    在Firebase控制台「Authentication」→「登录方法」→「Apple」中,确认已启用Apple登录,所有配置项(团队ID、服务ID、密钥ID)与Apple开发者后台完全一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 08:22:20