2016-03-02 50 views
0

我想第一次設置LexikJWTAuthenticationBundle(Symfony 3)。Symfony2 LexikJWTAuthenticationBundle未能正常工作login_check

一切工作順利,直到我試圖對受ROLE_USER限制的URL發出GET請求。

我可以向login_check url發送一個POST請求,該請求返回該令牌,之後我試圖對上述URL進行GET請求。

我在請求標題(Authorization:Bearer ...)上添加了令牌,我可以在Google Chrome瀏覽器的網絡標籤上看到標題。但是,迴應總是會回到「401 Unauthorized」。我不確定我在這裏錯過了什麼,並且一直試圖解決這個問題,並且搜索了每個論壇。

這裏是我的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 } 

這裏是headers being sent 和我ApiUser.php的usermodel我有getRoles這樣實現(測試)()方法:

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

我錯過了什麼嗎?

回答

0

經過幾天審查bundel的代碼,我發現問題是該包無法讀取公鑰,更改文件的權限修復了問題。