Search in sources :

Example 81 with OIDCClientRepresentation

use of org.keycloak.representations.oidc.OIDCClientRepresentation in project keycloak by keycloak.

the class OIDCClientRegistrationTest method createClient.

@Test
public void createClient() throws ClientRegistrationException {
    OIDCClientRepresentation response = create();
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientIdIssuedAt());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertEquals(0, response.getClientSecretExpiresAt().intValue());
    assertNotNull(response.getRegistrationClientUri());
    assertEquals("RegistrationAccessTokenTest", response.getClientName());
    assertEquals("http://root", response.getClientUri());
    assertEquals(1, response.getRedirectUris().size());
    assertEquals("http://redirect", response.getRedirectUris().get(0));
    assertEquals(Arrays.asList("code", "none"), response.getResponseTypes());
    assertEquals(Arrays.asList(OAuth2Constants.AUTHORIZATION_CODE, OAuth2Constants.REFRESH_TOKEN), response.getGrantTypes());
    assertEquals(OIDCLoginProtocol.CLIENT_SECRET_BASIC, response.getTokenEndpointAuthMethod());
    Assert.assertNull(response.getUserinfoSignedResponseAlg());
    assertEquals("http://frontchannel", response.getFrontChannelLogoutUri());
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) Test(org.junit.Test)

Example 82 with OIDCClientRepresentation

use of org.keycloak.representations.oidc.OIDCClientRepresentation in project keycloak by keycloak.

the class OIDCClientRegistrationTest method testRequestUris.

@Test
public void testRequestUris() throws Exception {
    OIDCClientRepresentation clientRep = null;
    OIDCClientRepresentation response = null;
    clientRep = createRep();
    clientRep.setRequestUris(Arrays.asList("http://host/foo", "https://host2/bar"));
    response = reg.oidc().create(clientRep);
    Assert.assertNames(response.getRequestUris(), "http://host/foo", "https://host2/bar");
    // Test Keycloak representation
    ClientRepresentation kcClient = getClient(response.getClientId());
    OIDCAdvancedConfigWrapper config = OIDCAdvancedConfigWrapper.fromClientRepresentation(kcClient);
    Assert.assertNames(config.getRequestUris(), "http://host/foo", "https://host2/bar");
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) OIDCAdvancedConfigWrapper(org.keycloak.protocol.oidc.OIDCAdvancedConfigWrapper) OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 83 with OIDCClientRepresentation

use of org.keycloak.representations.oidc.OIDCClientRepresentation in project keycloak by keycloak.

the class OIDCClientRegistrationTest method testOIDCEndpointCreateWithSamlClient.

@Test
public void testOIDCEndpointCreateWithSamlClient() throws Exception {
    ClientsResource clientsResource = adminClient.realm(TEST).clients();
    ClientRepresentation samlClient = clientsResource.findByClientId("saml-client").get(0);
    String samlClientServiceId = clientsResource.get(samlClient.getId()).getServiceAccountUser().getId();
    String realmManagementId = clientsResource.findByClientId("realm-management").get(0).getId();
    RoleRepresentation role = clientsResource.get(realmManagementId).roles().get("create-client").toRepresentation();
    adminClient.realm(TEST).users().get(samlClientServiceId).roles().clientLevel(realmManagementId).add(Arrays.asList(role));
    String accessToken = oauth.clientId("saml-client").doClientCredentialsGrantAccessTokenRequest("secret").getAccessToken();
    reg.auth(Auth.token(accessToken));
    // change client to saml
    samlClient.setProtocol("saml");
    clientsResource.get(samlClient.getId()).update(samlClient);
    OIDCClientRepresentation client = createRep();
    assertCreateFail(client, 400, Errors.INVALID_CLIENT);
    // revert client
    samlClient.setProtocol("openid-connect");
    clientsResource.get(samlClient.getId()).update(samlClient);
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientsResource(org.keycloak.admin.client.resource.ClientsResource) OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 84 with OIDCClientRepresentation

use of org.keycloak.representations.oidc.OIDCClientRepresentation in project keycloak by keycloak.

the class OIDCClientRegistrationTest method testClientWithNotDefinedScope.

@Test
public void testClientWithNotDefinedScope() throws Exception {
    OIDCClientRepresentation clientRep = null;
    OIDCClientRepresentation response = null;
    String clientScope = "notdefinedscope address";
    clientRep = createRep();
    clientRep.setScope(clientScope);
    try {
        response = reg.oidc().create(clientRep);
        fail("Expected 403");
    } catch (ClientRegistrationException e) {
        assertEquals(403, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
    }
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) Test(org.junit.Test)

Example 85 with OIDCClientRepresentation

use of org.keycloak.representations.oidc.OIDCClientRepresentation in project keycloak by keycloak.

the class OIDCClientRegistrationTest method testOIDCEndpointGetWithToken.

@Test
public void testOIDCEndpointGetWithToken() throws Exception {
    OIDCClientRepresentation response = create();
    reg.auth(Auth.token(response));
    assertNotNull(reg.oidc().get(response.getClientId()));
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) Test(org.junit.Test)

Aggregations

OIDCClientRepresentation (org.keycloak.representations.oidc.OIDCClientRepresentation)118 Test (org.junit.Test)95 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)44 AbstractClientPoliciesTest (org.keycloak.testsuite.client.AbstractClientPoliciesTest)22 ParResponse (org.keycloak.testsuite.util.OAuthClient.ParResponse)21 TestOIDCEndpointsApplicationResource (org.keycloak.testsuite.client.resources.TestOIDCEndpointsApplicationResource)16 OAuthClient (org.keycloak.testsuite.util.OAuthClient)16 OIDCAdvancedConfigWrapper (org.keycloak.protocol.oidc.OIDCAdvancedConfigWrapper)15 ClientRegistrationException (org.keycloak.client.registration.ClientRegistrationException)11 IOException (java.io.IOException)10 ClientResource (org.keycloak.admin.client.resource.ClientResource)9 ArrayList (java.util.ArrayList)8 ClientPoliciesBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPoliciesBuilder)7 ClientPolicyBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPolicyBuilder)7 ClientProfileBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientProfileBuilder)7 ClientProfilesBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientProfilesBuilder)7 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)6 ClientsResource (org.keycloak.admin.client.resource.ClientsResource)4 InputStream (java.io.InputStream)3 Produces (javax.ws.rs.Produces)3