Flutter应用Apple登录失败:firebase_auth/invalid-credential错误求助
Flutter Apple登录异常:firebase_auth/invalid-credential 错误解决办法
输入Apple ID和密码后操作看似成功,但控制台抛出如下错误:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_auth/invalid-credential] Invalid OAuth response from apple.com #0 FirebaseAuthHostApi.signInWithCredential (package:firebase_auth_platform_interface/src/pigeon/messages.pigeon.dart:1098:7) <asynchronous suspension> #1 MethodChannelFirebaseAuth.signInWithCredential (package:firebase_auth_platform_interface/src/method_channel/method_channel_firebase_auth.dart:306:22) <asynchronous suspension> #2 FirebaseAuth.signInWithCredential (package:firebase_auth/src/firebase_auth.dart:515:9) <asynchronous suspension> #3 AuthService.signInWithApple (package:parkbestapp/services/auth_service.dart:73:9) <asynchronous suspension>
以下是针对性的解决步骤:
检查Apple开发者账号配置
- 确认Apple开发者后台已开启Sign In with Apple服务,且应用Bundle ID已关联该服务
- 核对Service ID的重定向URI,必须与Firebase控制台中配置的完全一致(通常为
https://你的项目ID.firebaseapp.com/__/auth/handler) - 验证Sign In with Apple专用密钥:确保密钥已启用对应权限,且密钥ID、团队ID已准确填写到Firebase
核对Firebase平台配置
- 进入Firebase控制台的Authentication > 登录方法页面,确认Apple登录已启用,团队ID、服务ID、密钥ID、私钥内容均配置正确
- 确保iOS项目中的
GoogleService-Info.plist是从Firebase控制台最新下载的,包含完整的Apple登录配置字段
排查代码实现逻辑
- 重点检查
signInWithApple方法中的nonce生成与传递逻辑,必须保证生成的rawNonce与传递给Firebase的一致:String generateNonce([int length = 32]) { const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._'; final random = Random.secure(); return List.generate(length, (_) => charset[random.nextInt(charset.length)]).join(); } // 获取Apple凭证时需正确传入rawNonce final appleCredential = OAuthProvider("apple.com").credential( idToken: idToken, rawNonce: rawNonce, ); - 确认没有遗漏Apple登录返回的必要字段,比如idToken必须完整传递给Firebase的credential方法
- 重点检查
验证测试环境与证书
- 使用Apple开发者后台已注册的测试账号进行测试,避免使用未授权的个人Apple ID
- 确保测试设备/模拟器系统版本在iOS 13及以上,该版本才支持Sign In with Apple
- 检查iOS项目签名配置:使用有效的开发者证书或Ad Hoc证书,避免使用过期或未授权的证书
内容的提问来源于stack exchange,提问作者OverdoseB12
相关产品推荐
相关产品推荐

