Apple 登录错误
我最近遇到了 Apple Sign In 在我的 Flutter 应用程序中不起作用的问题。我输入了我的 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>
我找到的解决方案是我添加的一行代码。
// Request credential for the currently signed in Apple account.
final appleCredential = await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
nonce: nonce,
);
// Create an `OAuthCredential` from the credential returned by Apple.
final oauthCredential = OAuthProvider("apple.com").credential(
idToken: appleCredential.identityToken,
rawNonce: rawNonce,
accessToken: appleCredential.authorizationCode, <-- ADDED THIS LINE
);