Search in sources :

Example 6 with AuthorizationResponseToken

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"));
}
Also used : AuthorizationResponseToken(org.keycloak.representations.AuthorizationResponseToken) OAuthClient(org.keycloak.testsuite.util.OAuthClient) UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 7 with AuthorizationResponseToken

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);
}
Also used : AuthorizationResponseToken(org.keycloak.representations.AuthorizationResponseToken) OAuthClient(org.keycloak.testsuite.util.OAuthClient) IDToken(org.keycloak.representations.IDToken) URI(java.net.URI) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 8 with AuthorizationResponseToken

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);
}
Also used : AuthorizationResponseToken(org.keycloak.representations.AuthorizationResponseToken) OAuthClient(org.keycloak.testsuite.util.OAuthClient) URI(java.net.URI) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 9 with AuthorizationResponseToken

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();
}
Also used : AuthorizationResponseToken(org.keycloak.representations.AuthorizationResponseToken) OAuthClient(org.keycloak.testsuite.util.OAuthClient) UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 10 with AuthorizationResponseToken

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);
}
Also used : AuthorizationResponseToken(org.keycloak.representations.AuthorizationResponseToken) OAuthClient(org.keycloak.testsuite.util.OAuthClient) URI(java.net.URI) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Aggregations

AuthorizationResponseToken (org.keycloak.representations.AuthorizationResponseToken)10 Test (org.junit.Test)9 OAuthClient (org.keycloak.testsuite.util.OAuthClient)9 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)8 URI (java.net.URI)4 UriBuilder (javax.ws.rs.core.UriBuilder)2 IDToken (org.keycloak.representations.IDToken)2 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 PrivateKey (java.security.PrivateKey)1 ClientResource (org.keycloak.admin.client.resource.ClientResource)1 JWEException (org.keycloak.jose.jwe.JWEException)1 JWEHeader (org.keycloak.jose.jwe.JWEHeader)1 JWEAlgorithmProvider (org.keycloak.jose.jwe.alg.JWEAlgorithmProvider)1 JWEEncryptionProvider (org.keycloak.jose.jwe.enc.JWEEncryptionProvider)1 JWSInput (org.keycloak.jose.jws.JWSInput)1 AccessToken (org.keycloak.representations.AccessToken)1 EventRepresentation (org.keycloak.representations.idm.EventRepresentation)1 OIDCClientRepresentation (org.keycloak.representations.oidc.OIDCClientRepresentation)1