Skip to content

Commit a0b5585

Browse files
committed
bug #72 Make sure token is always authenticated (yoshz)
This PR was squashed before being merged into the 0.1-dev branch. Discussion ---------- Make sure token is always authenticated After upgrading to symfony 5.4, authorization is broken because the OAuth2Token doesn't is "authenticated" anymore (see #68). From symfony 5.4 on the `authenticated` property is not used anymore but triggers an error in the AuthorizationChecker when it is false (this seems buggy as well). This fix ensures the authenticated property is always true when an user is set on the token. ~~This is the same behavior as the UsernamePasswordToken and RememberMeToken.~~ Seems this fix is only necessary for symfony 5.4. Symfony 6.0 works fine. I have updated the pipeline config to tests on the right versions and update composer to v2 as it is required for symfony 6.0. Commits ------- 9468f33 Make sure token is always authenticated
2 parents 23bf59f + 9468f33 commit a0b5585

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

.github/workflows/unit-tests.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
#Stable supported versions
13-
php: ['7.3', '7.4', '8.0']
14-
symfony: ['5.3.*']
13+
php: ['7.3', '7.4', '8.0', '8.1']
14+
symfony: ['5.3.*', '5.4.*']
1515
composer-flags: ['--prefer-stable']
1616
can-fail: [false]
1717
include:
@@ -20,13 +20,18 @@ jobs:
2020
symfony: '5.3.*'
2121
composer-flags: '--prefer-stable --prefer-lowest'
2222
can-fail: false
23-
# Development versions
24-
- php: '8.1-rc'
25-
symfony: '5.4.x-dev'
26-
composer-flags: ''
23+
# Symfony 6
24+
- php: '8.0'
25+
symfony: '6.0.*'
26+
composer-flags: '--prefer-stable'
2727
can-fail: false
28+
- php: '8.1'
29+
symfony: '6.0.*'
30+
composer-flags: '--prefer-stable'
31+
can-fail: false
32+
# Development versions
2833
- php: '8.1-rc'
29-
symfony: '6.0.x-dev'
34+
symfony: '6.1.x-dev'
3035
composer-flags: ''
3136
can-fail: false
3237

src/Security/Authenticator/OAuth2Authenticator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ public function createToken(Passport $passport, string $firewallName): TokenInte
157157
$oauthClientId = $passport->getAttribute('oauthClientId', '');
158158

159159
$token = new OAuth2Token($passport->getUser(), $accessTokenId, $oauthClientId, $scopeBadge->getScopes(), $this->rolePrefix);
160+
if (method_exists(AuthenticatorInterface::class, 'createAuthenticatedToken') && !method_exists(AuthenticatorInterface::class, 'createToken')) {
161+
// symfony 5.4 only
162+
/** @psalm-suppress TooManyArguments */
163+
$token->setAuthenticated(true, false);
164+
}
160165

161166
return $token;
162167
}

0 commit comments

Comments
 (0)