Implement Sign In with Apple in your Application.
In most cases Sign in with social logins results in a lot of information being shared like age, gender, personal stuff like the photos, videos, the places you visited, and so on. To tackle this issue Apple provides a one-touch solution called Sign In With Apple. It will provide an additional button along with social sign-in options that are currently there and will let you sign in to services using Apple ID.
The login would be authenticated using Face ID or Touch ID and no personal information not even email would be shared with the service that you are login into. So, some services like shopping websites need your name and email id for completing the registration and creating an account. In such cases developers have an option to ask name or email address via Sign In With Apple. But the interesting part is apple will give you an option to hide the emails here, So you could either enter your email id or choose to masked completely, When you choose to hide your email id apple will create a dummy email id to log you in. This email address will be shared with the service and any message that they send to this email id will be automatically forwarded to your actual email id. Notably, Apple will create unique dummy email for every service that you login into using this method. Finally, if you don’t want to receive any emails from a particular service you can even disable the dummy email for them.
Integrating with Your App
Configuring your Apple Developer Account
To enable Sign In with Apple in your developer account you need to create an Auth Key with Sign In with Apple.
Set up “Sign in with Apple”
Enable “Sign in with Apple” under “Signing & Capabilities”.
- In Xcode 11, Project Navigator→ Select Project → Select Target.
- Select “Signing & Capabilities” from the top.
- Select “+ Capability” from the top left (Below “Signing & Capabilities”).
- Select “Sign in with Apple” from the list of Capabilities.
Add the Sign in with Apple button
Add the Sign in with Apple to your login view. You can either add it in Interface Builder by creating a UIView and making its class ASAuthorizationAppleIDButton or by adding it programmatically:
Login Button Click Event
Only scopes you can request are .fullName and .email. The name and email will be returned in the delegate method.
ASAuthorization Controller Delegate
We need to handle the delegate functions. The first is error handling and the second is actually handling the login result:
ASAuthorizationController Presentation Context
This returns the view for the login authorization UI to be presented over.
Existing Account Setup Flow
There are possibility of user might already logged in with your application. For that, we need to use both ASAuthorizationAppleIDProvider
and ASAuthorizationPasswordProvider
provider to create the request.
Handle ASAuthorization Controller Delegate For Existing Account
Sign in using an existing credential.
Check Credential State
Check to see if we’ve already been authorized when the app starts in our AppDelegate:
For reference, you can download the project from Here
Reference
Disclaimer: To make this article I had to read a lot of stuff over the internet. Also, I had copied easy to understand examples and sentences from another article to make this article meaningful.