Skip to main content

Add Sign in with Apple

This guide explains how to let users sign in to Casdoor with their Apple ID.


Learning outcomes​

  • Configure an App ID, a Services ID, and a key at Apple.
  • Add Apple as an OAuth provider in Casdoor.

What you need​

  • An Apple Developer account with a membership of the Apple Developer Program
  • Administrator access to the Casdoor admin console

Configure Apple​

  1. Create an App ID, or open an existing one, and turn on Sign in with Apple for it.

    Sign in with Apple capability of the App ID

  2. Create an identifier of the type Services IDs. Its identifier becomes the Client ID in Casdoor.

    Services ID registration

  3. Open the Services ID, turn on Sign in with Apple, and click Configure.

    Services ID configuration

  4. In Return URLs, enter the redirect URL that the Apple provider page in Casdoor shows, for example https://your-casdoor-domain.com/callback. The two values must match exactly.

    Return URLs of the Services ID

  5. Create a key, turn on Sign in with Apple for it, and associate it with your App ID.

    Key configuration

  6. Register the key. Note the Key ID and download the .p8 file at once. Apple lets you download the file only once, so store it securely.

    Key ID and download of the key file

  7. On the Membership page of the Apple Developer portal, note your Team ID.

Add the provider in Casdoor​

  1. In the Casdoor admin console, go to Identity > Providers and add a provider.

  2. Set Category to OAuth and Type to Apple.

  3. Fill in the fields:

    FieldValue
    Client IDThe identifier of the Services ID
    Team IDYour Apple Team ID
    Key IDThe ID of the key
    Key textThe complete content of the .p8 file, including the -----BEGIN and -----END lines
  4. Check that the redirect URL that Casdoor shows is in the Return URLs of the Services ID.

    Apple provider in Casdoor

  5. Save the provider.

User information​

Casdoor reads the user ID and the email address from the ID token that Apple signs.

Apple sends the first and last name of the user only once: in the user field of the form that it posts to the /api/callback endpoint of Casdoor, on the first authorization of the user. Casdoor keeps the name for 5 minutes in an HttpOnly cookie named casdoor_apple_user, and uses it as the display name of the user that it creates. An existing user gets the name only if the display name is empty.

  • The display name is <first-name> <last-name>. If either part is Chinese, it is <last-name><first-name>, without a space. If only one part is present, Casdoor uses that part.
  • Apple doesn't sign the name, so Casdoor uses it only for the display name. The username and the email address always come from the ID token.
  • On later sign-ins, Apple doesn't send the name. To send it again, the user removes the application under Sign in with Apple in the settings of their Apple ID, and then signs in again.

Next steps​

Add the provider to an application. See Add providers to an application.

See also​