Search in sources :

Example 36 with OIDCClientRepresentation

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

the class OIDCClientRegistrationTest method testSignaturesRequired.

@Test
public void testSignaturesRequired() throws Exception {
    OIDCClientRepresentation clientRep = null;
    OIDCClientRepresentation response = null;
    try {
        clientRep = createRep();
        clientRep.setUserinfoSignedResponseAlg(Algorithm.ES256.toString());
        clientRep.setRequestObjectSigningAlg(Algorithm.ES256.toString());
        response = reg.oidc().create(clientRep);
        Assert.assertEquals(Algorithm.ES256.toString(), response.getUserinfoSignedResponseAlg());
        Assert.assertEquals(Algorithm.ES256.toString(), response.getRequestObjectSigningAlg());
        Assert.assertNotNull(response.getClientSecret());
        // Test Keycloak representation
        ClientRepresentation kcClient = getClient(response.getClientId());
        OIDCAdvancedConfigWrapper config = OIDCAdvancedConfigWrapper.fromClientRepresentation(kcClient);
        Assert.assertEquals(config.getUserInfoSignedResponseAlg(), Algorithm.ES256);
        Assert.assertEquals(config.getRequestObjectSignatureAlg(), Algorithm.ES256);
        // update (ES256 to PS256)
        clientRep.setUserinfoSignedResponseAlg(Algorithm.PS256.toString());
        clientRep.setRequestObjectSigningAlg(Algorithm.PS256.toString());
        response = reg.oidc().create(clientRep);
        Assert.assertEquals(Algorithm.PS256.toString(), response.getUserinfoSignedResponseAlg());
        Assert.assertEquals(Algorithm.PS256.toString(), response.getRequestObjectSigningAlg());
        // keycloak representation
        kcClient = getClient(response.getClientId());
        config = OIDCAdvancedConfigWrapper.fromClientRepresentation(kcClient);
        Assert.assertEquals(config.getUserInfoSignedResponseAlg(), Algorithm.PS256);
        Assert.assertEquals(config.getRequestObjectSignatureAlg(), Algorithm.PS256);
    } finally {
        // back to RS256 for other tests
        clientRep.setUserinfoSignedResponseAlg(Algorithm.RS256.toString());
        clientRep.setRequestObjectSigningAlg(Algorithm.RS256.toString());
        response = reg.oidc().create(clientRep);
    }
}
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 37 with OIDCClientRepresentation

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

the class OIDCClientRegistrationTest method createClientImplicitFlow.

@Test
public void createClientImplicitFlow() throws ClientRegistrationException {
    OIDCClientRepresentation clientRep = createRep();
    clientRep.setResponseTypes(Arrays.asList("id_token token"));
    OIDCClientRepresentation response = reg.oidc().create(clientRep);
    String clientId = response.getClientId();
    ClientRepresentation kcClientRep = getKeycloakClient(clientId);
    Assert.assertFalse(kcClientRep.isPublicClient());
    Assert.assertNull(kcClientRep.getSecret());
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 38 with OIDCClientRepresentation

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

the class OIDCClientRegistrationTest method testTlsClientAuthSubjectDn.

@Test
public void testTlsClientAuthSubjectDn() throws Exception {
    OIDCClientRepresentation response = null;
    OIDCClientRepresentation updated = null;
    try {
        // create (no specification)
        OIDCClientRepresentation clientRep = createRep();
        clientRep.setTokenEndpointAuthMethod(OIDCLoginProtocol.TLS_CLIENT_AUTH);
        clientRep.setTlsClientAuthSubjectDn("Ein");
        response = reg.oidc().create(clientRep);
        Assert.assertEquals(OIDCLoginProtocol.TLS_CLIENT_AUTH, response.getTokenEndpointAuthMethod());
        Assert.assertEquals("Ein", response.getTlsClientAuthSubjectDn());
        // Test Keycloak representation
        ClientRepresentation kcClient = getClient(response.getClientId());
        OIDCAdvancedConfigWrapper config = OIDCAdvancedConfigWrapper.fromClientRepresentation(kcClient);
        Assert.assertEquals(X509ClientAuthenticator.PROVIDER_ID, kcClient.getClientAuthenticatorType());
        Assert.assertEquals("Ein", config.getTlsClientAuthSubjectDn());
        Assert.assertFalse(config.getAllowRegexPatternComparison());
        // update
        reg.auth(Auth.token(response));
        response.setTlsClientAuthSubjectDn("(.*?)(?:$)");
        updated = reg.oidc().update(response);
        Assert.assertEquals(OIDCLoginProtocol.TLS_CLIENT_AUTH, updated.getTokenEndpointAuthMethod());
        Assert.assertEquals("(.*?)(?:$)", updated.getTlsClientAuthSubjectDn());
        // Test Keycloak representation
        kcClient = getClient(updated.getClientId());
        config = OIDCAdvancedConfigWrapper.fromClientRepresentation(kcClient);
        Assert.assertEquals(X509ClientAuthenticator.PROVIDER_ID, kcClient.getClientAuthenticatorType());
        Assert.assertEquals("(.*?)(?:$)", config.getTlsClientAuthSubjectDn());
    } finally {
        // revert
        reg.auth(Auth.token(updated));
        updated.setTokenEndpointAuthMethod(null);
        updated.setTlsClientAuthSubjectDn(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)

Example 39 with OIDCClientRepresentation

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

the class OIDCClientRegistrationTest method createRep.

private OIDCClientRepresentation createRep() {
    OIDCClientRepresentation client = new OIDCClientRepresentation();
    client.setClientName("RegistrationAccessTokenTest");
    client.setClientUri("http://root");
    client.setRedirectUris(Collections.singletonList("http://redirect"));
    client.setFrontChannelLogoutUri("http://frontchannel");
    return client;
}
Also used : OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation)

Example 40 with OIDCClientRepresentation

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

the class OIDCClientRegistrationTest method testOIDCEndpointGetWithSamlClient.

@Test
public void testOIDCEndpointGetWithSamlClient() throws Exception {
    OIDCClientRepresentation response = create();
    reg.auth(Auth.token(response));
    assertNotNull(reg.oidc().get(response.getClientId()));
    ClientsResource clientsResource = adminClient.realm(TEST).clients();
    ClientRepresentation client = clientsResource.findByClientId(response.getClientId()).get(0);
    // change client to saml
    client.setProtocol("saml");
    clientsResource.get(client.getId()).update(client);
    assertGetFail(client.getClientId(), 400, Errors.INVALID_CLIENT);
}
Also used : 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)

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