jubaopen / jwt-authentication-bundle
This bundle provides JWT authentication for your Symfony REST API
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/jubaopen/jwt-authentication-bundle
Requires
- php: ^5.5|^7.0
- doctrine/doctrine-bundle: ~1.4
- doctrine/orm: ^2.4.8
- namshi/jose: ^7.2
- symfony/console: ^2.8|^3.0
- symfony/framework-bundle: ^2.8|^3.0
- symfony/security-bundle: ^2.8|^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.1
- lcobucci/jwt: ~3.2
- phpunit/phpunit: ^4.8|^5.0
- symfony/browser-kit: ^2.8|^3.0
- symfony/dom-crawler: ^2.8|^3.0
- symfony/phpunit-bridge: ~3.2
- symfony/yaml: ^2.8|^3.0
This package is not auto-updated.
Last update: 2025-10-21 22:11:10 UTC
README
@(使用说明)[JbpJWTAuthenticationBundle]
1.生成秘钥(公钥和私钥)
定位到console所在目录,执行
php console pem:create
输入私钥密码生成;
2.引入Bundle
在AppKernel中的registerBundles方法中加入:
new JubaopenTech\JWTAuthenticationBundle\JbpJWTAuthenticationBundle(),
在config.php文件加入以下配置:
jbp_jwt_authentication:
private_key_path: '%kernel.root_dir%/../var/jwt/private.pem'
public_key_path: '%kernel.root_dir%/../var/jwt/private.pem'
pass_phrase: '私钥密码'
token_ttl: 3600
refresh_ttl: 100
user_identity_field: username
encoder:
service: jbp_jwt_authentication.encoder.default
crypto_engine: openssl
signature_algorithm: RS256
token_extractors:
authorization_header:
enabled: true
prefix: '%authorization_prefix%'
name: '%authorization_header_key%'
cookie:
enabled: false
name: '%authorization_prefix%'
query_parameter:parameter
enabled: false
name: '%authorization_prefix%'
3.获取Token
请求地址:logincheck
请求参数:
_username:用户名
_password:密码(md5)
返回值:
{"token":"token"}
4.请求验证
前缀:jwt
请求头部添加Authorization参数
$.ajax({ ... headers:{ Authorization:前缀+空格+token }, ... })