symfony - 使用角色进行匿名身份验证
问题描述
我有一个需要匿名验证用户的身份验证器,但包含一个角色。createAuthenticatedToken
我通过在 Authenticator 中覆盖来做到这一点:
class ClientAuthenticator extends AbstractGuardAuthenticator
{
// supports(), getCredentials(), all working
public function getUser($credentials, UserProviderInterface $userProvider)
{
return new SessionUser;
}
// Return an anonymous user with the client role
public function createAuthenticatedToken(UserInterface $user, $providerKey)
{
return new AnonymousToken(
'Ynpir6i', // <-- here's the issue (the $secret param)
'anon.',
['ROLE_CLIENT_GUEST']
);
}
}
这非常有效——当我硬编码 AnonymousToken 的“秘密”参数时。
我不知道如何动态地获取这个秘密。它不是 parameters.yml (aka %kernel.secret%
) 中提供的“秘密”参数。
我只是通过在设置时将其倾倒而得到了我现在使用的秘密AnonymousAuthenticationListener
。我查看了该服务的配置,但根本没有看到它设置。
这个秘密参数是什么,如何将它注入到我的身份验证器中?
或者,是否有更好的方法将角色添加到以特定方式进行身份验证的匿名令牌?
解决方案
该参数可以设置为已知值security.yml
:
security:
firewalls:
main:
anonymous:
secret: '%secret%'
推荐阅读
- excel - 无法在 excel 公式中提交部分查询(无法使用 VBA)
- azure-data-explorer - 您可以使用变量来定义 Kusto 查询中的列名吗?
- methods - 阻塞方法执行直到异步 RxJava 调用返回
- c# - EF、SQL Server - 连接超时已过期。登录后阶段超时时间已过
- node.js - pm2 nodejs在集群模式下断开与数据库的连接-i 2
- python - 使用 access_token 向 Facebook 的 Graph API 发出 POST 请求
- asp.net-mvc - AspNetIdentity 中的 PasswordSignInAsync 方法抛出无效格式异常
- c# - C# .NET httpClient 响应
- google-app-engine - Google App Engine 和 Stackdriver 调试:找不到 /tmp/debugger-breakpoints 文件
- excel - 以下代码行之间的区别