Apple is complaining about my app because I am not calling the rest endpoint revoke token to delete an account.
I have to do it as described in this documentation: https://developer.apple.com/documentation/sign_in_with_apple/revoke_tokens
To call I need to get the client_id, client_secret and token.
The login process in my App is managed by Firebase and I don’t save this information when the user executes a login.
So I need to recover these 3 parameters from Firebase auth on IOS to call that revoke token endpoint.
There may be a method in the Firebase auth API on IOS that calls the Apple endpoint revoke_token for me and I am not seeing it.
3
Answers
apple-token-revoke-in-firebase
This document describes how to revoke the token of Sign in with Apple in the Firebase environment.
In accordance with Apple’s review guidelines, apps that do not take action by June 30, 2022 may be removed.
A translator was used to write this document, so I apologize whenever you feel weird about these sentences and describes.
This document uses Firebase’s Functions, and if Firebase provides related function in the future, I recommend using it.
The whole process is as follows.
You can get a refresh token at https://appleid.apple.com/auth/token and revoke at https://appleid.apple.com/auth/revoke.
Getting started
If you have implemented Apple Login using Firebase, you should have ASAuthorizationAppleIDCredential somewhere in your project.
In my case, it is written in the form below.
What we need is the authorizationCode. Add the following code under guard where you get the idTokenString.
Once you get this far, you can get the authorizationCode when the user log in.
However, we need to get a refresh token through authorizationCode, and this operation requires JWT, so let’s do this with Firebase functions.
Turn off Xcode for a while and go to your code in Firebase functions.
If you have never used functions, please refer to https://firebase.google.com/docs/functions.
In Firebase functions, you can use JavaScript or TypeScript, for me, I used JavaScript.
First, let’s declare a function that creates a JWT globally. Install the required packages with npm install.
There is a place to write route of your key file and ID(Team, Client, Key), so plz write your own information.
If you do not know your ID information, please refer to the relevant issue. https://github.com/jooyoungho/apple-token-revoke-in-firebase/issues/1
The above function is returned by creating JWT based on your key information.
Now, let’s get the Refresh token with AuthorizationCode.
We will add a function called getRefreshToken to functions.
When you call the above function, you get the code from the query and get a refresh_token.
For code, this is the authorizationCode we got from the app in the first place.
Before connecting to the app, let’s add a revoke function as well.
The above function revokes the login information based on the refresh_token we got.
So far we have configured our functions, and when we do ‘firebase deploy functions’ we will have something we added to the Firebase functions console.
Now back to Xcode.
Call the Functions address in the code you wrote earlier to save Refresh token.
I saved it in UserDefaults, You can save it in the Firebase database.
At this point, the user’s device will save the refresh_token as UserDefaults when logging in.
Now all that’s left is to revoke when the user leaves the service.
If we’ve followed everything up to this point, our app should have been removed from your Settings – Password & Security > Apps Using Apple ID.
Thank you.
[UPDATE] Resolution being actively worked on: https://github.com/firebase/firebase-ios-sdk/issues/9906#issuecomment-1159535230
Heads up, a feature request has been created to have Firebase Auth handle the revoking of tokens on user deletion, you can follow it here: https://github.com/firebase/firebase-ios-sdk/issues/9906
I think this should be done from your backend, so as not to expose sensitive data (client_secret) to the application.
This is how I generate client_secret in .net and call revoke token API endpoint:
Calling Apple ‘revoke’ token endpoint from .net core backend