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

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 and 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 示例中使用之前收到的完全相同的令牌(copy/pasted 来自 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);