Skip to content

Commit ce23503

Browse files
Update federated-auth.md for Facebook limited login
1 parent d41e30a commit ce23503

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

docs/auth/federated-auth.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,25 @@ with the Facebook App ID and Secret set.
136136
137137
Future<UserCredential> signInWithFacebook() async {
138138
// Trigger the sign-in flow
139+
final rawNonce = _generateRandomString();
140+
final nonce = sha256ofString(rawNonce);
139141
final LoginResult loginResult = await FacebookAuth.instance.login();
140142
141143
// Create a credential from the access token
142-
final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken.token);
144+
OAuthCredential? facebookAuthCredential;
145+
if (loginResult.accessToken is LimitedToken) {
146+
facebookAuthCredential = OAuthCredential(
147+
providerId: 'facebook.com',
148+
signInMethod: 'oauth',
149+
idToken: loginResult.accessToken.tokenString,
150+
rawNonce: rawNonce,
151+
);
152+
} else {
153+
facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken.token);
154+
}
143155
144156
// Once signed in, return the UserCredential
145-
return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
157+
return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential!);
146158
}
147159
```
148160

0 commit comments

Comments
 (0)