What OAuth authentication means for Apple apps

OAuth authentication lets users sign into your app using their Apple ID instead of creating a new username and password. Apple provides the Sign in with Apple service, which handles the login process securely without your app ever seeing the user's actual Apple ID password. The user approves the login on their device, and Apple sends your app a token that proves they are who they say they are.

This approach protects user privacy because Apple can hide the user's real email address behind a private relay address that only Apple knows how to decode. It also reduces the burden on you to store and protect passwords. The setup requires registering your app with Apple, configuring it in Xcode, and writing code to handle the authentication flow.

Key Takeaways

  • You must register your app in Apple Developer and create an App ID with the Sign in with Apple capability enabled.
  • In Xcode, add the Sign in with Apple framework and configure your app to request user information like name and email.
  • Your backend server receives a token from Apple that you verify to confirm the user's identity before creating a session.
  • Users can hide their real email address behind a private relay, so your app receives a unique address that Apple manages.
  • Testing requires a real Apple device or simulator running iOS 13 or later, because Sign in with Apple does not work in web browsers alone.

Register your app in Apple Developer and enable Sign in with Apple

Start by logging into your Apple Developer account at developer.apple.com. Go to Certificates, Identifiers & Profiles, then select Identifiers. Click the plus button to create a new App ID or edit an existing one. Choose App IDs from the dropdown if it is not already selected.

In the Capabilities section, scroll down and check the box for Sign in with Apple. This capability must be enabled before your app can use OAuth. Save your changes. If you are updating an existing App ID, you may need to regenerate your provisioning profile to include this new capability.

Next, create a Service ID if your app will authenticate users on a web version as well. Go back to Identifiers, select Service IDs from the dropdown, and click the plus button. Enter a description and a unique identifier. Check Sign in with Apple, then click Configure to set up the web domain and return URLs where Apple will send users after they authenticate.

Add the Sign in with Apple framework to your Xcode project

Open your project in Xcode. Select your app target, go to the Build Phases tab, and expand Link Binary With Libraries. Click the plus button and search for AuthenticationServices. Add it to your project. This framework contains all the code you need to present the Sign in with Apple button and handle the response.

In your view controller or SwiftUI view, import the framework at the top of your file:

import AuthenticationServices

Then create an ASAuthorizationAppleIDButton and add it to your user interface. This is the official Apple sign-in button that users will tap to start the authentication process. You can customize its style and size, but Apple requires you to use the official button design.

Set up the authentication request and handle the response

When the user taps the Sign in with Apple button, create an ASAuthorizationAppleIDProvider and request the user's name and email address. The request object tells Apple what information your app needs. Add a delegate to handle the response when Apple sends back the authentication result.

In your delegate method, check whether the authorization succeeded or failed. If it succeeded, you will receive a credential object containing a user identifier, an identity token, and an authorization code. The identity token is a JSON Web Token (JWT) that you decode to read the user's information. The authorization code is what you send to your backend server to verify the login.

Store the user identifier locally on the device so you can recognize the same user on future logins. Apple will not send the user's name and email on subsequent logins — only the first time — so you must save that information when you first receive it.

Verify the token on your backend server

Your app sends the identity token and authorization code to your backend server over a secure HTTPS connection. Your server must verify that the token is genuine by checking Apple's digital signature. Apple publishes its public keys at a standard URL that your server can fetch and cache.

Decode the JWT token and check that the issuer is Apple, the audience matches your app's bundle identifier, and the signature is valid. If all checks pass, extract the user's identifier from the token and create or update a user record in your database. Then send back a session token or cookie that your app uses for future requests.

Never trust the token on the client side alone. A malicious user could modify it before sending it to your server. Always verify on the backend, even though the token is cryptographically signed.

Handle private email relay and user information

When a user chooses to hide their email address, Apple generates a unique private relay address like user123456@privaterelay.appleid.com. Your app receives this address instead of the user's real email. You can use this address to contact the user, and Apple forwards the message to their actual inbox.

On the first login, you receive the user's name and email (or private relay address) in the credential. Store both the user identifier and the email address. On future logins, Apple only sends the user identifier, so you look up the user in your database using that identifier and restore their session.

If a user later decides to stop using Sign in with Apple, they can revoke access in their Apple ID settings. Your app should handle this by checking the revocation status periodically and logging the user out if their authorization has been revoked.

Test your implementation on a device or simulator

Sign in with Apple requires iOS 13 or later. You can test on a physical device or on the iOS simulator in Xcode. Create a test Apple ID in your Apple Developer account if you do not want to use your personal account for testing.

On a real device, go to Settings, tap your name, select Password & Security, and manage your app passwords. You can revoke access to your app here to test the revocation flow. On the simulator, you can simulate different authentication scenarios without needing a real Apple ID.

Test both the happy path (successful login) and error cases (user cancels, network error, invalid token). Make sure your app handles each scenario gracefully and does not crash or get stuck waiting for a response.

Frequently Asked Questions

Do I have to use Sign in with Apple if my app is on the App Store?

If your app uses any third-party sign-in service like Google or Facebook, Apple's App Store Review Guidelines require you to offer Sign in with Apple as an option as well. If your app only uses your own custom login system, Sign in with Apple is not required, but it is recommended for user convenience and privacy.

What happens if a user revokes their Sign in with Apple access?

Apple notifies your server through a webhook when a user revokes access. You should delete or deactivate that user's account in your system. If the user tries to sign in again, they will be treated as a new user and may receive a different user identifier.

Can I use Sign in with Apple on the web?

Yes, but the setup is different. You create a Service ID in Apple Developer, configure your web domain, and use the JavaScript SDK that Apple provides. The flow is similar, but you handle the response in JavaScript instead of Swift or Objective-C.

How do I know which user identifier to expect on the next login?

Apple sends the same user identifier every time the same user signs in with the same Apple ID on the same app. Store this identifier in your database on the first login and use it to look up the user on future logins. The identifier is unique per app, so the same Apple ID will have different identifiers for different apps.

What if the user's email address changes in their Apple ID settings?

If the user is using a private relay address, the address itself does not change. If the user is sharing their real email and later changes it in their Apple ID settings, Apple will send you the new email address on the next login. You should update your database record with the new address.