LexikJWTAuthenticationBundle | JwtToken正在运行,但是身份验证显示“访问此资源需要完全身份验证”。

时间:2020-01-11 15:08:30

标签: php symfony lexikjwtauthbundle

我的令牌登录工作正常,但是如果我想知道自己是否完全按照自己的路线登录:

UserController.php

/**
  * @Route("/auth/me", name="userIsAuthenticated")
  */
public function authenticated()
{
    return new Response(':-)', Response::HTTP_OK);
}

它只是显示

Symfony \ Component \ HttpKernel \ Exception \ HttpException: 要访问此资源,必须进行完全身份验证。

我发现在StackTrace中仅出现“ symfony \ security-http \ Firewall”,而Lexik没有显示?

如果令牌有效并且它全部有效,我也尝试了jwt.io。

security.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 }

1 个答案:

答案 0 :(得分:2)

问题是我的/ auth / me路由将使用/ auth防火墙。 / auth防火墙在配置中没有lexik身份验证器。

我只需要将^/auth更改为^/auth$,一切都很好。

$符号可阻止防火墙进行类似

的传送
/auth/me
/auth/example
/auth/anotherexample
...

它仅使用完全匹配的/auth路线:-)