Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sign in with Apple

I'm trying to implement Sign in with Apple since it's required now when you have other third party login library. My question is, is there a way for me to get apple's auth token just like from facebook and google login? All I could get is identity token and authorization code from ASAuthorizationAppleIDCredential. I am not quite sure what is used to get user information using our API.

Thank you so much for the answer.

like image 748
Christian Bringino Avatar asked Dec 05 '25 08:12

Christian Bringino


1 Answers

in ASAuthorizationControllerDelegate

get the token

func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
        
        if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
            if let data = appleIDCredential.identityToken {
                let token = String(decoding: data, as: UTF8.self)
                // here send token to server
            }
        }
    }
}

send the token to the server, which must be set up https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api

and based on this token your server will get the user information from Apple the same way you can get the facebook user data.

Then your api should implement user authentication based on this data (e.g. create user account based on the user email and return your access token to the app)

like image 56
vytick Avatar answered Dec 07 '25 20:12

vytick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!