Search in sources :

Example 6 with GoogleOidcClient

use of org.pac4j.oidc.client.GoogleOidcClient in project pac4j by pac4j.

the class OidcClientBuilder method tryCreateOidcClient.

public void tryCreateOidcClient(final List<Client> clients) {
    for (int i = 0; i <= MAX_NUM_CLIENTS; i++) {
        final String id = getProperty(OIDC_ID, i);
        final String secret = getProperty(OIDC_SECRET, i);
        if (isNotBlank(id) && isNotBlank(secret)) {
            final OidcConfiguration configuration = new OidcConfiguration();
            configuration.setClientId(id);
            configuration.setSecret(secret);
            final String scope = getProperty(OIDC_SCOPE, i);
            if (isNotBlank(scope)) {
                configuration.setScope(scope);
            }
            final String discoveryUri = getProperty(OIDC_DISCOVERY_URI, i);
            if (isNotBlank(discoveryUri)) {
                configuration.setDiscoveryURI(discoveryUri);
            }
            final String useNonce = getProperty(OIDC_USE_NONCE, i);
            if (isNotBlank(useNonce)) {
                configuration.setUseNonce(Boolean.parseBoolean(useNonce));
            }
            final String jwsAlgo = getProperty(OIDC_PREFERRED_JWS_ALGORITHM, i);
            if (isNotBlank(jwsAlgo)) {
                configuration.setPreferredJwsAlgorithm(JWSAlgorithm.parse(jwsAlgo));
            }
            final String maxClockSkew = getProperty(OIDC_MAX_CLOCK_SKEW, i);
            if (isNotBlank(maxClockSkew)) {
                configuration.setMaxClockSkew(Integer.parseInt(maxClockSkew));
            }
            final String clientAuthenticationMethod = getProperty(OIDC_CLIENT_AUTHENTICATION_METHOD, i);
            if (isNotBlank(clientAuthenticationMethod)) {
                configuration.setClientAuthenticationMethod(ClientAuthenticationMethod.parse(clientAuthenticationMethod));
            }
            for (int j = 1; j <= MAX_NUM_CUSTOM_PROPERTIES; j++) {
                if (containsProperty(OIDC_CUSTOM_PARAM_KEY + j, i)) {
                    configuration.addCustomParam(getProperty(OIDC_CUSTOM_PARAM_KEY + j, i), getProperty(OIDC_CUSTOM_PARAM_VALUE + j, i));
                }
            }
            final String type = getProperty(OIDC_TYPE, i);
            final OidcClient oidcClient;
            if (OIDC_AZURE_TYPE.equalsIgnoreCase(type)) {
                oidcClient = new AzureAdClient(new AzureAdOidcConfiguration(configuration));
            } else if (OIDC_GOOGLE_TYPE.equalsIgnoreCase(type)) {
                oidcClient = new GoogleOidcClient(configuration);
            } else {
                oidcClient = new OidcClient(configuration);
            }
            oidcClient.setName(concat(oidcClient.getName(), i));
            clients.add(oidcClient);
        }
    }
}
Also used : AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) OidcConfiguration(org.pac4j.oidc.config.OidcConfiguration) AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) OidcClient(org.pac4j.oidc.client.OidcClient) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient)

Example 7 with GoogleOidcClient

use of org.pac4j.oidc.client.GoogleOidcClient in project cas by apereo.

the class DefaultDelegatedClientFactory method getOidcClientFrom.

@SneakyThrows
private OidcClient getOidcClientFrom(final Pac4jOidcClientProperties oidc) {
    if (oidc.getAzure().isEnabled() && StringUtils.isNotBlank(oidc.getAzure().getId())) {
        LOGGER.debug("Building OpenID Connect client for Azure AD...");
        val azure = getOidcConfigurationForClient(oidc.getAzure(), AzureAdOidcConfiguration.class);
        azure.setTenant(oidc.getAzure().getTenant());
        val cfg = new AzureAdOidcConfiguration(azure);
        val azureClient = new AzureAdClient(cfg);
        configureClient(azureClient, oidc.getAzure());
        return azureClient;
    }
    if (oidc.getGoogle().isEnabled() && StringUtils.isNotBlank(oidc.getGoogle().getId())) {
        LOGGER.debug("Building OpenID Connect client for Google...");
        val cfg = getOidcConfigurationForClient(oidc.getGoogle(), OidcConfiguration.class);
        val googleClient = new GoogleOidcClient(cfg);
        configureClient(googleClient, oidc.getGoogle());
        return googleClient;
    }
    if (oidc.getKeycloak().isEnabled() && StringUtils.isNotBlank(oidc.getKeycloak().getId())) {
        LOGGER.debug("Building OpenID Connect client for KeyCloak...");
        val cfg = getOidcConfigurationForClient(oidc.getKeycloak(), KeycloakOidcConfiguration.class);
        cfg.setRealm(oidc.getKeycloak().getRealm());
        cfg.setBaseUri(oidc.getKeycloak().getBaseUri());
        val kc = new KeycloakOidcClient(cfg);
        configureClient(kc, oidc.getKeycloak());
        return kc;
    }
    if (oidc.getApple().isEnabled() && StringUtils.isNotBlank(oidc.getApple().getPrivateKey())) {
        LOGGER.debug("Building OpenID Connect client for Apple...");
        val cfg = getOidcConfigurationForClient(oidc.getApple(), AppleOidcConfiguration.class);
        val factory = new PrivateKeyFactoryBean();
        factory.setAlgorithm("EC");
        factory.setSingleton(false);
        factory.setLocation(ResourceUtils.getResourceFrom(oidc.getApple().getPrivateKey()));
        cfg.setPrivateKey((ECPrivateKey) factory.getObject());
        cfg.setPrivateKeyID(oidc.getApple().getPrivateKeyId());
        cfg.setTeamID(oidc.getApple().getTeamId());
        cfg.setTimeout(Beans.newDuration(oidc.getApple().getTimeout()));
        val kc = new AppleClient(cfg);
        configureClient(kc, oidc.getApple());
        return kc;
    }
    if (oidc.getGeneric().isEnabled()) {
        LOGGER.debug("Building generic OpenID Connect client...");
        val generic = getOidcConfigurationForClient(oidc.getGeneric(), OidcConfiguration.class);
        val oc = new OidcClient(generic);
        configureClient(oc, oidc.getGeneric());
        return oc;
    }
    return null;
}
Also used : lombok.val(lombok.val) AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) OidcClient(org.pac4j.oidc.client.OidcClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) PrivateKeyFactoryBean(org.apereo.cas.util.crypto.PrivateKeyFactoryBean) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) AppleClient(org.pac4j.oidc.client.AppleClient) SneakyThrows(lombok.SneakyThrows)

Example 8 with GoogleOidcClient

use of org.pac4j.oidc.client.GoogleOidcClient in project ddf by codice.

the class OidcHandlerConfigurationImpl method createOidcClient.

@VisibleForTesting
OidcClient createOidcClient(String idpType, OidcConfiguration oidcConfiguration, String callBackUri) {
    OidcClient oidcClient;
    if ("Keycloak".equals(idpType)) {
        oidcClient = new KeycloakOidcClient((KeycloakOidcConfiguration) oidcConfiguration);
    } else if ("Azure".equals(idpType)) {
        oidcClient = new AzureAdClient((AzureAdOidcConfiguration) oidcConfiguration);
    } else if ("Google".equals(idpType)) {
        oidcClient = new GoogleOidcClient(oidcConfiguration);
    } else {
        oidcClient = new OidcClient<>(oidcConfiguration);
    }
    oidcClient.setName(oidcConfiguration.getClientId());
    if (isBlank(callBackUri)) {
        oidcClient.setCallbackUrl(DEFAULT_CALLBACK_URL);
    } else {
        // Strip additional query parameters from the callBackUri
        String uri = callBackUri.split("&")[0];
        oidcClient.setCallbackUrl(uri);
    }
    return oidcClient;
}
Also used : KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) OidcClient(org.pac4j.oidc.client.OidcClient) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) KeycloakOidcConfiguration(org.pac4j.oidc.config.KeycloakOidcConfiguration) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

GoogleOidcClient (org.pac4j.oidc.client.GoogleOidcClient)8 OidcClient (org.pac4j.oidc.client.OidcClient)7 OidcConfiguration (org.pac4j.oidc.config.OidcConfiguration)5 AzureAdClient (org.pac4j.oidc.client.AzureAdClient)4 KeycloakOidcClient (org.pac4j.oidc.client.KeycloakOidcClient)4 AzureAdOidcConfiguration (org.pac4j.oidc.config.AzureAdOidcConfiguration)4 CasClient (org.pac4j.cas.client.CasClient)3 FacebookClient (org.pac4j.oauth.client.FacebookClient)3 Verb (com.github.scribejava.core.model.Verb)2 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)2 Collection (java.util.Collection)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SneakyThrows (lombok.SneakyThrows)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Test (org.junit.Test)2 CasConfiguration (org.pac4j.cas.config.CasConfiguration)2 BaseClient (org.pac4j.core.client.BaseClient)2 Clients (org.pac4j.core.client.Clients)2