Skip to content

Commit

Permalink
Fix RefreshAccessTokenListener after Symfony 7.2 decoration
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Security/Http/Firewall/RefreshAccessTokenListener.php
  • Loading branch information
Jean85 committed Dec 2, 2024
1 parent 8f848cd commit 8a74155
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/Security/Http/Firewall/RefreshAccessTokenListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@

use HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken;
use HWI\Bundle\OAuthBundle\Security\Http\Authenticator\OAuthAuthenticator;
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticator;

class RefreshAccessTokenListener extends AbstractRefreshAccessTokenListener
{
private OAuthAuthenticator $oAuthAuthenticator;
private AuthenticatorInterface $authenticator;

public function __construct(
OAuthAuthenticator $oAuthAuthenticator
AuthenticatorInterface $authenticator
) {
$this->oAuthAuthenticator = $oAuthAuthenticator;
$this->authenticator = $authenticator;
}

/**
Expand All @@ -33,6 +35,18 @@ public function __construct(
*/
protected function refreshToken(OAuthToken $token): OAuthToken
{
return $this->oAuthAuthenticator->refreshToken($token);
if ($this->authenticator instanceof OAuthAuthenticator) {
return $this->authenticator->refreshToken($token);
}

if ($this->authenticator instanceof TraceableAuthenticator) {
$authenticator = $this->authenticator->getAuthenticator();

Check failure on line 43 in src/Security/Http/Firewall/RefreshAccessTokenListener.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticator::getAuthenticator().

if ($authenticator instanceof OAuthAuthenticator) {
return $authenticator->refreshToken($token);
}
}

throw new \RuntimeException('Unsupported authenticator, expecting OAuthAuthenticator, got ' . get_debug_type($this->authenticator));
}
}

0 comments on commit 8a74155

Please sign in to comment.