Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth, revokeToken): sign in with apple revokeToken API #7239

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
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
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 @@
});
}

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

Check warning on line 461 in packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java

View check run for this annotation

Codecov / codecov/patch

packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java#L461

Added line #L461 was not covered by tests

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

Check warning on line 466 in packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java

View check run for this annotation

Codecov / codecov/patch

packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java#L464-L466

Added lines #L464 - L466 were not covered by tests

/**
* 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 @@
.then(userCredential => this._setUserCredential(userCredential));
}

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

Check warning on line 303 in packages/auth/lib/index.js

View check run for this annotation

Codecov / codecov/patch

packages/auth/lib/index.js#L302-L303

Added lines #L302 - L303 were not covered by tests
}

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