Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public Response introspect() {
TokenIntrospectionProvider provider = this.session.getProvider(TokenIntrospectionProvider.class, tokenTypeHint);

if (provider == null) {
throw throwErrorResponseException(Errors.INVALID_REQUEST, "Unsupported token type [" + tokenTypeHint + "].", Status.BAD_REQUEST);
event.detail(Details.TOKEN_TYPE, tokenTypeHint);
event.error(Errors.INVALID_REQUEST);
throw throwErrorResponseException(Errors.INVALID_REQUEST, "Unsupported token type.", Status.BAD_REQUEST);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.keycloak.OAuthErrorException;
import org.keycloak.admin.client.resource.ClientScopesResource;
import org.keycloak.crypto.Algorithm;
import org.keycloak.events.Details;
import org.keycloak.events.Errors;
import org.keycloak.events.EventType;
import org.keycloak.jose.jws.JWSInput;
Expand Down Expand Up @@ -579,6 +580,22 @@ public void testIntrospectionRequestParamsMoreThanOnce() throws Exception {
assertEquals(OAuthErrorException.INVALID_REQUEST, errorRep.getError());
}

@Test
public void testIntrospectionUnknownType() throws Exception {
events.clear();
String tokenResponse = introspectUnknownTokenType("confidential-cli", "secret1", "xxx");

OAuth2ErrorRepresentation errorRep = JsonSerialization.readValue(tokenResponse, OAuth2ErrorRepresentation.class);
assertEquals("Unsupported token type.", errorRep.getErrorDescription());
assertEquals(OAuthErrorException.INVALID_REQUEST, errorRep.getError());
events.expect(EventType.INTROSPECT_TOKEN)
.client("confidential-cli")
.user((String) null)
.detail(Details.TOKEN_TYPE, "unknown")
.error(Errors.INVALID_REQUEST)
.assertEvent();
}

@Test
public void testIntrospectRevokeRefreshToken() throws Exception {
RealmRepresentation realm = adminClient.realm(oauth.getRealm()).toRepresentation();
Expand Down Expand Up @@ -643,6 +660,29 @@ public void testIntrospectRefreshTokenAfterRefreshTokenRequest() throws Exceptio
}
}

private String introspectUnknownTokenType(String clientId, String clientSecret, String tokenToIntrospect) {
HttpPost post = new HttpPost(oauth.getEndpoints().getIntrospection());

String authorization = BasicAuthHelper.createHeader(clientId, clientSecret);
post.setHeader("Authorization", authorization);

List<NameValuePair> parameters = new LinkedList<>();

parameters.add(new BasicNameValuePair("token", tokenToIntrospect));
parameters.add(new BasicNameValuePair("token_type_hint", "unknown"));

UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(parameters, StandardCharsets.UTF_8);
post.setEntity(formEntity);

try (CloseableHttpResponse response = HttpClientBuilder.create().build().execute(post)) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
return new String(out.toByteArray());
} catch (Exception e) {
throw new RuntimeException("Failed to retrieve access token", e);
}
}

private String introspectAccessTokenWithDuplicateParams(String clientId, String clientSecret, String tokenToIntrospect) {
HttpPost post = new HttpPost(oauth.getEndpoints().getIntrospection());

Expand Down
Loading