LexikJWTAuthentificationBundle {"代码":401,"消息":"错误的凭据"}

时间:2017-08-07 10:22:11

标签: authentication jwt

我想将jwtauthentificationbundle与fosuserbundle集成,因此我可以为我的REST APi生成令牌,但是当我用邮递员测试它时: 发布http://127.0.0.1:8000/api/login_check 这是我的security.yml:

安全性:        编码器:             FOS \ UserBundle \ Model \ 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 / Resources / config / routing.yml"         前缀:/ api / doc

fos_user:         资源:" @ FOSUserBundle / Resources / config / routing / all.xml"

任何帮助??

1 个答案:

答案 0 :(得分: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