Skip to content

A Node.js utility for generating Apple Sign-In JWT tokens using your Apple Developer credentials.

ugi-dev/jwt-apple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apple JWT Generator

A Node.js utility for generating Apple Sign-In JWT tokens using your Apple Developer credentials.

Overview

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.

Prerequisites

  • Node.js (v14 or higher)
  • Apple Developer Account
  • Apple Developer credentials (Team ID, Key ID, Services ID)
  • Apple private key file (.p8)

Setup

1. Install Dependencies

npm install

2. Configure Environment Variables

Copy the environment template and fill in your Apple Developer credentials:

cp env.example .env

Edit 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.p8

3. Add Your Apple Private Key

Place your Apple private key file (.p8) in the project root directory. The filename should match the APPLE_PRIVATE_KEY_PATH in your .env file.

Usage

Generate a JWT token:

node index.js

The script will output a JWT token to the console. This token can be used as a client secret for Apple Sign-In authentication.

Apple Developer Setup

To obtain the required credentials:

  1. Team ID: Found in your Apple Developer account settings
  2. Key ID: Generated when you create a new key in your Apple Developer account
  3. Services ID: Create a Services ID for Sign in with Apple
  4. Private Key: Download the .p8 key file when creating the key

Creating Apple Developer Credentials

  1. Go to Apple Developer Console
  2. Navigate to "Certificates, Identifiers & Profiles"
  3. Create a new Key under "Keys" section
  4. Enable "Sign in with Apple" for the key
  5. Download the .p8 file
  6. Note the Key ID from the key details
  7. Create a Services ID under "Identifiers" for your web application

Token Details

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)

Security Notes

  • Never commit your .env file or .p8 key 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

Troubleshooting

Common Issues

  1. File not found error: Ensure the .p8 key file path is correct in your .env
  2. Invalid credentials: Verify your Team ID, Key ID, and Services ID are correct
  3. Token validation errors: Ensure your Services ID is properly configured for Sign in with Apple

Error Messages

  • Could not read private key: Check the file path and permissions
  • Invalid JWT claims: Verify your Apple Developer credentials

License

ISC

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

Support

For Apple Sign-In specific issues, refer to:

About

A Node.js utility for generating Apple Sign-In JWT tokens using your Apple Developer credentials.

Topics

Resources

Stars

Watchers

Forks