Skip to content

Commit 2b93827

Browse files
authored
Merge pull request #2022 from Jean85/fix-symfony-7.2
Fix RefreshAccessTokenListener after Symfony 7.2 decoration
2 parents c938583 + 6898907 commit 2b93827

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/Security/Http/Firewall/RefreshAccessTokenListener.php

+18-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313

1414
use HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken;
1515
use HWI\Bundle\OAuthBundle\Security\Http\Authenticator\OAuthAuthenticator;
16+
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
17+
use Symfony\Component\Security\Http\Authenticator\Debug\TraceableAuthenticator;
1618

1719
class RefreshAccessTokenListener extends AbstractRefreshAccessTokenListener
1820
{
19-
private OAuthAuthenticator $oAuthAuthenticator;
21+
private AuthenticatorInterface $authenticator;
2022

2123
public function __construct(
22-
OAuthAuthenticator $oAuthAuthenticator
24+
AuthenticatorInterface $authenticator
2325
) {
24-
$this->oAuthAuthenticator = $oAuthAuthenticator;
26+
$this->authenticator = $authenticator;
2527
}
2628

2729
/**
@@ -33,6 +35,18 @@ public function __construct(
3335
*/
3436
protected function refreshToken(OAuthToken $token): OAuthToken
3537
{
36-
return $this->oAuthAuthenticator->refreshToken($token);
38+
if ($this->authenticator instanceof OAuthAuthenticator) {
39+
return $this->authenticator->refreshToken($token);
40+
}
41+
42+
if ($this->authenticator instanceof TraceableAuthenticator) {
43+
$authenticator = $this->authenticator->getAuthenticator();
44+
45+
if ($authenticator instanceof OAuthAuthenticator) {
46+
return $authenticator->refreshToken($token);
47+
}
48+
}
49+
50+
throw new \RuntimeException('Unsupported authenticator, expecting OAuthAuthenticator, got ' . get_class($this->authenticator));
3751
}
3852
}

0 commit comments

Comments
 (0)