我的 token 登录工作正常,但如果我尝试知道我是否通过我的路线完全登录:
UserController.php
/**
* @Route("/auth/me", name="userIsAuthenticated")
*/
public function authenticated()
{
return new Response(':-)', Response::HTTP_OK);
}
它只是显示
Symfony\Component\HttpKernel\Exception\HttpException: Full authentication is required to access this resource.
我发现在 StackTrace 中只出现“symfony\security-http\Firewall”,而 Lexik 没有任何内容?
如果 token 有效,我也尝试了 jwt.io,并且它的工作原理全部有效。
安全.yaml
security:
encoders:
App\Entity\User:
algorithm: auto
providers:
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/auth
stateless: true
anonymous: true
json_login:
check_path: /auth
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
api:
pattern: ^/
stateless: true
provider: app_user_provider
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
access_control:
- { path: ^/auth/me, roles: IS_AUTHENTICATED_FULLY }
最佳答案
问题是我的/auth/me 路由将使用/auth 防火墙。/auth 防火墙的配置中没有 lexik 验证器。
我只需要将 ^/auth
更改为 ^/auth$
就可以了。
$ 符号会阻止防火墙执行类似的操作
/auth/me
/auth/example
/auth/anotherexample
...
它仅使用完全匹配的 /auth
路由:-)
关于php - LexikJWTAuthenticationBundle | LexikJWTAuthenticationBundle | LexikJWTAuthenticationBundle | LexikJWTAuthenticationBundle | LexikJWTAuthenticationBundle | JwtToken 正在工作,但身份验证显示 "Full authentication is required to access this resource.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59695638/