garlic / auth
JWT token authorization for Garlic services
Installs: 3 378
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 8
Forks: 1
Open Issues: 0
Requires
- lcobucci/jwt: ^3.2
- lexik/jwt-authentication-bundle: ^2.4
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-11-14 09:36:21 UTC
README
JWT token authorization bundle
Installation
1. Run:
$ composer require garlic/auth
2. Add to .env.dist (.env):
# Required JWT_PUBLIC_KEY_PATH='config/jwt/public.pem' # Optional JWT_PRIVATE_KEY_PATH='' JWT_KEY_PASS_PHRASE='passPhrase' JWT_TOKEN_TTL='3600' JWT_USER_IDENTITY_FIELD='email' JWT_USER_CLASS='Garlic\Auth\Security\User' # User auth settings USER_ADMIN_USERNAME=admin USER_ADMIN_PASSWORD=securePassword USER_SERVICE_NAME=users
3. Add Security configuration (change packages/security.yml):
security: providers: jwt_provider: lexik_jwt: class: Garlic\Auth\Security\User firewalls: main: pattern: ^/ stateless: true anonymous: true guard: authenticators: - lexik_jwt_authentication.jwt_token_authenticator
4. Add Lexik jwt bundle configuration (change lexik_jwt_authentication.yml):
lexik_jwt_authentication: private_key_path: '%kernel.project_dir%/%env(JWT_PRIVATE_KEY_PATH)%' public_key_path: '%kernel.project_dir%/%env(JWT_PUBLIC_KEY_PATH)%' pass_phrase: '%env(JWT_PASSPHRASE)%' token_ttl: '%env(JWT_TOKEN_TTL)%' user_identity_field: email encoder: service: lexik_jwt_authentication.encoder.lcobucci crypto_engine: openssl signature_algorithm: RS384 token_extractors: authorization_header: enabled: true prefix: '' name: Authorization
Using
1. Make JWT token from the authorization service
2. Add JWT token to to request headers:
Example:
Authorization: Body.Of.Token