Sign in with Apple for iOS App with Backend
Apple provides mechanism for sign in using Apple ID.
- Adding supporting it for iOS application, this give easy way to create account for user.
- Apple requires it for applications which use other social services for sign in.

Setup Apple ID in developer account.
First setup SignIn with Apple in application on https://developer.apple.com

Then need generate key for SignIn with Apple

iOS Application
For UI button I recommend use class ASAuthorizationAppleIDButton, because Apple has strict requirements.

For perform auth request iOS providing ASAuthorizationController

Code sample:
Then implementing protocols:
- ASAuthorizationControllerPresentationContextProviding
- ASAuthorizationControllerDelegate
Code sample:
iOS SDK provide accessCode, which you can use on backend side.
Moment*: email and fullName Apple provides only first time, need safe it in any storage(for example UserDefaults) for cases if application fail on network request.
Backend
I choose Python as programming language and Flask as Framework for my lightweight backend.
Load private key for working with SignIn with Apple API.
* I used PyJWT 2.0.1 for working with key
Need implement:
- Method for signin
- Method for refresh token
- Method for handle events from Apple
SignIn
First need add method for signin/signin to our’s backend via access code.
Example for perform SignIn Web Api method using Flask.
Refresh Token
access_token expiring after some time, so we should provide mechanism for refreshing it.
Example for perform refresh token Web Api method using Flask.
Handle events
User can manage account from General Settings

Events from Apple to endpoint:
- email-disabled — disable forwarding
- email-enabled — enable forwarding
- consent-revoked — disable account
- account-delete — removed account

Example for processing events from Apple:
More details about events you can read in documentation.