Skip to content

Commit 6b94e36

Browse files
committed
feat: allow configuring revocation of refresh tokens
fixes #211
1 parent 8dacedf commit 6b94e36

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
@@ -148,6 +148,10 @@ private function configureAuthorizationServer(ContainerBuilder $container, array
148148
$authorizationServer->replaceArgument(5, new Reference($config['response_type_class']));
149149
}
150150

151+
$authorizationServer->addMethodCall('revokeRefreshTokens', [
152+
$config['revoke_refresh_tokens'],
153+
]);
154+
151155
if ($config['enable_client_credentials_grant']) {
152156
$authorizationServer->addMethodCall('enableGrantType', [
153157
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($revokeRefreshTokens, $shouldRevokeRefreshTokens);
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)