twogate / cordova-plugin-sign-in-with-apple

A native-implemented plugin of Sign in with Apple // Thanks to your contribution! // Cordova>=8 iOS>=13
https://www.npmjs.com/package/cordova-plugin-sign-in-with-apple
MIT License
74 stars 49 forks source link

The user email is shared only once #24

Open marcusdiy opened 4 years ago

marcusdiy commented 4 years ago

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 commented 4 years ago

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?

azurenote commented 4 years ago

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.

frissonlabs commented 4 years ago

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.

faugusztin commented 4 years ago

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.

zhicheng-Fu commented 4 years ago

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)) } )

frissonlabs commented 4 years ago

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

menusha95 commented 4 years ago

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