dimkinthepro / jwt-auth-bundle
此组件提供JWT认证
1.0.0
2024-09-02 16:21 UTC
Requires
- php: >=8.1
- ext-openssl: *
- doctrine/doctrine-bundle: ^2 || ^3
- doctrine/orm: ^2 || ^3
- symfony/config: ^5 || ^6 || ^7
- symfony/dependency-injection: ^6 || ^7
- symfony/dotenv: ^6 || ^7
- symfony/form: ^6 || ^7
- symfony/framework-bundle: ^6 || ^7
- symfony/http-kernel: ^6 || ^7
- symfony/orm-pack: ^2 || ^3
- symfony/security-bundle: ^6 || ^7
- symfony/validator: ^6 || ^7
Requires (Dev)
- fakerphp/faker: ^1.21
- friendsofphp/php-cs-fixer: ^3.16
- phpstan/phpstan: ^1.10
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.7
- symfony/browser-kit: ^6.2
- symfony/console: ^6.2
- symfony/yaml: *
This package is auto-updated.
Last update: 2024-10-02 16:36:29 UTC
README
1. 安装
composer require dimkinthepro/jwt-auth-bundle
2. 检查组件配置
# config/bundles.php return [ #... Dimkinthepro\JwtAuth\DimkintheproJwtAuthBundle::class => ['all' => true], ];
3. 创建组件配置
# 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. 添加安全配置
# config/packages/security.yaml security: #... 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. 添加Doctrine配置
# config/packages/doctrine.yaml doctrine: #... orm: #... mappings: #... DimkintheproJwtAuthBundle: is_bundle: true type: xml prefix: Dimkinthepro\JwtAuth\Domain\Entity
6. 添加路由
# 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. 生成迁移文件
php bin/console doctrine:migrations:diff php bin/console doctrine:migrations:migrate
8. 生成密钥对
php bin/console dimkinthepro:jwt-auth:generate-key-pair