Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions docs/auth/federated-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,25 @@ with the Facebook App ID and Secret set.

Future<UserCredential> signInWithFacebook() async {
// Trigger the sign-in flow
final rawNonce = _generateRandomString(); // You should implement this function
final nonce = _sha256ofString(rawNonce); // You should implement this function
final LoginResult loginResult = await FacebookAuth.instance.login();

// Create a credential from the access token
final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken.token);
OAuthCredential? facebookAuthCredential;
if (loginResult.accessToken is LimitedToken) {
facebookAuthCredential = OAuthCredential(
providerId: 'facebook.com',
signInMethod: 'oauth',
idToken: loginResult.accessToken.tokenString,
rawNonce: rawNonce,
);
} else {
facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken.token);
}

// Once signed in, return the UserCredential
return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential!);
}
```

Expand Down