php - LexikJWTAuthenticationBundle | LexikJWTAuthenticationBundle | LexikJWTAuthenticationBundle | LexikJWTAuthenticationBundle | LexikJWTAuthenticationBundle | JwtToken 正在工作,但身份验证显示 "Full authentication is required to access this resource."

标签 php symfony lexikjwtauthbundle

我的 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/

相关文章:

forms - 如何在Symfony2中的表单模板中自定义form_label block ?

file-upload - Symfony2 : Resizing uploaded images

symfony4 - Symfony 4 : Test DB for JWT and Behat

Symfony 2 FOSUserBundle 具有其余登录和注册功能

php - 如何连接两个mysql表

php - MySQL 基准测试

php - Symfony 3 - (文件路径)的定义没有类属性并且似乎引用了全局命名空间中的类或接口(interface)

Symfony JWT - 使用 symfony lexik JWT 身份验证包更改登录方式

具有高级数据库结构的 PHP 和真正的 MVC 结构

php - 加载动态选择 - PHP VS AJAX