KEYCLOAK-5280 (#4576)

This commit is contained in:
Stian Thorgersen 2017-10-19 08:02:23 +02:00 committed by GitHub
parent 988d660083
commit fea4c54adc
2 changed files with 17 additions and 0 deletions

View file

@ -309,6 +309,10 @@ public class TokenManager {
try {
RefreshToken refreshToken = toRefreshToken(session, realm, encodedRefreshToken);
if (!(TokenUtil.TOKEN_TYPE_REFRESH.equals(refreshToken.getType()) || TokenUtil.TOKEN_TYPE_OFFLINE.equals(refreshToken.getType()))) {
throw new OAuthErrorException(OAuthErrorException.INVALID_GRANT, "Invalid refresh token");
}
if (checkExpiration) {
if (refreshToken.getExpiration() != 0 && refreshToken.isExpired()) {
throw new OAuthErrorException(OAuthErrorException.INVALID_GRANT, "Refresh token expired");

View file

@ -192,6 +192,19 @@ public class RefreshTokenTest extends AbstractKeycloakTest {
setTimeOffset(0);
}
@Test
public void refreshTokenWithAccessToken() throws Exception {
oauth.doLogin("test-user@localhost", "password");
String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
OAuthClient.AccessTokenResponse tokenResponse = oauth.doAccessTokenRequest(code, "password");
String accessTokenString = tokenResponse.getAccessToken();
OAuthClient.AccessTokenResponse response = oauth.doRefreshTokenRequest(accessTokenString, "password");
Assert.assertNotEquals(200, response.getStatusCode());
}
@Test
public void refreshTokenReuseTokenWithoutRefreshTokensRevoked() throws Exception {