Skip to content

Commit

Permalink
feat(auth, revokeToken): sign in with apple revokeToken API (#7239)
Browse files Browse the repository at this point in the history
* feat(revoke): add support for revokeToken API

* Fixed there/their

* style(auth, lint): result of `yarn lint:android && yarn lint:ios:fix`

---------

Co-authored-by: Mike Hardy <github@mikehardy.net>
  • Loading branch information
donaldkwong and mikehardy committed Jul 17, 2023
1 parent 4c666df commit 2b9dc73
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/auth/social-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ async function onAppleButtonPress() {
Upon successful sign-in, any [`onAuthStateChanged`](/auth/usage#listening-to-authentication-state) listeners will trigger
with the new authentication state of the user.

Apple also requires that the app revoke the `Sign in with Apple` token when the user chooses to delete their account. This can be accomplished with the `revokeToken` API.

```js
import auth from '@react-native-firebase/auth';
import { appleAuth } from '@invertase/react-native-apple-authentication';

async function revokeSignInWithAppleToken() {
// Get an authorizationCode from Apple
const { authorizationCode } = await appleAuth.performRequest({
requestedOperation: appleAuth.Operation.REFRESH,
});

// Ensure Apple returned an authorizationCode
if (!authorizationCode) {
throw new Error('Apple Revocation failed - no authorizationCode returned');
}

// Revoke the token
return auth().revokeToken(authorizationCode);
}
```

## Facebook

There is a [community-supported React Native library](https://github.com/thebergamo/react-native-fbsdk-next) which wraps around
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,21 @@ private void signInWithCustomToken(String appName, final String token, final Pro
});
}

/**
* revokeToken
*
* @param authorizationCode
* @param promise
*/
@ReactMethod
public void revokeToken(String appName, final String authorizationCode, final Promise promise) {
Log.d(TAG, "revokeToken");

// Revocation is not implemented on Android
Log.e(TAG, "revokeToken:failure:noCurrentUser");
promiseNoUser(promise, false);
}

/**
* sendPasswordResetEmail
*
Expand Down
16 changes: 16 additions & 0 deletions packages/auth/ios/RNFBAuth/RNFBAuthModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,22 @@ - (void)invalidate {
}];
}

RCT_EXPORT_METHOD(revokeToken
: (FIRApp *)firebaseApp
: (NSString *)authorizationCode
: (RCTPromiseResolveBlock)resolve
: (RCTPromiseRejectBlock)reject) {
[[FIRAuth authWithApp:firebaseApp]
revokeTokenWithAuthorizationCode:authorizationCode
completion:^(NSError *_Nullable error) {
if (error) {
[self promiseRejectAuthException:reject error:error];
} else {
[self promiseNoUser:resolve rejecter:reject isError:NO];
}
}];
}

RCT_EXPORT_METHOD(sendPasswordResetEmail
: (FIRApp *)firebaseApp
: (NSString *)email
Expand Down
16 changes: 16 additions & 0 deletions packages/auth/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,22 @@ export namespace FirebaseAuthTypes {
*/
signInWithCredential(credential: AuthCredential): Promise<UserCredential>;

/**
* Revokes a user's Sign in with Apple token.
*
* #### Example
*
* ```js
* // Generate an Apple ID authorizationCode for the currently logged in user (ie, with @invertase/react-native-apple-authentication)
* const { authorizationCode } = await appleAuth.performRequest({ requestedOperation: appleAuth.Operation.REFRESH });
* // Revoke the token
* await firebase.auth().revokeToken(authorizationCode);
* ```
*
* @param authorizationCode A generated authorization code from Sign in with Apple.
*/
revokeToken(authorizationCode: string): Promise<void>;

/**
* Sends a password reset email to the given email address.
* Unlike the web SDK, the email will contain a password reset link rather than a code.
Expand Down
4 changes: 4 additions & 0 deletions packages/auth/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ class FirebaseAuthModule extends FirebaseModule {
.then(userCredential => this._setUserCredential(userCredential));
}

revokeToken(authorizationCode) {
return this.native.revokeToken(authorizationCode);
}

sendPasswordResetEmail(email, actionCodeSettings = null) {
return this.native.sendPasswordResetEmail(email, actionCodeSettings);
}
Expand Down

1 comment on commit 2b9dc73

@vercel
Copy link

@vercel vercel bot commented on 2b9dc73 Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.