Search in sources :

Example 41 with OIDCClientRepresentation

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

the class OIDCClientRegistrationTest method testDefaultAcrValues.

@Test
public void testDefaultAcrValues() throws Exception {
    // Set realm acr-to-loa mapping
    RealmRepresentation realmRep = adminClient.realm("test").toRepresentation();
    Map<String, Integer> acrLoaMap = new HashMap<>();
    acrLoaMap.put("copper", 0);
    acrLoaMap.put("silver", 1);
    acrLoaMap.put("gold", 2);
    realmRep.getAttributes().put(Constants.ACR_LOA_MAP, JsonSerialization.writeValueAsString(acrLoaMap));
    adminClient.realm("test").update(realmRep);
    OIDCClientRepresentation clientRep = createRep();
    clientRep.setDefaultAcrValues(Arrays.asList("silver", "foo"));
    try {
        OIDCClientRepresentation response = reg.oidc().create(clientRep);
        fail("Expected 400");
    } catch (ClientRegistrationException e) {
        assertEquals(400, ((HttpErrorException) e.getCause()).getStatusLine().getStatusCode());
    }
    clientRep.setDefaultAcrValues(Arrays.asList("silver", "gold"));
    OIDCClientRepresentation response = reg.oidc().create(clientRep);
    Assert.assertNames(response.getDefaultAcrValues(), "silver", "gold");
    // Test Keycloak representation
    ClientRepresentation kcClient = getClient(response.getClientId());
    OIDCAdvancedConfigWrapper config = OIDCAdvancedConfigWrapper.fromClientRepresentation(kcClient);
    Assert.assertNames(config.getAttributeMultivalued(Constants.DEFAULT_ACR_VALUES), "silver", "gold");
    // Revert realm acr-to-loa mappings
    realmRep.getAttributes().remove(Constants.ACR_LOA_MAP);
    adminClient.realm("test").update(realmRep);
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) OIDCAdvancedConfigWrapper(org.keycloak.protocol.oidc.OIDCAdvancedConfigWrapper) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 42 with OIDCClientRepresentation

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

the class OIDCClientRegistrationTest method createClientWithUriFragment.

// KEYCLOAK-3421
@Test
public void createClientWithUriFragment() {
    OIDCClientRepresentation client = createRep();
    client.setRedirectUris(Arrays.asList("http://localhost/auth", "http://localhost/auth#fragment", "http://localhost/auth*"));
    assertCreateFail(client, 400, "URI fragment");
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) Test(org.junit.Test)

Example 43 with OIDCClientRepresentation

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

the class OIDCClientRegistrationTest method updateClientError.

@Test
public void updateClientError() throws ClientRegistrationException {
    try {
        OIDCClientRepresentation response = create();
        reg.auth(Auth.token(response));
        response.setResponseTypes(Arrays.asList("code", "tokenn"));
        reg.oidc().update(response);
        fail("Not expected to end with success");
    } catch (ClientRegistrationException cre) {
    }
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) Test(org.junit.Test)

Example 44 with OIDCClientRepresentation

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

the class OIDCClientRegistrationTest method testClientWithScope.

@Test
public void testClientWithScope() throws Exception {
    OIDCClientRepresentation clientRep = null;
    OIDCClientRepresentation response = null;
    String clientScope = "phone address";
    clientRep = createRep();
    clientRep.setScope(clientScope);
    response = reg.oidc().create(clientRep);
    Set<String> clientScopes = new HashSet<>(Arrays.asList(clientScope.split(" ")));
    Set<String> registeredClientScopes = new HashSet<>(Arrays.asList(response.getScope().split(" ")));
    assertTrue(clientScopes.equals(registeredClientScopes));
    ClientResource clientResource = adminClient.realm(REALM_NAME).clients().get(response.getClientId());
    assertTrue(clientResource.toRepresentation().getDefaultClientScopes().isEmpty());
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientResource(org.keycloak.admin.client.resource.ClientResource) Test(org.junit.Test)

Example 45 with OIDCClientRepresentation

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

the class OIDCClientRegistrationTest method testTokenEndpointSigningAlg.

@Test
public void testTokenEndpointSigningAlg() throws Exception {
    OIDCClientRepresentation response = null;
    OIDCClientRepresentation updated = null;
    try {
        OIDCClientRepresentation clientRep = createRep();
        clientRep.setTokenEndpointAuthSigningAlg(Algorithm.ES256.toString());
        response = reg.oidc().create(clientRep);
        Assert.assertEquals(Algorithm.ES256.toString(), response.getTokenEndpointAuthSigningAlg());
        ClientRepresentation kcClient = getClient(response.getClientId());
        OIDCAdvancedConfigWrapper config = OIDCAdvancedConfigWrapper.fromClientRepresentation(kcClient);
        Assert.assertEquals(Algorithm.ES256.toString(), config.getTokenEndpointAuthSigningAlg());
        reg.auth(Auth.token(response));
        response.setTokenEndpointAuthSigningAlg(null);
        updated = reg.oidc().update(response);
        Assert.assertEquals(null, response.getTokenEndpointAuthSigningAlg());
        kcClient = getClient(updated.getClientId());
        config = OIDCAdvancedConfigWrapper.fromClientRepresentation(kcClient);
        Assert.assertEquals(null, config.getTokenEndpointAuthSigningAlg());
    } finally {
        // revert
        reg.auth(Auth.token(updated));
        updated.setTokenEndpointAuthSigningAlg(null);
        reg.oidc().update(updated);
    }
}
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)

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