2017-08-07 56 views
1

我想jwtauthentificationbundle整合與fosuserbundle,所以我可以爲我的REST API的令牌,但是當我跟郵遞員測試: 後http://127.0.0.1:8000/api/login_check 這是我的security.yml:LexikJWTAuthentificationBundle {「代碼」:401,「消息」:「壞憑據」}

安全: 編碼器: FOS \ UserBundle \型號\的UserInterface:bcrypt

providers: 
    fos_userbundle: 
     id: fos_user.user_provider.username 


firewalls: 

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


    login: 
     pattern: ^/api/login 
     stateless: true 
     anonymous: true 
     form_login: 
      check_path:    /api/login_check 
      username_parameter: username 
      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: ^/api 
     stateless: true 
     guard: 
      authenticators: 
       - lexik_jwt_authentication.jwt_token_authenticator 


    main: 
     anonymous: ~ 


access_control: 
     - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/api,  roles: IS_AUTHENTICATED_FULLY } 

,這是我的routing.yml:

app: 
resource: '@AppBundle/Controller/' 
type: annotation 

app_api: 
    resource: '@AppBundle/Controller/Api' 
    type: annotation 

api_login_check: 路徑:/ API/login_check

NelmioApiDocBundle: 資源: 「@ NelmioApiDocBundle /資源/配置/ routing.yml中」 前綴:/ API/DOC

fos_user: 資源:「@ FOSUserBundle/Resources/config/routing/all.xml」

任何幫助?

+0

我發現anwser是了when我跟郵遞員測試它,我必須 頭髮送數據:內容類型application/x-WWW窗體-urlencoded –

回答

0

您是否嘗試在登錄防火牆上指定您的提供者? 它給這樣的礦:

firewalls: 
    # disables authentication for assets and the profiler, adapt it according to your needs 
    dev: 
     pattern: ^/(_(profiler|wdt)|css|images|js)/ 
     security: false 
    login: 
     pattern: ^/api/login 
     stateless: true 
     anonymous: true 
     provider: fos_userbundle 
     form_login: 
      check_path:    /api/login_check 
      provider: main 
      success_handler:   lexik_jwt_authentication.handler.authentication_success 
      failure_handler:   lexik_jwt_authentication.handler.authentication_failure 
      require_previous_session: false 
+0

YES,我找到了解決方案;首先像你說的那樣:在lofin防火牆中添加提供程序,然後我使用內容類型應用程序/ x-www-form-urlencoded讓他在postman中請求標題。 itworks很好!謝謝 。 –