Symfony身份验证令牌getCredentials返回null [英] Symfony authentication token getCredentials returning null

查看:773
本文介绍了Symfony身份验证令牌getCredentials返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实现SimplePreAuthenticatorInterfaceAuthenticationSuccessHandlerInterfaceAuthenticationFailureHandlerInterfaceTokenAuthenticator.它会创建一个PreAuthenticatedToken令牌.

I have a TokenAuthenticator which implements SimplePreAuthenticatorInterface, AuthenticationSuccessHandlerInterface and AuthenticationFailureHandlerInterface. It creates a PreAuthenticatedToken token.

在该类中,我有一个名为authenticateToken的方法,它看起来像这样.

Within that class I have a method called authenticateToken which looks like this.

/**
 * @param TokenInterface        $token
 * @param UserProviderInterface $userProvider
 * @param $providerKey
 *
 * @return PreAuthenticatedToken
 */
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
    $token = $token->getCredentials();

该代码有效,但是最近有几次getCredentials返回null导致代码掉落.

The code works, however there have been a couple of occasions recently where getCredentials has returned null causing the code to fall over.

我正在尝试确定原因,并考虑了用户使用专用浏览器会话和/或清除其会话cookie/缓存等,但是我似乎无法复制.

I am trying to ascertain why this is and have considered users using private browser sessions and/or clearing their session cookies/cache etc, but I cannot seem to replicate this.

考虑authenticateToken方法的类型,将$token变量提示为TokenInterface-是什么导致对getCredentials的调用然后返回null?

Considering the authenticateToken method type-hints the $token variable to a TokenInterface - what would cause a call to getCredentials to then return null?

推荐答案

是否要求对所有路由进行所有身份验证?

Are you requiring all authentication for all routes?

如果您允许匿名用户,则getCredentials将返回'',如您从该类的代码段中所见

If you allow anonymous users getCredentials will return '', as you can see in this snippet from the class

/**
 * {@inheritdoc}
 */
public function getCredentials()
{
    return '';
}

另一个返回此默认令牌的默认令牌类是RememberMeToken.

The other default token class that returns this is the RememberMeToken.

这篇关于Symfony身份验证令牌getCredentials返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆