Created
April 8, 2020 13:48
-
-
Save sirateek/a3600427b8804183e81ffb97c8505902 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<FirebaseUser> signInWithApple() async { | |
if (await AppleSignIn.isAvailable()) { | |
final AuthorizationResult result = await AppleSignIn.performRequests([ | |
AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName]) | |
]); | |
AuthCredential credential; | |
switch (result.status) { | |
case AuthorizationStatus.authorized: | |
credential = OAuthProvider(providerId: "apple.com").getCredential( | |
idToken: String.fromCharCodes(result.credential.identityToken), | |
accessToken: | |
String.fromCharCodes(result.credential.authorizationCode), | |
); | |
break; | |
case AuthorizationStatus.error: | |
print("Error: " + result.error.localizedDescription); | |
throw PlatformException( | |
code: "SIGN_IN_WITH_APPLE_FAILED", | |
details: result.error.localizedDescription, | |
); | |
break; | |
case AuthorizationStatus.cancelled: | |
print("User Cancelled"); | |
throw PlatformException( | |
code: "USER_CANCELLED_LOGIN", | |
details: "The user calcelled the login process", | |
); | |
break; | |
} | |
return (await _auth.signInWithCredential(credential)).user; | |
} else { | |
print("Unsupported sign in with apple"); | |
throw PlatformException( | |
code: "UNSUPPORTED_SIGN_IN_WITH_APPLE", | |
details: "There is no sign in with apple supported on this device", | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment