jwtrefreshtokenbundle更改user_identity_field symfony 5.4+ apiplatform

发布于 2025-01-22 21:13:17 字数 844 浏览 0 评论 0原文

我正在使用:SYMFONY 5.4 + APIPLATFORM + JWTREFRESHTOKENBUNDLE 1.1

JWTREFRESHTOKENBUNDLED =>

https://github.com/markitosgv/jwtrefreshtokenbundle无法更改此问题:

  • 我试图更改yaml =>

    gesdinet_jwt_refresh_token:

    user_identity_field:电子邮件

    user_provider:app_user_provider

  • 我尝试在我的用户提供者(app_user_provider)entity user.php:

    public函数getUserIdentifier():字符串 {

    返回(字符串)$ this-> id; }

现在,我可以获得的越好是将ID代替我的数据库中的“用户名”列中的电子邮件,但是一旦我尝试刷新令牌,我就会得到此消息=> “ 401”无效的凭据”。

我试图拥有“ ID”,而不是“电子邮件”作为User_identity_field。

有人找到了解决方案吗? 谢谢。

I am using : Symfony 5.4 + ApiPlatform + JWTRefreshTokenBundle 1.1

JWTRefreshTokenBundle => https://github.com/markitosgv/JWTRefreshTokenBundle

I need to change this parameter "user_identity_field" but there is no way to change this :

  • I tried to change the Yaml =>

    gesdinet_jwt_refresh_token:

    user_identity_field: email

    user_provider: app_user_provider

  • I tried to modify this function in my user provider (app_user_provider) entity User.php :

    public function getUserIdentifier(): string
    {

    return (string) $this->id;
    }

Right now the better I can get is to have the ID instead of the E-mail in the user name column in my database, but as soon as I try to refresh the token, I get this message => " 401 "Invalid credentials".

I am tried to have "ID" instead of "E-MAIL" as user_identity_field.

Has anyone found a solution ?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮凉 2025-01-29 21:13:17

SF 5,4+

#gesdinet_jwt_refresh_token.yaml

gesdinet_jwt_refresh_token:
    user_identity_field: email
    ttl:      2592000
    firewall: login
    user_provider: security.user.provider.concrete.app_user_provider

Sf 5,4+

#gesdinet_jwt_refresh_token.yaml

gesdinet_jwt_refresh_token:
    user_identity_field: email
    ttl:      2592000
    firewall: login
    user_provider: security.user.provider.concrete.app_user_provider
变身佩奇 2025-01-29 21:13:17

我认为您需要在安全性中更改App_user_provider.yaml文件:

app_user_provider:
        entity:
            class: App\Entity\User
            property: id
jwt:
        lexik_jwt:
            class: App\Entity\User 

我认为问题是:Symfony尝试使用App_USER_PROVIDER对用户进行认证,并且您遇到了冲突,因为ID在JWT中,但框架搜索了电子邮件。
为了验证您可以在:

i think you need to change the app_user_provider in the security.yaml file :

app_user_provider:
        entity:
            class: App\Entity\User
            property: id
jwt:
        lexik_jwt:
            class: App\Entity\User 

i think the problem is : symfony try to authneticate user with the app_user_provider and you have a conflict because id's are in your JWT but framework search for email.
For verify that you can check your tokens on : https://jwt.io/

花想c 2025-01-29 21:13:17

Jwtrefreshtokenbundle(gesdinet/jwt-refresh-token-bundle)是在lexik/jwt-authentication-bundle),这是定义user_identity_field配置的捆绑包:

# config/packages/lexik_jwt_authentication.yaml
lexik_jwt_authentication:
    user_identity_field: 'email'

The JWTRefreshTokenBundle (gesdinet/jwt-refresh-token-bundle) is build upon the JWTAuthenticationBundle (lexik/jwt-authentication-bundle), which is the bundle that defines the user_identity_field configuration:

# config/packages/lexik_jwt_authentication.yaml
lexik_jwt_authentication:
    user_identity_field: 'email'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文