[英]Authenticate anonymously with roles
我有一個 Authenticator 需要匿名驗證用戶,但包含一個角色。 我通過覆蓋 Authenticator 中的createAuthenticatedToken
來做到這一點:
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 中提供的“秘密”參數(又名%kernel.secret%
)。
當它在AnonymousAuthenticationListener
中設置時,我只是通過將它轉儲出來得到我現在使用的秘密。 我查看了該服務的配置,但根本看不到它的設置。
這個秘密參數是什么,我如何將它注入我的身份驗證器?
或者,是否有更好的方法將角色添加到以特定方式進行身份驗證的匿名令牌?
該參數可以在security.yml
中設置為已知值:
security:
firewalls:
main:
anonymous:
secret: '%secret%'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.