Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dimkinthepro/jwt-auth-bundle
JWT authentication bundle for Symfony
https://github.com/dimkinthepro/jwt-auth-bundle
jwt jwt-auth jwt-authentication jwt-token php81 symfony-bundle
Last synced: about 1 month ago
JSON representation
JWT authentication bundle for Symfony
- Host: GitHub
- URL: https://github.com/dimkinthepro/jwt-auth-bundle
- Owner: dimkinthepro
- Created: 2023-09-10T15:36:23.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-02T16:25:21.000Z (2 months ago)
- Last Synced: 2024-09-30T16:04:40.796Z (about 2 months ago)
- Topics: jwt, jwt-auth, jwt-authentication, jwt-token, php81, symfony-bundle
- Language: PHP
- Homepage:
- Size: 64.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# JWT authentication bundle for Symfony
### 1. Installation:
```bash
composer require dimkinthepro/jwt-auth-bundle
```### 2. Check bundles config:
```php
# config/bundles.phpreturn [
#...
Dimkinthepro\JwtAuth\DimkintheproJwtAuthBundle::class => ['all' => true],
];
```### 3. Create bundle configuration:
```yaml
# config/packages/dimkinthepro_jwt_auth.yaml
dimkinthepro_jwt_auth:
public_key_path: '%kernel.project_dir%/var/dimkinthepro/jwt-auth-bundle/public.pem'
private_key_path: '%kernel.project_dir%/var/dimkinthepro/jwt-auth-bundle/private.pem'
passphrase: 'SomeRandomPassPhrase'
token_ttl: 36000 # 10 hour
algorithm: 'RS512'
refresh_token_ttl: 2592000 # 1 month
refresh_token_length: 128 # max=255
```### 4. Add security configuration
```yaml
# config/packages/security.yamlsecurity:
#...
main:
lazy: true
auth_jwt: ~
pattern: ^/api/
stateless: true
provider: your_app_user_provider
json_login:
check_path: /api/user/login
username_path: email
success_handler: Dimkinthepro\JwtAuth\Infrastructure\Security\SuccessAuthenticationHandler
failure_handler: Dimkinthepro\JwtAuth\Infrastructure\Security\FailAuthenticationHandler
```### 5. Add doctrine configuration
```yaml
# config/packages/doctrine.yaml
doctrine:
#...
orm:
#...
mappings:
#...
DimkintheproJwtAuthBundle:
is_bundle: true
type: xml
prefix: Dimkinthepro\JwtAuth\Domain\Entity
```### 6. Add Routes
```yaml
# config/routes.yaml
api_login:
path: /api/login
methods: [POST]api_token_refresh:
path: /api/token-refresh
controller: Dimkinthepro\JwtAuth\Infrastructure\Controller\TokenRefreshAction
methods: [POST]
```### 7. Generate migrations:
```bash
php bin/console doctrine:migrations:diffphp bin/console doctrine:migrations:migrate
```### 8. Generate key pair:
```bash
php bin/console dimkinthepro:jwt-auth:generate-key-pair
```