大蒜 / auth
Garlic服务JWT令牌授权
1.1.2
2019-07-04 10:18 UTC
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-09-19 09:05:00 UTC
README
JWT令牌授权包
安装
1. 运行
$ composer require garlic/auth
2. 添加到 .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. 添加安全配置(更改 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. 添加 Lexik jwt 包配置(更改 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
使用
1. 从授权服务生成JWT令牌
2. 将JWT令牌添加到请求头中
示例
Authorization: Body.Of.Token