更改 LexikJWTAuthenticationBundle 中的默认用户名字段

问题描述 投票:0回答:1

我想将我的 symfony 2.8 应用程序更新到版本 5.4。

我使用 fos rest 包作为 api,使用 jwt auth 包来使用令牌进行身份验证。我的问题是检索令牌需要版本 2 上的“_username”字段和版本 5 上的“username”字段。

您能告诉我如何修改此字段,使其能够对应我的旧配置吗?

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%'

我的 scurity.yaml

firewalls:
    login:
        pattern:  ^/api/login
        stateless: true
        anonymous: true
        form_login:
            check_path:               /api/login_check
            success_handler:          lexik_jwt_authentication.handler.authentication_success
            failure_handler:          lexik_jwt_authentication.handler.authentication_failure
            require_previous_session: false

    refresh:
        pattern:  ^/api/token/refresh
        stateless: true
        anonymous: true

    api:
        pattern:   ^/api/secure
        stateless: true
        guard:
            authenticators:
                - word.user.guard.jwt_token_authenticator

    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_token_generator: security.csrf.token_manager
        logout:       true
        anonymous:    true
php api symfony fosrestbundle lexikjwtauthbundle
1个回答
2
投票

您可以使用

username
配置文件中的
username_path
参数更改默认的
security.yaml
字段:

firewalls:
    login:
        pattern:  ^/api/login
        stateless: true
        anonymous: true
        form_login:
            username_path: YOUR_NEEDED_FIELD
            check_path:  /api/login_check
      
© www.soinside.com 2019 - 2024. All rights reserved.