-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Labels
Description
Symfony cookbook entry for Api Key Authentication states that you can return null
from SimplePreAuthenticatorInterface::createToken
. If you don't want to authenticate at certain url:
public function createToken(Request $request, $providerKey)
{
// set the only URL where we should look for auth information
// and only return the token if we're at that URL
$targetUrl = '/login/check';
if (!$this->httpUtils->checkRequestPath($request, $targetUrl)) {
return;
}
// ...
}
However, when I did it, I got the following error:
Catchable Fatal Error: Argument 1 passed to Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager::authenticate() must be an instance of Symfony\Component\Security\Core\Authentication\Token\TokenInterface, null given
createToken
method is called from SimplePreAuthenticationListener
and when I examined it, this looked like the part that is problematic:
$token = $this->simpleAuthenticator->createToken($request, $this->providerKey);
$token = $this->authenticationManager->authenticate($token);
So when SimpleAuthenticator
returns null
, it passes that null
to AuthenticationManager::authenticate
which doesn't accept nulls:
interface AuthenticationManagerInterface
{
public function authenticate(TokenInterface $token);
}