Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user information like email, name using "user" param in Sign in with apple feature?

Apple introduced Sign in with apple feature in iOS 13 and later iOS at WWDC19. I have implemented that feature in my application.

When the user authenticates the first time for an app, We will get the authentication information like Email, Name, User, State etc in the below delegate method.

func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { }

Once the user successfully authenticated, Apple will maintain the app information in iCloud under Apple Sign in.

Again when the user tries to authenticate for the same app, Apple will return User, State etc. It should not return the name and email information.

Is there any way to get the user's email and name using that user param in the above delegate method.

like image 390
Vimalkumar N.M. Avatar asked Feb 05 '20 11:02

Vimalkumar N.M.


People also ask

What email does Sign in with Apple use?

If you're signing into an app, Apple uses your default ‌Apple ID‌ email address, but if you're signing into a website, you can change your associated email address for forwarding purposes.

How do you get the Apple ID Identity Token?

To obtain the identity token from their server, web apps must validate the authorization code using the Generate and validate tokens endpoint. To verify the identity token, your app server must: Verify the JWS E256 signature using the server's public key. Verify the nonce for the authentication.

What is Sign in with Apple user?

If a user signs up for an app on their Apple device — like, say, their iPad — then wants to use the app on a non-Apple device, like their Android phone, they're sent over to a web view. Here, they'll see a Sign in with Apple login screen where they'll enter their Apple ID and password to complete the sign in.

Does Apple use OAuth?

How Sign In with Apple Works (Hint: it uses OAuth and OIDC) Thankfully, Apple adopted the existing open standards OAuth 2.0 and OpenID Connect to use as the foundation for their new API. While they don't explicitly call out OAuth or OIDC in their documentation, they use all the same terminology and API calls.


2 Answers

As per Apple documentation, you cannot get the name or email again by doing the same auth process again on the same or any other device unless the user stops using Sign in with Apple for your app and later reconnects to your app. Even then you will only get it for the very first time.

Check the documentation here

like image 141
anandb Avatar answered Nov 10 '22 20:11

anandb


Sign in with Apple does not return email and name when you are trying to auth the same app again.

However, you get a user id(token) which you can use to verify the login for next time.

For Name and Email you can store those credentials on your database using an api and can fetch and authenticate again whenever same user with same token do login again.

See the answer here from Dima_Beliy, who is an Apple employee:

The scopes are only shared once, during the initial authorization. Once the SIWA API returns the information, it is up to the client application to store it within their systems. For follow up authorizations, the "user" identifier returned as part of SIWA API should be used as a means of fetching the previously shared information from your system.

Once SWIA API returns the information, the application should create an account in its own system, store the information and later use the "user" identifier to retrieve it for follow on authorizations.

The data is only returned once for privacy reasons, we do not support an ongoing data sharing.

https://forums.developer.apple.com/thread/119826

like image 23
Saurabh Avatar answered Nov 10 '22 21:11

Saurabh