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);
}
}
}
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;
}
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;
}
Aggregations