-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Revoke previous refresh token after issuing a new one #1128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I found this in RFC 7009 OAuth 2.0 Token Revocation.
For OIDC ID token, I think we can infer similar. https://www.rfc-editor.org/rfc/rfc7009#section-2.1
|
This is not correct. If the AS generates a new refresh token then the previous one cannot be reused. Add the test below to @Test
public void requestWhenGenerateNewRefreshTokenOnRefreshThenOldOneCannotBeUsed() throws Exception {
this.spring.register(AuthorizationServerConfiguration.class).autowire();
TokenSettings tokenSettings = TokenSettings.builder().reuseRefreshTokens(false).build();
RegisteredClient registeredClient = TestRegisteredClients.registeredClient()
.tokenSettings(tokenSettings)
.build();
this.registeredClientRepository.save(registeredClient);
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient).build();
this.authorizationService.save(authorization);
OAuth2RefreshToken originalRefreshToken = authorization.getRefreshToken().getToken();
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.set(OAuth2ParameterNames.GRANT_TYPE, AuthorizationGrantType.REFRESH_TOKEN.getValue());
parameters.set(OAuth2ParameterNames.REFRESH_TOKEN, originalRefreshToken.getTokenValue());
this.mvc.perform(post(DEFAULT_TOKEN_ENDPOINT_URI)
.params(parameters)
.header(HttpHeaders.AUTHORIZATION, "Basic " + encodeBasicAuth(
registeredClient.getClientId(), registeredClient.getClientSecret())))
.andExpect(status().isOk());
OAuth2Authorization updatedAuthorization = this.authorizationService.findById(authorization.getId());
// Assert new refresh token was generated
assertThat(updatedAuthorization.getRefreshToken().getToken().getTokenValue()).isNotEqualTo(originalRefreshToken.getTokenValue());
// Attempt again using the original refresh token
this.mvc.perform(post(DEFAULT_TOKEN_ENDPOINT_URI)
.params(parameters)
.header(HttpHeaders.AUTHORIZATION, "Basic " + encodeBasicAuth(
registeredClient.getClientId(), registeredClient.getClientSecret())))
.andExpect(status().isBadRequest()); // Old refresh token cannot be used
} |
Apologies, it works indeed. There was an issue on how we handle our persistence; which made the refresh token always reusable. |
Expected Behavior
Refresh token used on the refresh_token grant type flow should be invalidated after the new one has been issued.
Current Behavior
Previously used refresh token can still be used even though the server generates a new one.
Context
According to the specification (https://www.rfc-editor.org/rfc/rfc6749#section-5.2):
At the moment, it is only possible to change the server's configuration to make it issue a new refresh token on each request instead of reusing the same one over again. We're looking for a similar approach that aims to revoke the previous token at the same time to provide better security.
The text was updated successfully, but these errors were encountered: