8000 Log error event for TokenInterceptorException in token endpoint by wakqasahmed · Pull Request #52705 · keycloak/keycloak · GitHub
[go: up one dir, main page]

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 @@ -173,6 +173,8 @@ public Response processGrantRequest() {
try {
return grant.process(context);
} catch (TokenInterceptorException e) {
event.detail(REASON, e.getDescription());
event.error(Errors.INVALID_REQUEST);
throw new CorsErrorResponseException(cors, e.getError(), e.getDescription(), Response.Status.BAD_REQUEST);
} catch (RefreshTokenException e) {
event.detail(REASON, e.getErrorDescription());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package org.keycloak.tests.oauth;

import org.keycloak.common.Profile;
import org.keycloak.events.Details;
import org.keycloak.events.Errors;
import org.keycloak.events.EventType;
import org.keycloak.representations.AccessToken;
import org.keycloak.testframework.annotations.InjectEvents;
import org.keycloak.testframework.annotations.InjectRealm;
import org.keycloak.testframework.annotations.KeycloakIntegrationTest;
import org.keycloak.testframework.annotations.TestSetup;
import org.keycloak.testframework.events.EventAssertion;
import org.keycloak.testframework.events.Events;
import org.keycloak.testframework.oauth.DefaultOAuthClientConfiguration;
import org.keycloak.testframework.oauth.OAuthClient;
import org.keycloak.testframework.oauth.annotations.InjectOAuthClient;
Expand Down Expand Up @@ -40,6 +46,9 @@ public class ResourceIndicatorsTest {
@InjectOAuthClient(ref = "bare", config = BareClientConfig.class)
OAuthClient bareOauth;

@InjectEvents
Events events;

@TestSetup
public void loginUser() {
AuthorizationEndpointResponse authorizationEndpointResponse = oauth.loginForm().resource("urn:client:theservice").doLogin("user", "pass");
Expand Down Expand Up @@ -152,6 +161,21 @@ public void testClientCredentialsWithoutRefreshTokenSetsAudience() {
assertValidResponse(tokenResponse, "test-app");
}

@Test
public void testClientCredentialsInvalidResourceLogsErrorEvent() {
events.clear();

AccessTokenResponse tokenResponse = oauth.clientCredentialsGrantRequest()
.resource("/invalid").send();
assertErrorResponse(tokenResponse, INVALID_TARGET, ERROR_INVALID_RESOURCE);

EventAssertion.assertError(events.poll())
.type(EventType.CLIENT_LOGIN_ERROR)
.error(Errors.INVALID_REQUEST)
.details(Details.REASON, ERROR_INVALID_RESOURCE);
Assertions.assertNull(events.poll());
}

private static final class ResourceIndicatorsRealm implements RealmConfig {

@Override
Expand Down
Loading
0