Skip to content

Commit 746321a

Browse files
committed
[Security] Fix deprecation notice on TokenInterface::getUser() stringable return
AuthenticatorManager raises a deprecation notice about the missing implementation of UserInterface::getUserIdentifier() when TokenInterface::getUser() returns a string. This fixes that issue.
1 parent 195f720 commit 746321a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Authentication/AuthenticatorManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ private function executeAuthenticator(AuthenticatorInterface $authenticator, Req
230230
private function handleAuthenticationSuccess(TokenInterface $authenticatedToken, PassportInterface $passport, Request $request, AuthenticatorInterface $authenticator): ?Response
231231
{
232232
// @deprecated since 5.3
233-
if (!method_exists($authenticatedToken->getUser(), 'getUserIdentifier')) {
233+
$user = $authenticatedToken->getUser();
234+
if ($user instanceof UserInterface && !method_exists($user, 'getUserIdentifier')) {
234235
trigger_deprecation('symfony/security-core', '5.3', 'Not implementing method "getUserIdentifier(): string" in user class "%s" is deprecated. This method will replace "getUsername()" in Symfony 6.0.', get_debug_type($authenticatedToken->getUser()));
235236
}
236237

0 commit comments

Comments
 (0)