Firebase 身份验证尝试使用 Apple 的身份令牌会在 Xamarin.iOS 应用程序中返回 17999 INVALID_CREDENTIAL_OR_PROVIDER_ID

Dre*_*ile 3 ios firebase xamarin firebase-authentication apple-sign-in

我使用Xamarin.Firebase.iOS.Auth和 Apple AuthenticationServicesApple 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);
Run Code Online (Sandbox Code Playgroud)

我收到了以下详细信息的异常:

(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;
        }
    );
Run Code Online (Sandbox Code Playgroud)

起初我认为该令牌无效,但后来我尝试在本机 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
})
Run Code Online (Sandbox Code Playgroud)

本机应用程序和 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)
Run Code Online (Sandbox Code Playgroud)

是否可能是 Xamarin 提供的过时版本存在问题,或者可能存在特定于 Xamarin.iOS 应用程序的其他配置问题?

Dre*_*ile 5

事实证明,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);
Run Code Online (Sandbox Code Playgroud)

所以我改成了另一个重载并且效果很好:

var credentials = OAuthProvider.GetCredential("apple.com", IdToken: idTokenString, accessToken: null);
Run Code Online (Sandbox Code Playgroud)