After a successful login in which my Web App receives the TokenResponse - containing the access_token, expirations time, id_token, refresh_token, token_type - and sends the access token down to the client to make subsequent calls to my Web App, how do I validate the access token and the identity of the user? Should the access token be the Authorization Bearer token or should the identity_token be the Authorization Bearer token? Do the steps below make sense? or do I have something mixed up?
When the user first signs in on the client, Apple ID server sends back the Client ID, Identity Token, Authorization Code
Client app sends those 3 credentials to the Web API
The Web API FIRST checks the validity of the Identity Token, NEXT, if verified, calls Apple ID servers (https://appleid.apple.com/auth/token) to get the TokenResponse (contains access_token, expiration time, id_token, refresh_token, token_type)
Web API stores the refresh_token on the DB
Web API sends the the access_token to client.
Client sends access_token on all subsequent calls to Web API
As described in this doc page (Access Tokens), Identity Tokens are meant for application use only. So when securing your API you should send Access Token in the Authorization header.
I noticed that auth0 created a few blog posts on Sign In With Apple and was hoping the auth0 team could provide some insight on my question above. But I think I figured it out. After the user is authenticated, the client app receives the credentials, sends the credentials to my server. My server will verify the identity_token provided by Apple’s server, I’ll have my server create a refresh token, send it down to the client and then the next time the client calls my server, I’ll verify the refresh token and then send down an access token.
I won’t do steps 4, 5, 6 and the TokenResponse step in 3.
I found some answer few days back and it worked. Totally conceptual response provided
For code:
in Swift file use this method:
Auth0
.authentication()
.login(appleAuthorizationCode: authCode, fullName: appleIDCredential.fullName, scope: “openid profile email”, audience: “YOUR AUDIENCE URL”).start { result in
switch(result) {}})