Skip to content

Commit 1c0f371

Browse files
russellwheatleykevinthecheung
authored andcommitted
feat(auth): revokeTokenWithAuthorizationCode() implementation for revoking Apple sign-in token (#11454)
Co-authored-by: Kevin Cheung <[email protected]>
1 parent a6b9f3e commit 1c0f371

File tree

21 files changed

+772
-355
lines changed

21 files changed

+772
-355
lines changed

docs/auth/federated-auth.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ You can authenticate users in your Android game using Play Games Sign-In.
9797

9898
* {Android}
9999

100-
Follow the instructions for Google setup on Android, then configure
100+
Follow the instructions for Google setup on Android, then configure
101101
[Play Games services with your Firebase app information](https://firebase.google.com/docs/auth/android/play-games#configure-play-games-with-firebase-info).
102102

103103
The following will trigger the sign-in flow, create a new credential and sign in the user:
@@ -232,6 +232,25 @@ Future<UserCredential> signInWithApple() async {
232232
}
233233
```
234234

235+
### Revoke Apple auth tokens
236+
237+
Apple sign-in on Apple platforms will return an authorization code that can be used to revoke the Apple auth token
238+
using the `revokeTokenWithAuthorizationCode()` API.
239+
240+
```dart
241+
import 'package:firebase_auth/firebase_auth.dart';
242+
243+
Future<UserCredential> signInWithApple() async {
244+
final appleProvider = AppleAuthProvider();
245+
246+
UserCredential userCredential = await FirebaseAuth.instance.signInWithPopup(appleProvider);
247+
// Keep the authorization code returned from Apple platforms
248+
String? authCode = userCredential.additionalUserInfo?.authorizationCode;
249+
// Revoke Apple auth token
250+
await FirebaseAuth.instance.revokeTokenWithAuthorizationCode(authCode!);
251+
}
252+
```
253+
235254
## Microsoft
236255

237256
* {iOS+}
@@ -241,7 +260,7 @@ Future<UserCredential> signInWithApple() async {
241260

242261
* {Android}
243262
Before you begin [configure Microsoft Login for Android](/docs/auth/android/microsoft-oauth#before_you_begin).
244-
263+
245264
Don't forget to add your app's SHA-1 fingerprint.
246265

247266
* {Web}
@@ -264,7 +283,7 @@ Future<UserCredential> signInWithMicrosoft() async {
264283
## Twitter
265284

266285
Ensure the "Twitter" sign-in provider is enabled on the [Firebase Console](https://console.firebase.google.com/project/_/authentication/providers)
267-
with an API Key and API Secret set. Ensure your Firebase OAuth redirect URI (e.g. my-app-12345.firebaseapp.com/__/auth/handler)
286+
with an API Key and API Secret set. Ensure your Firebase OAuth redirect URI (e.g. my-app-12345.firebaseapp.com/__/auth/handler)
268287
is set as your Authorization callback URL in your app's settings page on your [Twitter app's config](https://apps.twitter.com/).
269288

270289
You also might need to request elevated [API access depending on your app](https://developer.twitter.com/en/portal/products/elevated).
@@ -275,7 +294,7 @@ You also might need to request elevated [API access depending on your app](https
275294

276295
* {Android}
277296

278-
If you haven't yet specified your app's SHA-1 fingerprint, do so from the [Settings page](https://console.firebase.google.com/project/_/settings/general/)
297+
If you haven't yet specified your app's SHA-1 fingerprint, do so from the [Settings page](https://console.firebase.google.com/project/_/settings/general/)
279298
of the Firebase console. Refer to [Authenticating Your Client](https://developers.google.com/android/guides/client-auth) for details on how to get your app's SHA-1 fingerprint.
280299

281300
* {Web}
@@ -347,7 +366,7 @@ with the Client ID and Secret are set, with the callback URL set in the GitHub a
347366
## Yahoo
348367

349368
Ensure the "Yahoo" sign-in provider is enabled on the [Firebase Console](https://console.firebase.google.com/project/_/authentication/providers)
350-
with an API Key and API Secret set. Also make sure your Firebase OAuth redirect URI (e.g. my-app-12345.firebaseapp.com/__/auth/handler)
369+
with an API Key and API Secret set. Also make sure your Firebase OAuth redirect URI (e.g. my-app-12345.firebaseapp.com/__/auth/handler)
351370
is set as a redirect URI in your app's Yahoo Developer Network configuration.
352371

353372

@@ -358,7 +377,7 @@ is set as a redirect URI in your app's Yahoo Developer Network configuration.
358377

359378
* {Android}
360379
Before you begin, [configure Yahoo Login for Android](/docs/auth/android/yahoo-oauth#before_you_begin).
361-
380+
362381
Don't forget to add your app's SHA-1 fingerprint.
363382

364383
* {Web}
@@ -403,7 +422,7 @@ final appleProvider = AppleAuthProvider();
403422
404423
if (kIsWeb) {
405424
await FirebaseAuth.instance.currentUser?.linkWithPopup(appleProvider);
406-
425+
407426
// You can also use `linkWithRedirect`
408427
} else {
409428
await FirebaseAuth.instance.currentUser?.linkWithProvider(appleProvider);
@@ -422,7 +441,7 @@ final appleProvider = AppleAuthProvider();
422441
423442
if (kIsWeb) {
424443
await FirebaseAuth.instance.currentUser?.reauthenticateWithPopup(appleProvider);
425-
444+
426445
// Or you can reauthenticate with a redirection
427446
// await FirebaseAuth.instance.currentUser?.reauthenticateWithRedirect(appleProvider);
428447
} else {

packages/firebase_auth/firebase_auth/android/src/main/java/io/flutter/plugins/firebase/auth/FlutterFirebaseAuthPlugin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,14 @@ public void verifyPhoneNumber(
639639
}
640640
}
641641

642+
@Override
643+
public void revokeTokenWithAuthorizationCode(
644+
@NonNull GeneratedAndroidFirebaseAuth.PigeonFirebaseApp app,
645+
@NonNull String authorizationCode,
646+
@NonNull GeneratedAndroidFirebaseAuth.Result<Void> result) {
647+
// Should never get here as we throw Exception on Dart side.
648+
}
649+
642650
@Override
643651
public Task<Map<String, Object>> getPluginConstantsForFirebaseApp(FirebaseApp firebaseApp) {
644652
TaskCompletionSource<Map<String, Object>> taskCompletionSource = new TaskCompletionSource<>();

0 commit comments

Comments
 (0)