use of org.keycloak.representations.idm.OAuth2ErrorRepresentation in project keycloak by keycloak.
the class TokenRevocationTest method testRevokeRequestParamsMoreThanOnce.
// KEYCLOAK-17300
@Test
public void testRevokeRequestParamsMoreThanOnce() throws Exception {
oauth.clientId("test-app");
OAuthClient.AccessTokenResponse tokenResponse = oauth.doGrantAccessTokenRequest("password", "test-user@localhost", "password");
isTokenEnabled(tokenResponse, "test-app");
String revokeResponse = doTokenRevokeWithDuplicateParams(tokenResponse.getRefreshToken(), "refresh_token", "password");
OAuth2ErrorRepresentation errorRep = JsonSerialization.readValue(revokeResponse, OAuth2ErrorRepresentation.class);
assertEquals("duplicated parameter", errorRep.getErrorDescription());
assertEquals(OAuthErrorException.INVALID_REQUEST, errorRep.getError());
}
use of org.keycloak.representations.idm.OAuth2ErrorRepresentation in project keycloak by keycloak.
the class TokenIntrospectionTest method testInvalidClientCredentials.
@Test
public void testInvalidClientCredentials() throws Exception {
oauth.doLogin("test-user@localhost", "password");
String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
AccessTokenResponse accessTokenResponse = oauth.doAccessTokenRequest(code, "password");
String tokenResponse = oauth.introspectAccessTokenWithClientCredential("confidential-cli", "bad_credential", accessTokenResponse.getAccessToken());
OAuth2ErrorRepresentation errorRep = JsonSerialization.readValue(tokenResponse, OAuth2ErrorRepresentation.class);
Assert.assertEquals("Authentication failed.", errorRep.getErrorDescription());
Assert.assertEquals(OAuthErrorException.INVALID_REQUEST, errorRep.getError());
}
use of org.keycloak.representations.idm.OAuth2ErrorRepresentation in project keycloak by keycloak.
the class TokenIntrospectionTest method testPublicClientCredentialsNotAllowed.
@Test
public void testPublicClientCredentialsNotAllowed() throws Exception {
oauth.doLogin("test-user@localhost", "password");
String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
AccessTokenResponse accessTokenResponse = oauth.doAccessTokenRequest(code, "password");
String tokenResponse = oauth.introspectAccessTokenWithClientCredential("public-cli", "it_doesnt_matter", accessTokenResponse.getAccessToken());
OAuth2ErrorRepresentation errorRep = JsonSerialization.readValue(tokenResponse, OAuth2ErrorRepresentation.class);
Assert.assertEquals("Client not allowed.", errorRep.getErrorDescription());
Assert.assertEquals(OAuthErrorException.INVALID_REQUEST, errorRep.getError());
}
use of org.keycloak.representations.idm.OAuth2ErrorRepresentation in project keycloak by keycloak.
the class KcOidcBrokerTest method testIdPNotFound.
@Test
public void testIdPNotFound() {
final String notExistingIdP = "not-exists";
final String realmName = Optional.ofNullable(realmsResouce().realm(bc.providerRealmName()).toRepresentation().getRealm()).orElse(null);
assertThat(realmName, notNullValue());
final String LINK = OAuthClient.AUTH_SERVER_ROOT + "/realms/" + realmName + "/broker/" + notExistingIdP + "/endpoint";
driver.navigate().to(LINK);
errorPage.assertCurrent();
assertThat(errorPage.getError(), is("Page not found"));
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
SimpleHttp.Response simple = SimpleHttp.doGet(LINK, client).asResponse();
assertThat(simple, notNullValue());
assertThat(simple.getStatus(), is(Response.Status.NOT_FOUND.getStatusCode()));
OAuth2ErrorRepresentation error = simple.asJson(OAuth2ErrorRepresentation.class);
assertThat(error, notNullValue());
assertThat(error.getError(), is("Identity Provider [" + notExistingIdP + "] not found."));
} catch (IOException ex) {
Assert.fail("Cannot create HTTP client. Details: " + ex.getMessage());
}
}
use of org.keycloak.representations.idm.OAuth2ErrorRepresentation in project keycloak by keycloak.
the class ClientRegistrationTest method registerOrUpdateClientExpectingValidationErrors.
private void registerOrUpdateClientExpectingValidationErrors(ClientRepresentation rep, boolean register, boolean redirectUris, String... expectedErrors) {
HttpErrorException errorException = null;
try {
if (register) {
registerClient(rep);
} else {
reg.update(rep);
}
fail("Expected exception");
} catch (ClientRegistrationException e) {
errorException = (HttpErrorException) e.getCause();
}
expectedErrors = Arrays.stream(expectedErrors).filter(Objects::nonNull).toArray(String[]::new);
assertEquals(errorException.getStatusLine().getStatusCode(), 400);
OAuth2ErrorRepresentation errorRep;
try {
errorRep = JsonSerialization.readValue(errorException.getErrorResponse(), OAuth2ErrorRepresentation.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
List<String> actualErrors = asList(errorRep.getErrorDescription().split("; "));
assertThat(actualErrors, containsInAnyOrder(expectedErrors));
assertEquals(redirectUris ? INVALID_REDIRECT_URI : INVALID_CLIENT_METADATA, errorRep.getError());
}
Aggregations