【问题标题】:JWTRefreshTokenBundle change user_identity_field Symfony 5.4 + ApiPlatformJWTRefreshTokenBundle 更改 user_identity_field Symfony 5.4 + ApiPlatform
【发布时间】:2022-11-10 09:26:57
【问题描述】:
我正在使用:Symfony 5.4 + ApiPlatform + JWTRefreshTokenBundle 1.1
JWTRefreshTokenBundle => https://github.com/markitosgv/JWTRefreshTokenBundle
我需要更改此参数“user_identity_field”,但无法更改:
-
我试图改变 Yaml =>
gesdinet_jwt_refresh_token:
user_identity_field: email
user_provider: app_user_provider
-
我试图在我的用户提供程序 (app_user_provider) 实体 User.php 中修改此函数:
public function getUserIdentifier(): string
{
return (string) $this->id;
}
现在我能得到的更好的是在我的数据库的用户名列中使用 ID 而不是电子邮件,但是一旦我尝试刷新令牌,我就会收到此消息 =>“401”无效凭据“ .
我试图将“ID”而不是“E-MAIL”作为 user_identity_field。
有没有人找到解决方案?
谢谢。
【问题讨论】:
标签:
symfony
jwt
api-platform.com
refresh-token
【解决方案1】:
我认为您需要更改 security.yaml 文件中的 app_user_provider :
app_user_provider:
entity:
class: AppEntityUser
property: id
jwt:
lexik_jwt:
class: AppEntityUser
我认为问题是:symfony 尝试使用 app_user_provider 对用户进行身份验证,但您遇到了冲突,因为 id 在您的 JWT 中,但框架搜索电子邮件。
为了验证您是否可以检查您的令牌:https://jwt.io/
【解决方案2】:
JWTRefreshTokenBundle (gesdinet/jwt-refresh-token-bundle) 基于 JWTAuthenticationBundle (lexik/jwt-authentication-bundle) 构建,后者是定义 user_identity_field 配置的包:
# config/packages/lexik_jwt_authentication.yaml
lexik_jwt_authentication:
user_identity_field: 'email'
【解决方案3】:
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