signInWithApple method
Implementation
Future<UserCredential> signInWithApple({
List<AppleIDAuthorizationScopes> scopes =
const <AppleIDAuthorizationScopes>[
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
}) async {
if (!Platform.isIOS && !Platform.isMacOS) {
throw UnsupportedError(
'Apple sign-in is only supported on iOS & Macos for this app.',
);
}
final rawNonce = _generateNonce();
final nonce = _sha256OfString(rawNonce);
final appleCredential = await SignInWithApple.getAppleIDCredential(
scopes: scopes,
nonce: nonce,
);
if (appleCredential.identityToken == null) {
throw FirebaseAuthException(
code: 'missing-apple-id-token',
message: 'Apple sign-in returned no identityToken.',
);
}
final oauthCredential = _oauthProvider.credential(
idToken: appleCredential.identityToken,
accessToken: appleCredential.authorizationCode,
rawNonce: rawNonce,
);
final userCred = await _auth.signInWithCredential(oauthCredential);
await getFirebaseIdToken();
return userCred;
}