Skip to content

Commit

Permalink
[Security] Aligned RestAuthenticator with Symfony 6
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Nov 20, 2024
1 parent 8c93a08 commit 4ab1bfc
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/lib/Security/Authenticator/RestAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ public function supports(Request $request): ?bool
public function authenticate(Request $request): Passport
{
$existingUserToken = $this->fetchExistingToken($request);
if ($this->canUserFromSessionBeAuthenticated($existingUserToken)) {
if (null !== $existingUserToken && $this->canUserFromSessionBeAuthenticated($existingUserToken)) {
$existingUser = $existingUserToken->getUser();

return $this->createAuthorizationPassport(
/** @phpstan-ignore-next-line */
$existingUser->getUserIdentifier(),
/** @phpstan-ignore-next-line */
$existingUser->getPassword()
// @todo not sure how to refactor this
''
);
}

Expand Down Expand Up @@ -112,17 +111,11 @@ private function fetchExistingToken(Request $request): ?TokenInterface
}

/**
* @phpstan-assert-if-true !null $existingUserToken
* @phpstan-assert-if-true !null $existingUserToken->getUser()
*/
private function canUserFromSessionBeAuthenticated(?TokenInterface $existingUserToken): bool
{
if ($existingUserToken === null) {
return false;
}

$user = $existingUserToken->getUser();

return !($user === null || $user->getPassword() === null);
return $existingUserToken?->getUser() !== null;
}

private function createAuthorizationPassport(string $login, string $password): Passport
Expand Down

0 comments on commit 4ab1bfc

Please sign in to comment.