我正在使用LexikJWTBundle來驗證symfony2REST API的離子angularjs應用。LexikJWTBundle:找不到POST/api/login_check的路由
我的問題是,當我嘗試對用戶進行身份驗證時,Symfony返回:找不到POST/api/login_check的路由。
編輯 我已經把路由放在我的休息路由文件中,所以得到的路由是/ api/api/login_check。 現在的錯誤是:無法找到路徑「/ api/login_check」的控制器。 它看起來像LexikJWTBundle不會攔截呼叫。 結束編輯
我確切的說,我的API是工作正常W/O認證,並通過NelmioCorsBundle使用CORS。
這裏是我的routing.yml部分:
api_login_check:
path: /api/login_check
這裏是我的config.yml
lexik_jwt_authentication:
private_key_path: %kernel.root_dir%/var/jwt/private.pem # ssh private key path
public_key_path: %kernel.root_dir%/var/jwt/public.pem # ssh public key path
pass_phrase: 'passphrase' # ssh key pass phrase
token_ttl: 86400 # token ttl - defaults to 86400
這裏是我的security.yml:
# app/config/security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
dev:
pattern: ^/{_{profiler|wdt}}/
security: false
switch_user: true
main:
pattern: .*
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
switch_user: true
# JWT SETUP
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
# JWT SETUP
api:
pattern: ^/api
stateless: true
lexik_jwt:
authorization_header:
enabled: true
prefix: Bearer
query_parameter:
enabled: true
name: bearer
access_control:
# JWT SETUP
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
,你可以在上面看到,在創建爲每演示每個文檔和作爲[沙盒(HTTPS路線:// github上。 COM/slashfan/LexikJWTAuthenticationBundleSandbox)。而且我通過FOSUserBundle的身份驗證工作正常。我的問題與通過lexikjwtbundle進行授權有關,然後應該提供JWT。 – curuba
@curuba創建一個空控制器並指向你的'api_login_check'。 – keyboardSmasher
嗨@keyboardSmasher和thx很多幫助我。這就是我用'return new Response('',401)'所做的事情''。現在,當我用證書卷曲時,我收到一個401響應,似乎認爲Lexikjwtbudnle不會攔截請求...我可能錯過了一些東西。是否應該在另一個文件中通知此路線? – curuba