Skip to content

Commit 03911d8

Browse files
committed
feature #213 feat: allow configuring revocation of refresh tokens (fschmtt)
This PR was merged into the 1.x-dev branch. Discussion ---------- feat: allow configuring revocation of refresh tokens adds a configuration for disabling revocation of refresh token after they were used. this configuration applies to all grant types that will be enabled. complies with `league/oauth2-server`: https://github.com/thephpleague/oauth2-server/blob/master/src/AuthorizationServer.php#L209-L215 ``` # config/packages/league_oauth2_server.yaml league_oauth2_server: authorization_server: revoke_refresh_tokens: false ``` Commits ------- e238516 feat: allow configuring revocation of refresh tokens
2 parents cee1e71 + e238516 commit 03911d8

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

docs/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ For implementation into Symfony projects, please see [bundle documentation](basi
7575
# Whether to enable access token saving to persistence layer (default to true)
7676
persist_access_token: true
7777
78+
# Whether to revoke refresh tokens after they were used for all grant types (default to true)
79+
revoke_refresh_tokens: true
80+
7881
resource_server: # Required
7982
8083
# Full path to the public key file

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ private function createAuthorizationServerNode(): NodeDefinition
111111
->info('Define a custom ResponseType')
112112
->defaultValue(null)
113113
->end()
114+
->booleanNode('revoke_refresh_tokens')
115+
->info('Whether to revoke refresh tokens after they were used for all grant types')
116+
->defaultTrue()
117+
->end()
114118
->end()
115119
;
116120

src/DependencyInjection/LeagueOAuth2ServerExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ private function configureAuthorizationServer(ContainerBuilder $container, array
152152
$authorizationServer->replaceArgument(5, new Reference($config['response_type_class']));
153153
}
154154

155+
$authorizationServer->addMethodCall('revokeRefreshTokens', [
156+
$config['revoke_refresh_tokens'],
157+
]);
158+
155159
if ($config['enable_client_credentials_grant']) {
156160
$authorizationServer->addMethodCall('enableGrantType', [
157161
new Reference(ClientCredentialsGrant::class),

tests/Unit/ExtensionTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,30 @@ public function testDefaultScopeValidation(array $available, array $default, boo
130130
$this->addToAssertionCount(1);
131131
}
132132

133+
/**
134+
* @dataProvider revokeRefreshTokensProvider
135+
*/
136+
public function testEnablingAndDisablingRevocationOfRefreshTokens(bool $shouldRevokeRefreshTokens): void
137+
{
138+
$container = new ContainerBuilder();
139+
$extension = new LeagueOAuth2ServerExtension();
140+
141+
$extension->load($this->getValidConfiguration(['revoke_refresh_tokens' => $shouldRevokeRefreshTokens]), $container);
142+
143+
$authorizationServer = $container->findDefinition(AuthorizationServer::class);
144+
$methodCalls = $authorizationServer->getMethodCalls();
145+
$revokeRefreshTokens = null;
146+
147+
foreach ($methodCalls as $methodCall) {
148+
if ('revokeRefreshTokens' === $methodCall[0]) {
149+
$revokeRefreshTokens = $methodCall[1][0];
150+
break;
151+
}
152+
}
153+
154+
$this->assertSame($shouldRevokeRefreshTokens, $revokeRefreshTokens);
155+
}
156+
133157
public function scopeProvider(): iterable
134158
{
135159
yield 'when a default scope is part of available scopes' => [
@@ -155,6 +179,7 @@ private function getValidConfiguration(array $options = []): array
155179
'enable_client_credentials_grant' => $options['enable_client_credentials_grant'] ?? true,
156180
'enable_password_grant' => $options['enable_password_grant'] ?? true,
157181
'enable_refresh_token_grant' => $options['enable_refresh_token_grant'] ?? true,
182+
'revoke_refresh_tokens' => $options['revoke_refresh_tokens'] ?? true,
158183
],
159184
'resource_server' => [
160185
'public_key' => 'foo',
@@ -175,6 +200,12 @@ private function getValidConfiguration(array $options = []): array
175200
];
176201
}
177202

203+
public function revokeRefreshTokensProvider(): iterable
204+
{
205+
yield 'do revoke refresh tokens' => [true];
206+
yield 'do not revoke refresh tokens' => [false];
207+
}
208+
178209
private function setupContainer(ContainerBuilder $container): void
179210
{
180211
$container->register(ScopeManager::class);

0 commit comments

Comments
 (0)