To create an Apple SSO login, you'll need to follow these steps:
Create an App ID and configure Sign in with Apple:
- Go to the Apple Developer Portal and sign in with your Apple Developer account.
- Click on your account.
- In the "Certificates, Ids & Profiles" section please select "Identifiers".
- Click the "+" button to create a new App ID.
- Choose "App" and click "Continue".
- Fill in the required fields:
- Description
- Bundle ID
- Under "Capabilities" select "Sign in with Apple".
Click "Continue" and then click "Register" to create the App ID.
After registering you should be redirected back to the identifiers page.
Create a Service ID for your web application:
- In the "Certificates, Ids & Profiles" section please select "Identifiers".
- Click the "+" button and select "Services IDs", then click "Continue".
- Fill in the required fields:
- Description
- Identifier - reversed domain
click "Continue" and then click "Register".
After registering you should be redirected back to the identifiers page.
- Click on the newly created Service ID, a details page will open.
Select the checkbox next to the "Sign in with Apple" capability, and click "Configure". - Add your domain and redirect URLs as follows:
- Add your domain in the "Domains and Subdomains" section. You'll need to verify your domain by following the instructions provided by Apple.
- Add your redirect URL(s) in the "Return URLs" section. This is where the user will be redirected to after a successful authentication.
After a successful configuration, confirm the list you’d like to add to this Services ID and click Done.
To complete the process, click Continue, then click Save.
Create a private key for client authentication:
- In the "Certificates, Ids & Profiles" section, click "Keys".
- Click the "+" button to create a new key.
- Fill in the key name, check "Sign in with Apple" and click "Configure".
- Select the primary App ID you created earlier, then click "Save" and "Continue".
- Review the key details and click "Register".
- Download the private key (.p8 file) and securely store it. You'll need this to authenticate your server.
Implement the Sign in with Apple button on your frontend:
- Add the "Sign in with Apple" button to your frontend following Apple's Human Interface Guidelines.
- In order to get the client secret for the verification in the backend that is mentioned below, run the following python script:
import jwt
from datetime import datetime, timedelta
client_id = 'CLIENT_SERVICE_ID'
team_id = 'APPLE_DEVELOPER_TEAM_ID'
private_key = '''-----BEGIN PRIVATE KEY-----
YOUR PRIVATE KEY
-----END PRIVATE KEY-----''' # Private key in PEM format
header = {
'alg': 'ES256',
'kid': YOUR_PRIVATE_KEY_ID # Key ID for your private key
}
payload = {
'iss': team_id,
'iat': datetime.utcnow(),
'exp': datetime.utcnow() + timedelta(days=180),# 180 days expiration time
'aud': 'https://appleid.apple.com',
'sub': client_id
}
client_secret = jwt.encode(payload, private_key, algorithm='ES256', headers=header)
print(client_secret)