lade-devs / socialite-apple-jwt-generator
Laravel Socialite Apple Login Helper to generate and manage Client Secret
Package info
github.com/lade-devs/socialite-apple-jwt-generator
pkg:composer/lade-devs/socialite-apple-jwt-generator
Requires
- php: ^8.3
- laravel/framework: ^12.0|^13.0
- lcobucci/jwt: ^5.6
Requires (Dev)
- orchestra/testbench: ^10.11|^11.0
- phpunit/phpunit: ^12.5
README
Laravel Socialite helper to generate and auto-refresh the Apple Sign-In client secret — a signed ES256 JWT required by Apple's OAuth flow.
Apple enforces a maximum 6-month (180-day) expiry on client secrets.
This package handles generation, storage in.env, and scheduled automatic refresh.
Requirements
| Version | |
|---|---|
| PHP | ^8.3 |
| Laravel | ^12.0 |
| lcobucci/jwt | ^5.6 |
Installation
composer require lade-devs/socialite-apple-jwt-generator
Laravel's package auto-discovery registers the service provider automatically.
Apple Developer Setup
You will need the following from the Apple Developer Portal:
- Team ID – found under Membership.
- Key ID – found under Certificates, Identifiers & Profiles → Keys.
- Client ID – your Services ID identifier (e.g.
com.example.signin). - Auth Key file (
.p8) – downloaded when you create the key.
Place it insidestorage/app/and note the filename, e.g.AuthKey_ABCDEF1234.p8. - Redirect URI – the fully-qualified HTTPS callback URL registered in your Services ID.
Configuration
1. Run the interactive setup
php artisan socialite:apple
The command prompts for all five values above plus a refresh interval (default 180 days), generates the client secret JWT, and writes everything to .env.
2. Add to config/services.php
This ensures values survive php artisan config:cache in production:
'apple' => [ 'client_id' => env('APPLE_CLIENT_ID'), 'client_secret' => env('APPLE_CLIENT_SECRET'), 'redirect' => env('APPLE_REDIRECT_URI'), 'key_id' => env('APPLE_KEY_ID'), 'team_id' => env('APPLE_TEAM_ID'), 'auth_key' => env('APPLE_AUTH_KEY'), 'client_secret_updated_at' => env('APPLE_CLIENT_SECRET_UPDATED_AT'), 'refresh_token_interval_days' => env('APPLE_REFRESH_TOKEN_INTERVAL_DAYS', 180), ],
Automatic Secret Refresh
The package registers a scheduled task that checks every minute whether the secret is due for renewal based on APPLE_REFRESH_TOKEN_INTERVAL_DAYS and APPLE_CLIENT_SECRET_UPDATED_AT.
Make sure Laravel's task scheduler is running:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
Manual refresh
php artisan socialite:apple --refresh
Environment Variables
| Variable | Description |
|---|---|
APPLE_CLIENT_ID |
Your Services ID |
APPLE_CLIENT_SECRET |
Generated JWT (managed by this package) |
APPLE_REDIRECT_URI |
OAuth callback URL |
APPLE_KEY_ID |
Key ID from the developer portal |
APPLE_TEAM_ID |
Team ID from the developer portal |
APPLE_AUTH_KEY |
Filename of the .p8 key in storage/app/ |
APPLE_CLIENT_SECRET_UPDATED_AT |
Unix timestamp of last generation (auto-managed) |
APPLE_REFRESH_TOKEN_INTERVAL_DAYS |
Days between refreshes (1–180, default 180) |
Running Tests
composer install vendor/bin/phpunit
Changelog
See CHANGELOG.md.
License
MIT © LadeDevs