ciricihq / jwt-client-bundle
Symfony 客户端,用于管理针对外部 JWT 服务器进行 JWT 登录或检查传入的 JWT 令牌是否有效
dev-master
2018-09-26 16:42 UTC
Requires
- php: >=5.5
- eightpoints/guzzle-bundle: ^7.2
- namshi/jose: ^6.0
Requires (Dev)
- lexik/jwt-authentication-bundle: ^1.5
- phpunit/phpunit: 4.8.*|~5.2
- symfony/symfony: ~2.3.1|~2.7|~3.0
Suggests
- eightpoints/guzzle-bundle: In order to achieve the external JWT server authentication
This package is auto-updated.
Last update: 2024-09-08 06:38:28 UTC
README
此 Bundle 用于针对 JWT 服务器进行登录或检查 JWT 令牌的有效性
它基于 这些说明 构建。
警告!此 Bundle 处于开发中,尚未准备好投入生产
安装
composer require ciricihq/jwt-client-bundle:dev-master
然后将其添加到 AppKernel.php
$bundles = [ ... new Cirici\JWTClientBundle\CiriciJWTClientBundle(), ... ];
配置
如果您计划将此 Bundle 用作针对 JWT 服务器进行身份验证的服务,您应该在 config.yml
中添加外部令牌验证器以加载此 Bundle
cirici_jwt_client: use_external_jwt_api: true external_api: "@eight_points_guzzle.client.api_jwt" jwt_token_path: /jwt/token # Endpoint where the token POST request will be done
并且您必须使用 Guzzle 配置定义 API
guzzle: clients: api_jwt: base_url: %api_jwt_base_url%
配置针对外部 JWT 服务器的登录表单的安全
为了使此 Bundle 正常运行,您应该像这样定义您的 security.yml
# To get started with security, check out the documentation: security: providers: token: id: project.token.user_provider firewalls: # disables authentication for assets and the profiler, adapt it according to your needs dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false main: pattern: ^/ provider: token anonymous: true simple_form: authenticator: project.token.external_authenticator check_path: login_check login_path: login # user_referer: true failure_path: login logout: path: /logout target: login remember_me: secret: '%secret%' lifetime: 86400 path: / access_control: - { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/registration, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/, role: ROLE_ADMIN }
在 routes.yml
中,您必须添加一个登录路径,如以下行,对于登录失败重定向,并添加 Bundle 路由导入
jwt_client: resource: '@CiriciJWTClientBundle/Resources/config/routing.yml' prefix: / login: path: /login
设置自定义用户类以用于传入请求
如果您希望将传入的令牌调用映射到自定义用户类而不是 ApiUser,您应该在您的自定义用户类中实现 Cirici\JWTClientBundle\Security\ApiUserInterface
。然后配置您的自定义用户类在 config.yml
cirici_jwt_client: api_user_class: '\AppBundle\Entity\User'
配置以验证传入的认证令牌
在您的 security.yml
防火墙中,您必须添加以下行
security: providers: token: id: project.token.user_provider firewalls: api: pattern: ^/api/user stateless: true guard: provider: token authenticators: - project.token.authenticator
扩展登录模板
如果您想修改默认登录模板,您应该创建以下文件夹
mkdir -P app/Resources/CiriciJWTClientBundle/views/Security
然后复制 Bundle 中的 login.html.twig
文件到创建的文件夹中。
现在,您的应用程序将加载刚刚复制的登录模板,您可以修改它而不需要修改 Bundle 中的模板。 :)