Skip to content

Commit 06ed29e

Browse files
docs(auth, apple): show how to use credentialWithIDToken() (#12940)
Co-authored-by: Kevin Cheung <[email protected]>
1 parent 39c7a54 commit 06ed29e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/auth/federated-auth.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,33 @@ Future<UserCredential> signInWithApple() async {
224224
}
225225
```
226226

227+
#### Apple platform sign-in only
228+
229+
Apple sign-in on iOS+ platforms can also be achieved with the following method:
230+
231+
```dart
232+
// Implement a function that generates a nonce. See iOS documentation for how to create a nonce:
233+
// https://firebase.google.com/docs/auth/ios/apple#sign_in_with_apple_and_authenticate_with_firebase
234+
String rawNonce = createNonce();
235+
// Create a SHA-256 hash of the nonce. Consider using the `crypto` package from the pub.dev registry.
236+
String hashSHA256String = createHashSHA256String(rawNonce);
237+
// Use the hash of the nonce to get the idToken. Consider using the `sign_in_with_apple` plugin from the pub.dev registry.
238+
String idToken = await getIdToken();
239+
240+
final fullName = AppleFullPersonName(
241+
familyName: 'Name',
242+
givenName: 'Your',
243+
);
244+
// Use the `rawNonce` and `idToken` to get the credential
245+
final credential = AppleAuthProvider.credentialWithIDToken(
246+
idToken,
247+
rawNonce,
248+
fullName,
249+
);
250+
251+
await FirebaseAuth.instance.signInWithCredential(credential);
252+
```
253+
227254
### Revoke Apple auth tokens {:#revoke-apple}
228255

229256
Apple sign-in on Apple platforms returns an authorization code that can be used

0 commit comments

Comments
 (0)