React-native-apple-authentication: onCredentialRevoked callback not called after app restart

Created on 4 Mar 2020  路  2Comments  路  Source: invertase/react-native-apple-authentication

I am using the onCredentialRevoked listener to check if the logged in user revoked access to the app. This works fine when the user logs in and revokes access to the app while the app is still in the background (without closing the app once).

But when I reopen the app it doesn't fire the callback of the listener anymore. These are the reproduce steps:
1) Login using Sign In with Apple
2) Close the app completely and start it again.
3) Add the onCredentialRevoked listener because you want to check if the logged in user is still valid.
4) Revoke access to the app. You'll see that the callback of the onCredentialRevoked listener is never called.

I tried to fix this problem myself but I'm stuck. It appears that the observer is set in RNAppleAuthModule.m. So adding the listener itself works but it appears that the observer never calls the onCredentialRevoked method (in the same file).

Most helpful comment

I've looked into this today and maybe I've got a workaround. Previously I just initiated the listener because I thought that the app would already "know" that I was logged in using Apple (since I never revoked it, and never pressed the logout button).

When I launch the app I now call this function:

const result = await appleAuth.getCredentialStateForUser(USER_ID);

So when the app starts I check if the user' is still authorized using the method above. Calling that method surprisingly fixes the original issue. I add the listener when the getCredentialStateForUser function says that I'm authorized. Now the listener gets called when I revoke the app. Maybe because I'm passing the ID of the user to the Sign In with Apple SDK (using getCredentialStateForUser) which you don't do with the listener.

I'm not sure if this is the intended behaviour or a workaround to get it working. The downside is of course that you need the ID of the Apple account to verify this, which you might not have if you are using your own database with users.

I can take a look in the upcoming days to see if this can be improved (check it with the Expo library or a native app). But I wanted to share this here for now.

All 2 comments

This might be similar to #10 in that it sounds like it could be an upstream bug. If you have looked at this module's code and it all looks right then upstream is where I'd look. Have you looked through apple's developer forums and/or stackoverflow, or attempted to do a minimal Obj-C (or Swift) reproduction without the react-native layer to see if it's upstream and/or already discussed?

I've looked into this today and maybe I've got a workaround. Previously I just initiated the listener because I thought that the app would already "know" that I was logged in using Apple (since I never revoked it, and never pressed the logout button).

When I launch the app I now call this function:

const result = await appleAuth.getCredentialStateForUser(USER_ID);

So when the app starts I check if the user' is still authorized using the method above. Calling that method surprisingly fixes the original issue. I add the listener when the getCredentialStateForUser function says that I'm authorized. Now the listener gets called when I revoke the app. Maybe because I'm passing the ID of the user to the Sign In with Apple SDK (using getCredentialStateForUser) which you don't do with the listener.

I'm not sure if this is the intended behaviour or a workaround to get it working. The downside is of course that you need the ID of the Apple account to verify this, which you might not have if you are using your own database with users.

I can take a look in the upcoming days to see if this can be improved (check it with the Expo library or a native app). But I wanted to share this here for now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vanminhnguyenbmt picture vanminhnguyenbmt  路  7Comments

DIGITALSQUAD picture DIGITALSQUAD  路  5Comments

thinnakrit picture thinnakrit  路  3Comments

pantelispanayiotou picture pantelispanayiotou  路  8Comments

fareszoghbi1 picture fareszoghbi1  路  5Comments