0

我的 REST API 必须有 jwt 身份验证。现在一切正常,但是当我尝试通过配对电子邮件/密码获取令牌时,出现错误:凭据错误。当我使用用户名/密码时,一切正常。我的安全.yml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        api_doc:
            pattern: ^/api/doc
            anonymous: true
            security: false

        login:
            pattern:  ^/login
            stateless: true
            anonymous: true
            form_login:
                check_path:               /login
                username_parameter:       username
                password_parameter:       password
                provider:                 fos_userbundle
                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

        password:
            pattern:    ^/user/passwords
            anonymous:  true
            security:   false

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

配置.yml

lexik_jwt_authentication:
    private_key_path:     '%jwt_private_key_path%'
    public_key_path:      '%jwt_public_key_path%'
    pass_phrase:          '%jwt_key_pass_phrase%'
    token_ttl:            '%jwt_token_ttl%'
    user_identity_field:  email
4

2 回答 2

1

所以答案是添加新的用户提供者:

providers:
        main_provider:
            entity: { class: UserBundle\Entity\User, property: email }

我不知道为什么默认的 fos_userprovider 不起作用。也许某些设置有误。

于 2017-09-10T18:08:55.530 回答
0

对于 check_path,它是 check_path: /login_check

于 2017-12-18T08:53:03.227 回答