cordova-plugin-sign-in-with-apple icon indicating copy to clipboard operation
cordova-plugin-sign-in-with-apple copied to clipboard

The user email is shared only once

Open marcusdiy opened this issue 4 years ago • 7 comments

Hi, Is it normal that the user email is showed only on the first sign up? ...on the following logins it will be just and empty string. Thanks

marcusdiy avatar Jul 30 '20 16:07 marcusdiy

Uh ok seems the expected behavior. https://developer.apple.com/forums/thread/121496 But I think some kind of internal plugin cache would be better. What do you think?

marcusdiy avatar Jul 30 '20 16:07 marcusdiy

I've faced same problem few days ago. personally I use NativeStorage to cache user's email. It just work but Idk it is proper way.

azurenote avatar Jul 31 '20 05:07 azurenote

Using NativeStorage doesn't suffice: if the user uninstalls and reinstalls the app (thus clearing NativeStorage), the device still stores the Apple Sign In configuration from the first time. Hence, on reinstall, it will be treated as just another login and, since NativeStorage was cleared), the app has no way of every retrieving the email again. The user would have to manually go into Settings->Apple ID->Password & Security->Apps Using Apple ID->{appName} and then tap on "Stop Using Apple ID". This is probably not the best way to handle this.

frissonlabs avatar Sep 11 '20 00:09 frissonlabs

The only reliable solution is to communicate the token to your backend servers, which then communicates to Apple servers, where you get the email on every request: https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api/authenticating_users_with_sign_in_with_apple https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens

Not sure if it is valid, secure or even possible (i mean without rejection in App Store review) to communicate with Apple REST API directly from the application, without a intermediate backend.

faugusztin avatar Sep 11 '20 07:09 faugusztin

window.cordova.plugins.SignInWithApple.signin({ requestedScopes: [0, 1] }, function (succ) { let jwt = succ.identityToken; let decoded = jwt_decode(jwt); console.log(decodedl); console.log(decoded.email); }, function (err) { console.error(err) console.log(JSON.stringify(err)) } )

zhicheng-Fu avatar Oct 22 '20 04:10 zhicheng-Fu

@zhicheng-Fu Thanks, this addresses this issue perfectly!

frissonlabs avatar Nov 11 '20 23:11 frissonlabs

window.cordova.plugins.SignInWithApple.signin({ requestedScopes: [0, 1] }, function (succ) { let jwt = succ.identityToken; let decoded = jwt_decode(jwt); console.log(decodedl); console.log(decoded.email); }, function (err) { console.error(err) console.log(JSON.stringify(err)) } ) This should be the accepted answer.

for jwt_decode use this https://www.npmjs.com/package/jwt-decode

menusha95 avatar Nov 23 '20 12:11 menusha95