Skip to main content

Apple Sign-In

Sign in to a web or iOS app with an Apple Account. Mini programs are not supported.

Step 1: Copy the callback URL​

The Service ID Return URL must be the CloudBase callback URL. Copy it first and keep the page open.

  1. Open CloudBase Console / Authentication / Sign-in methods.

  2. Find Apple sign-in and click "Edit".

    Edit Apple sign-in

  3. In "Identity provider settings", copy the callback URL.

    Copy the callback URL

Step 2: Configure Apple Developer​

Record the Team ID​

Open Membership and record the Team ID.

Team ID

Create an App ID​

iOS uses the App ID. Record its Bundle ID.

  1. Open Identifiers and click "+".

    Create an identifier

  2. Select App IDs and click "Continue".

    Select App IDs

  3. Select the app type and click "Continue".

    Select the app type

  4. Fill in "Description" and "Bundle ID", then select "Sign in with Apple". Record the Bundle ID.

    Enter the Bundle ID

  5. Click "Continue", confirm the details, and click "Register".

    Register the App ID

Create a Service ID​

Web sign-in uses the Service ID. Enter this value as the Client ID in the console.

  1. Open Services IDs, click "+", select Services IDs, and click "Continue".

    Select Services IDs

  2. Fill in "Description" and "Identifier", click "Continue", then click "Register".

    Enter the Service ID

    Confirm the Service

  3. Open the Service you just created, select "Sign in with Apple", and click "Configure".

    Configure Sign in with Apple

  4. For "Primary App ID", select the App ID you just created.

  5. For "Domains and Subdomains", enter the domain from the callback URL. Add any custom domains as well.

    Enter domains and the callback URL

    Enter the domain

  6. For "Return URLs", enter the callback URL copied in Step 1.

  7. Click "Save", "Continue", and "Register", then record the Service ID.

    Save the Service ID

Create a key​

This key signs the Client Secret.

  1. Open Keys and click "+".

    Create a key

  2. Enter a name, select "Sign in with Apple", and click "Configure". For "Primary App ID", select the App ID you just created.

    Select Sign in with Apple

    Select the Primary App ID

  3. Click "Save", "Continue", and "Register". Record the Key ID, then click "Download" to download the .p8 private key.

    Download the private key

Caution

The .p8 private key can be downloaded only once. If it is lost, create a new key.

Step 3: Generate the Client Secret​

The Client Secret is a JWT (JSON Web Token) signed with the .p8 private key.

Caution

It is valid for at most 180 days. Generate a new one before it expires and update the Client Secret in the console.

Install the dependency:

pip3 install PyJWT cryptography

Replace the four values below, run the script, and copy the printed JWT.

import time
import jwt

TEAM_ID = "" # Team ID from the Membership page
CLIENT_ID = "" # Service ID
KEY_ID = "" # Key ID from the Keys page
PRIVATE_KEY_PATH = "" # Path to the .p8 file

with open(PRIVATE_KEY_PATH) as f:
private_key = f.read()

now = int(time.time())
client_secret = jwt.encode(
{
"iss": TEAM_ID,
"iat": now,
"exp": now + 86400 * 180,
"aud": "https://appleid.apple.com",
"sub": CLIENT_ID,
},
private_key,
algorithm="ES256",
headers={"kid": KEY_ID},
)
print(client_secret)
SettingValue
TEAM_IDTeam ID from the Membership page
CLIENT_IDService ID
KEY_IDKey ID from the Keys page
PRIVATE_KEY_PATHPath to the .p8 file

Step 4: Enable Apple sign-in​

Return to the configuration page from Step 1, fill in the identity provider, then save and enable it.

Apple sign-in configuration

Open the editor

FieldValue
Client IDService ID created in Step 2
Client SecretJWT printed in Step 3
Scopeopenid email name by default; change it if needed

Enter the Client ID and Client Secret

Finish account linking, then save and enable the identity provider.

Account linking