use of org.keycloak.representations.AuthorizationResponseToken in project keycloak by keycloak.
the class AuthorizationTokenResponseModeTest method testErrorObjectExpectedClaims.
@Test
public void testErrorObjectExpectedClaims() throws Exception {
ClientManager.realm(adminClient.realm("test")).clientId("test-app").implicitFlow(true);
oauth.responseMode("query.jwt");
oauth.responseType("code id_token");
oauth.stateParamHardcoded("OpenIdConnect.AuthenticationProperties=2302984sdlk");
oauth.nonce("123456");
UriBuilder b = UriBuilder.fromUri(oauth.getLoginFormUrl());
driver.navigate().to(b.build().toURL());
OAuthClient.AuthorizationEndpointResponse errorResponse = new OAuthClient.AuthorizationEndpointResponse(oauth);
AuthorizationResponseToken responseToken = oauth.verifyAuthorizationResponseToken(errorResponse.getResponse());
assertNotNull(responseToken.getIssuer());
assertNotNull(responseToken.getExp());
assertNotNull(responseToken.getAudience());
assertNotEquals(0, responseToken.getAudience().length);
assertTrue(responseToken.getOtherClaims().containsKey("error"));
assertTrue(responseToken.getOtherClaims().containsKey("error_description"));
}
use of org.keycloak.representations.AuthorizationResponseToken in project keycloak by keycloak.
the class AuthorizationTokenResponseModeTest method authorizationRequestJWTResponseModeIdTokenResponseType.
@Test
public void authorizationRequestJWTResponseModeIdTokenResponseType() throws Exception {
ClientManager.realm(adminClient.realm("test")).clientId("test-app").implicitFlow(true);
// jwt response_mode. It should fallback to fragment.jwt when its hybrid flow
oauth.responseMode("jwt");
oauth.responseType("code id_token");
oauth.stateParamHardcoded("OpenIdConnect.AuthenticationProperties=2302984sdlk");
oauth.nonce("123456");
OAuthClient.AuthorizationEndpointResponse response = oauth.doLogin("test-user@localhost", "password");
assertTrue(response.isRedirected());
AuthorizationResponseToken responseToken = oauth.verifyAuthorizationResponseToken(response.getResponse());
assertEquals("test-app", responseToken.getAudience()[0]);
Assert.assertNotNull(responseToken.getOtherClaims().get("code"));
assertEquals("OpenIdConnect.AuthenticationProperties=2302984sdlk", responseToken.getOtherClaims().get("state"));
Assert.assertNull(responseToken.getOtherClaims().get("error"));
Assert.assertNotNull(responseToken.getOtherClaims().get("id_token"));
String idTokenEncoded = (String) responseToken.getOtherClaims().get("id_token");
IDToken idToken = oauth.verifyIDToken(idTokenEncoded);
assertEquals("123456", idToken.getNonce());
URI currentUri = new URI(driver.getCurrentUrl());
Assert.assertNull(currentUri.getRawQuery());
Assert.assertNotNull(currentUri.getRawFragment());
String codeId = events.expectLogin().assertEvent().getDetails().get(Details.CODE_ID);
}
use of org.keycloak.representations.AuthorizationResponseToken in project keycloak by keycloak.
the class AuthorizationTokenResponseModeTest method authorizationRequestJWTResponseMode.
@Test
public void authorizationRequestJWTResponseMode() throws Exception {
// jwt response_mode. It should fallback to query.jwt
oauth.responseMode("jwt");
oauth.stateParamHardcoded("OpenIdConnect.AuthenticationProperties=2302984sdlk");
OAuthClient.AuthorizationEndpointResponse response = oauth.doLogin("test-user@localhost", "password");
assertTrue(response.isRedirected());
AuthorizationResponseToken responseToken = oauth.verifyAuthorizationResponseToken(response.getResponse());
assertEquals("test-app", responseToken.getAudience()[0]);
Assert.assertNotNull(responseToken.getOtherClaims().get("code"));
// should not return code when response_type not 'token'
assertFalse(responseToken.getOtherClaims().containsKey(OAuth2Constants.SCOPE));
assertEquals("OpenIdConnect.AuthenticationProperties=2302984sdlk", responseToken.getOtherClaims().get("state"));
Assert.assertNull(responseToken.getOtherClaims().get("error"));
URI currentUri = new URI(driver.getCurrentUrl());
Assert.assertNotNull(currentUri.getRawQuery());
Assert.assertNull(currentUri.getRawFragment());
String codeId = events.expectLogin().assertEvent().getDetails().get(Details.CODE_ID);
}
use of org.keycloak.representations.AuthorizationResponseToken in project keycloak by keycloak.
the class AuthorizationTokenResponseModeTest method authorizationRequestFailInvalidResponseModeQueryJWT.
@Test
public void authorizationRequestFailInvalidResponseModeQueryJWT() throws Exception {
ClientManager.realm(adminClient.realm("test")).clientId("test-app").implicitFlow(true);
oauth.responseMode("query.jwt");
oauth.responseType("code id_token");
oauth.stateParamHardcoded("OpenIdConnect.AuthenticationProperties=2302984sdlk");
oauth.nonce("123456");
UriBuilder b = UriBuilder.fromUri(oauth.getLoginFormUrl());
driver.navigate().to(b.build().toURL());
OAuthClient.AuthorizationEndpointResponse errorResponse = new OAuthClient.AuthorizationEndpointResponse(oauth);
AuthorizationResponseToken responseToken = oauth.verifyAuthorizationResponseToken(errorResponse.getResponse());
Assert.assertEquals(OAuthErrorException.INVALID_REQUEST, responseToken.getOtherClaims().get("error"));
Assert.assertEquals("Response_mode 'query.jwt' is allowed only when the authorization response token is encrypted", responseToken.getOtherClaims().get("error_description"));
events.expectLogin().error(Errors.INVALID_REQUEST).user((String) null).session((String) null).clearDetails().assertEvent();
}
use of org.keycloak.representations.AuthorizationResponseToken in project keycloak by keycloak.
the class AuthorizationTokenResponseModeTest method authorizationRequestFragmentJWTResponseMode.
@Test
public void authorizationRequestFragmentJWTResponseMode() throws Exception {
oauth.responseMode(OIDCResponseMode.FRAGMENT_JWT.value());
oauth.stateParamHardcoded("OpenIdConnect.AuthenticationProperties=2302984sdlk");
OAuthClient.AuthorizationEndpointResponse response = oauth.doLogin("test-user@localhost", "password");
assertTrue(response.isRedirected());
AuthorizationResponseToken responseToken = oauth.verifyAuthorizationResponseToken(response.getResponse());
assertEquals("test-app", responseToken.getAudience()[0]);
Assert.assertNotNull(responseToken.getOtherClaims().get("code"));
assertEquals("OpenIdConnect.AuthenticationProperties=2302984sdlk", responseToken.getOtherClaims().get("state"));
Assert.assertNull(responseToken.getOtherClaims().get("error"));
URI currentUri = new URI(driver.getCurrentUrl());
Assert.assertNull(currentUri.getRawQuery());
Assert.assertNotNull(currentUri.getRawFragment());
String codeId = events.expectLogin().assertEvent().getDetails().get(Details.CODE_ID);
}
Aggregations