A Node.js utility for generating Apple Sign-In JWT tokens using your Apple Developer credentials.
This project generates JWT tokens required for Apple Sign-In authentication. The token serves as a client secret when implementing Sign in with Apple on your web application or backend service.
- Node.js (v14 or higher)
- Apple Developer Account
- Apple Developer credentials (Team ID, Key ID, Services ID)
- Apple private key file (.p8)
npm installCopy the environment template and fill in your Apple Developer credentials:
cp env.example .envEdit the .env file with your actual values:
# Your Apple Team ID (found in your Apple Developer account)
APPLE_TEAM_ID=YOUR_TEAM_ID
# Your Apple Key ID (from the .p8 key file you downloaded)
APPLE_KEY_ID=YOUR_KEY_ID
# Your Apple Client ID (Services ID for Sign in with Apple)
APPLE_CLIENT_ID=com.flownty.app.web
# Path to your .p8 private key file
APPLE_PRIVATE_KEY_PATH=./AuthKey_G5A82D6H5R.p8Place your Apple private key file (.p8) in the project root directory. The filename should match the APPLE_PRIVATE_KEY_PATH in your .env file.
Generate a JWT token:
node index.jsThe script will output a JWT token to the console. This token can be used as a client secret for Apple Sign-In authentication.
To obtain the required credentials:
- Team ID: Found in your Apple Developer account settings
- Key ID: Generated when you create a new key in your Apple Developer account
- Services ID: Create a Services ID for Sign in with Apple
- Private Key: Download the
.p8key file when creating the key
- Go to Apple Developer Console
- Navigate to "Certificates, Identifiers & Profiles"
- Create a new Key under "Keys" section
- Enable "Sign in with Apple" for the key
- Download the
.p8file - Note the Key ID from the key details
- Create a Services ID under "Identifiers" for your web application
The generated JWT token includes:
- Issuer (iss): Your Apple Team ID
- Issued At (iat): Current timestamp
- Expiration (exp): 6 months from issue date (Apple's maximum limit)
- Audience (aud):
https://appleid.apple.com - Subject (sub): Your Services ID (Client ID)
- Never commit your
.envfile or.p8key files to version control - Keep your private key secure and rotate it regularly
- The generated token expires after 6 months (Apple's hard limit)
- Use HTTPS when transmitting tokens
- File not found error: Ensure the
.p8key file path is correct in your.env - Invalid credentials: Verify your Team ID, Key ID, and Services ID are correct
- Token validation errors: Ensure your Services ID is properly configured for Sign in with Apple
Could not read private key: Check the file path and permissions- Invalid JWT claims: Verify your Apple Developer credentials
ISC
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
For Apple Sign-In specific issues, refer to: