
[英]invalid-app-credential/Token mismatch in Flutter firebase_auth
[英]Firebase auth attempt to use an Apple's identity token returns 17999 INVALID_CREDENTIAL_OR_PROVIDER_ID in a Xamarin.iOS app
我正在使用Xamarin.Firebase.iOS.Auth和 Apple AuthenticationServices让用户使用Apple Sign In
,然后使用 Firebase 进行身份验证。 我有一个Xamarin.iOS
应用程序, Apple Sign In
部分没有任何问题,我能够激活Apple Sign In
并从 ASAuthorizationAppleIdCredential 接收有效的身份令牌。 问题出在第二步,当我尝试使用该令牌向 Firebase 进行身份验证时:
var idTokenString = "<my_valid_identity_token_here>";
var credentials = OAuthProvider.GetCredential("apple.com", idTokenString);
var authResult = await Auth.DefaultInstance.SignInWithCredentialAsync(credentials);
我收到以下详细信息的异常:
(Inner Exception #0) Foundation.NSErrorException: Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={FIRAuthErrorUserInfoNameKey=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information., NSUnderlyingError=0x600002c89260 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
code = 400;
errors = (
{
domain = global;
message = "INVALID_CREDENTIAL_OR_PROVIDER_ID : Invalid IdP response/credential: http://localhost?providerId=apple.com&access_token=<my_token_here>";
reason = invalid;
}
);
起初我认为令牌无效,但后来我尝试在我的原生 Swift 示例中使用之前收到的完全相同的令牌(从 xamarin 应用程序复制/粘贴),并且我能够通过 Firebase 进行身份验证而没有任何问题:
let appleIDToken = "<my_valid_identity_token_here>";
let credential = OAuthProvider.credential(
withProviderID: "apple.com",
idToken: appleIDToken,
accessToken: nil)
Auth.auth().signIn(with: credential, completion: { (authResult, error) in
// error = nil!, authResult - OK
})
本机应用程序和 Xamarin 应用程序都是相同的、相同的配置、相同的包 ID、相同的功能。 我发现的唯一区别是组件版本。 Firebase 原生组件是:
FirebaseCore (6.5.0) vs Xamarin.Firebase.iOS.Core (6.1.0)
FirebaseAuth (6.4.1) vs Xamarin.Firebase.iOS.Auth (6.2.1.1)
FirebaseFirestore (1.8.3) vs Xamarin.Firebase.iOS.CloudFirestore (1.4.2.1)
是否有可能是 Xamarin 提供的过时版本中的问题,或者可能存在其他特定于 Xamarin.iOS 应用的配置问题?
原来 Xamarin 组件的版本号与 Google Firebase SDK 不同,Xamarin.Firebase.Core.iOS 6.1.0.0 版本对应于最新的 FirebaseCore 6.5.0:
https://github.com/xamarin/GoogleApisForiOSComponents/blob/master/components.cake#L122
应用程序中的问题与 API 接口定义有关,以下行将 idTokenString 值作为访问令牌传递
var credentials = OAuthProvider.GetCredential("apple.com", idTokenString);
所以我改用另一个重载,效果很好:
var credentials = OAuthProvider.GetCredential("apple.com", IdToken: idTokenString, accessToken: null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.