简体   繁体   English

Symfony2 LexikJWTAuthenticationBundle在login_check之后无法正常工作

[英]Symfony2 LexikJWTAuthenticationBundle not working past login_check

I am trying to set up LexikJWTAuthenticationBundle (Symfony 3) for the first time. 我正在尝试首次设置LexikJWTAuthenticationBundle(Symfony 3)。

Everything worked smoothly until I tried to make a GET request to an url that was restricted by ROLE_USER. 一切工作都进行得很顺利,直到我尝试向ROLE_USER限制的网址发出GET请求。

I can make a POST request to the login_check url, which returns the token, and after that I am trying to make the GET request to the url mentioned above. 我可以向login_check URL发出POST请求,该请求返回令牌,然后尝试对上述URL进行GET请求。

I am adding the token on the request headers (Authorization: Bearer ...) and I can see the header being sent on the Google chrome's network tab. 我在请求标头(授权:承载...)上添加了令牌,并且可以在Google chrome的“网络”标签上看到发送的标头。 However the response always comes back as "401 Unauthorized". 但是,响应始终返回为“ 401未经授权”。 I am not sure what I missed here and have been trying to figure this out for days now and searched every forum possible. 我不确定我在这里错过了什么,并且已经尝试了好几天了,并搜索了每个论坛。

Here is my security.yml 这是我的security.yml

security:

user-providers
    providers:
        db_provider:
            entity:
                class: ApiBundle:ApiUser
                property: email

encoders:
    ApiBundle\Entity\ApiUser:
        algorithm: bcrypt

firewalls:

    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    login:
        pattern:  ^/login_check
        provider: db_provider
        stateless: true
        anonymous: true
        form_login:
            check_path:               api_login_check
            username_parameter:       email
            password_parameter:       password
            success_handler:          lexik_jwt_authentication.handler.authentication_success
            failure_handler:          lexik_jwt_authentication.handler.authentication_failure
            require_previous_session: false

    api:
        pattern:   ^/
        stateless: true
        lexik_jwt:
            authorization_header:
                enabled: true
                prefix:  Bearer
            query_parameter:
                enabled: false
                name:    bearer

access_control:
    - { path: ^/testpage,    roles: ROLE_USER }
    - { path: ^/register,    roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/login_check, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/,            roles: IS_AUTHENTICATED_ANONYMOUSLY }

Here are the headers being sent And on My ApiUser.php UserModel I have the getRoles() method implemented like this (for testing): 这是要发送标头,并且在My ApiUser.php UserModel上,我实现了这样的getRoles()方法(用于测试):

public function getRoles()
{
    return ['ROLE_USER'];
}

Have I missed anything? 我错过了什么吗?

经过两天的审查,Bundle的代码后,我发现问题在于该捆绑包无法读取公钥,更改文件的权限解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM