zestic / graphql-auth-component
Requires
- php: ^8.3
- league/oauth2-server: ^9.1
- matomo/device-detector: ^6.4
- mll-lab/graphql-php-scalars: ^6.3
- nyholm/psr7: ^1.8
- psr/log: ^3.0
- robmorgan/phinx: ^0.15.4 | ^0.16
- symfony/dotenv: ^6.4|^7.0
- symfony/yaml: ^6.4|^7.0
- webonyx/graphql-php: ^15.0
Requires (Dev)
- ext-pdo: *
- phpunit/phpunit: ^11.4
- slope-it/clock-mock: ^0.4.0
README
A GraphQL authentication component with OAuth2 support, magic link authentication, and JWT tokens.
Setup
Generating OAuth2 Keys
Before using the authentication component, you need to generate the required OAuth2 keys:
composer run generate-keys
This script will generate:
- JWT Private/Public Key Pair: Used for signing and verifying JWT tokens
- Encryption Key: Used for encrypting authorization and refresh codes
The keys will be saved to:
config/jwt/private.key
- JWT private key (keep secure!)config/jwt/public.key
- JWT public keyconfig/autoload/auth.local.php
- Contains only the encryption key
Important: The script will fail if keys already exist to prevent accidental overwriting.
Key Generation Parameters
The script uses configurable OpenSSL parameters for JWT key generation:
-
digestAlg: Hash algorithm (
sha256
,sha384
,sha512
)sha256
: Fast, widely supported (default)sha384
: More secure, good balancesha512
: Most secure, slower
-
privateKeyBits: Key size in bits (
2048
,3072
,4096
)2048
: Fast, minimum recommended (default)3072
: Good security/performance balance4096
: Maximum security, slower
-
privateKeyType: Key algorithm (
RSA
,DSA
,DH
,EC
)RSA
: Most widely supported (default)EC
: Elliptic Curve, smaller keys, good performance
Docker Support
For Docker environments, you can override the key paths using environment variables:
export JWT_PRIVATE_KEY_PATH=/app/keys/jwt/private.key export JWT_PUBLIC_KEY_PATH=/app/keys/jwt/public.key export AUTH_LOCAL_CONFIG_PATH=/app/config/autoload/auth.local.php composer run generate-keys
Configuration
The component uses the following default configuration structure:
'auth' => [ 'jwt' => [ 'privateKeyPath' => 'config/jwt/private.key', 'publicKeyPath' => 'config/jwt/public.key', 'passphrase' => null, // Set via environment if needed 'keyGeneration' => [ 'digestAlg' => 'sha256', // sha256, sha384, sha512 'privateKeyBits' => 2048, // 2048, 3072, 4096 'privateKeyType' => 'RSA', // RSA, DSA, DH, EC ], ], 'token' => [ 'accessTokenTtl' => 60, // 1 hour (in minutes) 'loginTtl' => 10, // 10 minutes 'refreshTokenTtl' => 10080, // 1 week (in minutes) 'registrationTtl' => 1440, // 24 hours (in minutes) ], ]
Notifications
Need to create a class that implements SendVerificationEmailInterface and configure it