我正在使用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);