From 8a74155ec9263637abfb61aef26c402ad0582154 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Mon, 2 Dec 2024 12:18:42 +0100 Subject: [PATCH 1/2] Fix RefreshAccessTokenListener after Symfony 7.2 decoration # Conflicts: # src/Security/Http/Firewall/RefreshAccessTokenListener.php --- .../Firewall/RefreshAccessTokenListener.php | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Security/Http/Firewall/RefreshAccessTokenListener.php b/src/Security/Http/Firewall/RefreshAccessTokenListener.php index 28a8ec66e..be66e3068 100644 --- a/src/Security/Http/Firewall/RefreshAccessTokenListener.php +++ b/src/Security/Http/Firewall/RefreshAccessTokenListener.php @@ -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; } /** @@ -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(); + + if ($authenticator instanceof OAuthAuthenticator) { + return $authenticator->refreshToken($token); + } + } + + throw new \RuntimeException('Unsupported authenticator, expecting OAuthAuthenticator, got ' . get_debug_type($this->authenticator)); } } From 6898907e36f0d378ed1d5d8ced23811e2aa5fd44 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 3 Dec 2024 08:56:35 +0100 Subject: [PATCH 2/2] Refine exception message Co-authored-by: Karel --- src/Security/Http/Firewall/RefreshAccessTokenListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Security/Http/Firewall/RefreshAccessTokenListener.php b/src/Security/Http/Firewall/RefreshAccessTokenListener.php index be66e3068..d64343b6b 100644 --- a/src/Security/Http/Firewall/RefreshAccessTokenListener.php +++ b/src/Security/Http/Firewall/RefreshAccessTokenListener.php @@ -47,6 +47,6 @@ protected function refreshToken(OAuthToken $token): OAuthToken } } - throw new \RuntimeException('Unsupported authenticator, expecting OAuthAuthenticator, got ' . get_debug_type($this->authenticator)); + throw new \RuntimeException('Unsupported authenticator, expecting OAuthAuthenticator, got ' . get_class($this->authenticator)); } }