Add an Apple IdP

On this page
Available since 1.17.0

Add a Sign in with Apple button to the FusionAuth login page. This guide shows how to collect the configuration details from your Apple Developer account and configure the Apple Identity Provider, a social loginLogin through an account the user already has with a consumer service, such as Google or Apple. option.

After you configure the Identity Provider, you can enable the Sign in with Apple button for one or more FusionAuth Applications. The following login page shows the Apple Identity Provider:

A FusionAuth login page with a Sign in with Apple button.
A FusionAuth login page with a Sign in with Apple button.

The following diagram shows a login through Apple on the FusionAuth hosted login pages:

Identity ProviderFusionAuthYour ApplicationUser/BrowserIdentity ProviderFusionAuthYour ApplicationUser/BrowserClick LoginRedirect to the FusionAuth login pageClick the Identity Provider buttonRedirect to the Identity ProviderLog inRedirect to FusionAuth with the login resultFollow the redirect to the FusionAuth callback URLRequest the user's tokens or profileReturn the tokens or profileReconcile, link, and create the user and registration as neededRedirect to your application with an authorization codeFollow the redirectExchange the authorization code for tokensReturn FusionAuth tokens
Identity ProviderFusionAuthYour ApplicationUser/BrowserIdentity ProviderFusionAuthYour ApplicationUser/BrowserClick LoginRedirect to the FusionAuth login pageClick the Identity Provider buttonRedirect to the Identity ProviderLog inRedirect to FusionAuth with the login resultFollow the redirect to the FusionAuth callback URLRequest the user's tokens or profileReturn the tokens or profileReconcile, link, and create the user and registration as neededRedirect to your application with an authorization codeFollow the redirectExchange the authorization code for tokensReturn FusionAuth tokens

A user logs in through an Identity Provider on the FusionAuth hosted login pages.

The user sees only the FusionAuth login page, the login page of Apple, and your application. Your application completes a standard OAuth authorization code grant with FusionAuth, and FusionAuth handles the exchange with Apple.

Create an Apple Developer Account#

Log in to your Apple Developer account, or create one. Then continue to the next step.

Configure Your Apple Developer Account#

When you already have an App ID, a Services ID, and a key configured for Sign in with Apple, use the existing values. Otherwise, complete the following sections.

Register a New App ID#

The Identifiers page of an Apple Developer account.
The Identifiers page of an Apple Developer account.
  1. In your Apple Developer account, navigate to Certificates, Identifiers & Profiles and select Identifiers in the left column.

  2. Click the plus icon to add an identifier.

    The Apple form to register a new App ID.
    The Apple form to register a new App ID.
  3. Select App IDs and click Continue .

  4. Select the type App and click Continue .

  5. Fill in Description, specify the Bundle ID, and select Sign in with Apple in the list of capabilities. Click Continue .

  6. Confirm your selection, record the App ID Prefix (Team ID), and click Register .

Register a New Services ID#

  1. In your Apple Developer account, navigate to Certificates, Identifiers & Profiles and select Identifiers in the left column.

  2. Click the plus icon to add an identifier.

    The Apple form to register a new Services ID.
    The Apple form to register a new Services ID.
  3. Select Services IDs and click Continue .

  4. Fill in Description and Identifier, and click Continue . Click Register on the next panel.

  5. Edit the new Services ID, and turn on Sign In with Apple. Click Configure to open the Web Authentication Configuration panel.

  6. When the panel doesn't show Domains and Subdomains and Return URLs, click the plus icon next to Website URLs.

  7. Enter the domain and the Return URL of your FusionAuth service. For FusionAuth at https://login.piedpiper.com, the domain is login.piedpiper.com. The Return URL is the FusionAuth URL with a path of /oauth2/callback, such as https://login.piedpiper.com/oauth2/callback. Apple expects a secure https URL, so an http endpoint doesn't work, even in development or test environments. You can add more domains and Return URLs later.

  8. Save your changes and click Continue . To confirm the changes to the Services ID, click Save .

Register a New Key#

The Keys page of an Apple Developer account.
The Keys page of an Apple Developer account.
  1. In your Apple Developer account, navigate to Certificates, Identifiers & Profiles and select Keys in the left column.

  2. Click the plus icon to add a key.

    The Apple form to register a new key.
    The Apple form to register a new key.
  3. Enter a name for the key.

    The Apple key form with Sign in with Apple selected.
    The Apple key form with Sign in with Apple selected.
  4. Check Sign in with Apple, and click Configure .

  5. Select the App ID that you created and click Save .

  6. Click Continue , then click Register to confirm the key registration.

  7. Download the key when Apple prompts you, and record the Key ID.

Import the Private Key#

Import the private key from the previous step into FusionAuth. Unless Apple says otherwise, the private key uses an elliptic curve.

  1. In the Admin UI, navigate to Settings -> Key Master .
  2. Select Import Elliptic Private Key in the actions at the top right.
  3. Set Key identifier to the Key ID from the previous step.
  4. Open the downloaded key file in a text editor, and copy the contents into Private key.
The Key Master import menu in the Admin UI.
The Key Master import menu in the Admin UI.

Create an Apple Identity Provider in FusionAuth#

Create the Apple Identity Provider in FusionAuth. Fill in the required fields with the values from your Apple Developer account. Button text is required and defaults to Sign in with Apple.

To enable Apple for an Application or CIMD domain:

  1. In the Admin UI, navigate to Settings -> Identity Providers .

  2. Click the arrow next to the add button, and select Apple .

  3. Select the Tenant for the Identity Provider, or select Global identity provider. You can't change the scope later. For more information, see Identity Provider Scope.

  4. Fill out the form. Your identity provider supplies most of the values. For a description of each field, see Form Fields.

  5. On the Applications tab, turn on Enabled for each Application or CIMD domain that uses the Identity Provider.

  6. To register new users for the Application with the Application's default roles, turn on Create registration. When Create registration is off, a user needs a registration for the Application before the user can log in through the Identity Provider.

  7. Click .

The login page of each enabled Application then shows a login button for the Identity Provider. An Identity Provider with managed domains asks for the user's email address instead of showing a button.

The form to configure an Apple Identity Provider in the Admin UI.
The form to configure an Apple Identity Provider in the Admin UI.

Form Fields#

Id
  • Optional
  • Available since 1.61.0

An optional UUID. When you leave out the Id, FusionAuth generates a unique Id.

Tenant
  • Optional
  • Available since 1.62.0

The Tenant that this Identity Provider belongs to. The field appears only when you select a specific Tenant on the previous page. When you select Global identity provider on the previous page, the field doesn't appear.

Name
  • Required
  • Available since 1.61.0

A unique name for the Identity Provider. FusionAuth uses the name for display only, and you can change the name later.

Bundle Id
  • Optional
  • Available since 1.43.0

The Apple Bundle ID configured for Sign in with Apple in your Apple Developer account. To find the Bundle ID, navigate to Certificates, Identifiers & Profiles -> Identifiers -> App IDs in your Apple Developer account.

The configuration needs Bundle Id or Services Id. When you leave out Services Id, this field is required.

Services Id
  • Optional

The Apple Services ID configured for Sign in with Apple in your Apple Developer account. To find the Services ID, navigate to Certificates, Identifiers & Profiles -> Identifiers -> Services IDs in your Apple Developer account.

Available since 1.43.0 The configuration needs Bundle Id or Services Id. When you leave out Bundle Id, this field is required.

Team Id
  • Required

The Apple App ID Prefix, or Team ID, configured for Sign in with Apple in your Apple Developer account. To find the Team ID, navigate to Certificates, Identifiers & Profiles -> Identifiers -> App IDs in your Apple Developer account.

Button text
  • Required

The text of the button on the login form. The default value is Sign in with Apple.

Scope
  • Optional

A space-separated list of the user attributes to request, such as name email. You can request the user's name, email address, or both. When Linking strategy links on email, request the email scope.

Signing key
  • Required

The private signing key from Apple. FusionAuth signs the client secret with the key when FusionAuth requests an access token from Apple.

Linking strategy
  • Required

How FusionAuth links an Apple user to a FusionAuth user. For more information, see Linking Strategies.

Available since 1.65.0 You can only change this value when the identity provider is disabled. To change the linking strategy for an identity provider that is already enabled, disable the provider, change the value, and then re-enable the provider.

Reconcile Lambda
  • Optional

A lambda that maps custom claims from Apple to the user.

To create a lambda, navigate to Customizations -> Lambdas .

Enable debug logging
  • Optional

Creates Event Log entries that help you debug integration errors. To read the entries, navigate to System -> Event Log .

Tenants#

The Tenants tab limits the number of links that each user in a Tenant can have to this Identity Provider. Links to other Identity Providers don't count toward the limit. On a global Identity Provider, the tab starts empty. To set a limit for a Tenant, click Add tenant configuration . On a tenant-scoped Identity Provider, the tab lists only the Identity Provider's Tenant.

Limit links per user
  • Optional
  • Defaults to false
  • Available since 1.32.0

When turned on, FusionAuth enforces Maximum link count for users in the Tenant.

Maximum link count
  • Optional
  • Available since 1.32.0

The maximum number of links that a user can have to this Identity Provider. When a user reaches the limit, FusionAuth rejects a new link. The Link API returns a 400, and the hosted login pages show an error.

For more information, see Identity Providers and Tenants.

Apple Private Email Relay Configuration#

When a user logs in with Apple, Apple lets the user send FusionAuth either the user's real email address or an anonymous email address.

An anonymous email address ends in @privaterelay.appleid.com. You can email the user at the anonymous address, and Apple routes the email through the Apple Private Email Relay service. To make sure your email arrives, register your email domain with Apple and configure your SMTP service provider. For more information, see Communicating Using the Private Email Relay Service.

Some email service providers document the configuration. For example, see the SendGrid article Configuring Sign in with Apple.

CORS Configuration#

To complete the login, Apple sends an HTTP POST request to the callback URLThe URL where the authorization server sends the browser after login, with an authorization code or an error. in FusionAuth. To let the request through the CORSA browser security mechanism that lets a web page request restricted resources from another domain when the server allows the request. filter, navigate to Settings -> System -> CORS and add https://appleid.apple.com to Allowed Origin.

When the CORS configuration doesn't yet allow the Apple login request, the Admin UI shows the following warning after you configure the Apple Identity Provider:

The Admin UI warning that the CORS configuration doesn't allow Apple login requests.
The Admin UI warning that the CORS configuration doesn't allow Apple login requests.

For more information, see the CORS Filter reference.

Troubleshooting CORS#

When Safari logs a 403 status code in the browser console during login, add more configuration. The redirect flow differs slightly between browsers. Navigate to Settings -> System -> CORS and add the GET method to Allowed methods.

Building Your Own Integration#

To build your own login experience instead of using the FusionAuth hosted login pages, start the Identity Provider flow in your application, and complete the login with the Login API. The following diagram shows the flow:

ProviderFusionAuthAppUser/BrowserProviderFusionAuthAppUser/BrowserUser Is Logged In And App Can ProceedDelivering Data And FunctionalityView Initial PageClick LoginDisplays Login PageIncluding Link To 'Login With Provider'Clicks On 'Login With Provider'Redirect To Provider Authorization URLEnters CredentialsValidate CredentialsRedirect to App With Authorization CodeRequests Page, Has Authorization CodeCalls Complete LoginWith Code And Redirect URIExchanges Code AndRedirect URI For Provider TokenReturns Provider TokenStores Provider Token, Calls Lambda, Creates User And Registrations (If Needed), Generates FusionAuth TokensReturn FusionAuth TokensCreate Session OrOtherwise Log User In
ProviderFusionAuthAppUser/BrowserProviderFusionAuthAppUser/BrowserUser Is Logged In And App Can ProceedDelivering Data And FunctionalityView Initial PageClick LoginDisplays Login PageIncluding Link To 'Login With Provider'Clicks On 'Login With Provider'Redirect To Provider Authorization URLEnters CredentialsValidate CredentialsRedirect to App With Authorization CodeRequests Page, Has Authorization CodeCalls Complete LoginWith Code And Redirect URIExchanges Code AndRedirect URI For Provider TokenReturns Provider TokenStores Provider Token, Calls Lambda, Creates User And Registrations (If Needed), Generates FusionAuth TokensReturn FusionAuth TokensCreate Session OrOtherwise Log User In

Your application starts the Identity Provider login and completes the login with the FusionAuth API.

For the request that completes the login, see the Apple Identity Provider API.

When your application needs a refresh token after the login, turn on Enable JWT Refresh for the Application. In the Admin UI, navigate to Applications -> Your Application -> Security -> Login API settings .

Supporting Web and Mobile#

Version

FusionAuth 1.43.0 and later supports web and mobile Sign in with Apple with a single Identity Provider configuration.

In FusionAuth 1.43.0 and later, follow Using Bundle Id. In earlier versions, follow Using Services Id with Application Overrides.

Using Bundle Id#

In FusionAuth 1.43.0 and later, Sign in with Apple from both web and mobile applications doesn't need more than one Application. The Identity Provider has the following fields:

  • Services Id is the Apple Services ID for web applications.
  • Bundle Id is the Apple Bundle ID for native applications.

Fill in the fields that your applications need:

  • For a native app only, fill in Bundle Id and leave Services Id blank.
  • For a web app only, fill in Services Id and leave Bundle Id blank.
  • For both a native app and a web app, fill in Bundle Id and Services Id.

You can still override either field for each Application.

A login APIThe FusionAuth API that logs a user in without the hosted login pages. request from a native application needs data.isNativeApp with the string value "true". FusionAuth then uses Bundle Id instead of Services Id.

Using Services Id with Application Overrides#

Before FusionAuth 1.43.0, Sign in with Apple from both web and mobile applications needs two configurations with different values:

  • For web applications, Services Id is the Apple Services ID.
  • For mobile applications, Services Id is the Apple Bundle ID.

One Application can't have more than one Apple Identity Provider. To support both mobile and web users:

  1. Create two Applications in FusionAuth.
  2. Enable the Apple Identity Provider for each Application.
  3. In the Overrides section, set Services Id to the right value for each Application.
The Overrides section of the Apple Identity Provider form.
The Overrides section of the Apple Identity Provider form.

Usually you register the user for both Applications when the user signs in with Apple. To do so, use a User Registration Complete webhook.

Troubleshooting#

Key Import Error#

The UI may show the following error:

A request to the Apple Token API has failed. Unable to complete this login request.

The Event Log then shows the following error:

Status code [400] Error response is { "error" : "invalid_client" }

Check that you imported the private key from Apple with the Key ID from the Apple Developer account dashboard. When you import the key with the default behavior, FusionAuth generates a key identifier. The generated identifier doesn't match the value that Apple expects, and the integration fails with the error. To fix the error, import the private key again with the correct Id.

With a Link on email linking strategy, the UI may show the following error:

"An email address was not provided for the user. This account cannot be used to login, unable to complete this login request."

Check that you requested the email scope. For more information, see Form Fields.

You may still see the error after you request the email scope, when an earlier configuration error made a full login or user creation fail. Apple sends the user's email address only on the first login, and only the user Id on later logins. To fix the error, reset access to your app on your Apple device. On a phone, navigate to Phone Settings -> Apple ID -> Password & Security -> Apple ID logins -> Your App -> Stop using Apple ID . On macOS, navigate to System Settings -> Apple ID -> Password & Security -> Apple ID logins -> Your App -> Stop using Apple ID . Then log in again, and Apple sends the email address.