use of io.gravitee.am.common.utils.ConstantKeys.CLIENT_CONTEXT_KEY in project gravitee-access-management by gravitee-io.
the class LoginSocialAuthenticationHandler method handle.
@Override
public void handle(RoutingContext routingContext) {
final Client client = routingContext.get(CLIENT_CONTEXT_KEY);
// fetch client identity providers
getSocialIdentityProviders(client.getIdentityProviders(), identityProvidersResultHandler -> {
if (identityProvidersResultHandler.failed()) {
logger.error("Unable to fetch client social identity providers", identityProvidersResultHandler.cause());
routingContext.fail(new InvalidRequestException("Unable to fetch client social identity providers"));
}
List<IdentityProvider> socialIdentityProviders = identityProvidersResultHandler.result();
// no social provider, continue
if (socialIdentityProviders == null || socialIdentityProviders.isEmpty()) {
routingContext.next();
return;
}
// client enable social connect
// get social identity providers information to correctly build the login page
enhanceSocialIdentityProviders(socialIdentityProviders, routingContext, resultHandler -> {
if (resultHandler.failed()) {
logger.error("Unable to enhance client social identity providers", resultHandler.cause());
routingContext.fail(new InvalidRequestException("Unable to enhance client social identity providers"));
}
// put social providers in context data
final List<SocialProviderData> socialProviderData = resultHandler.result();
if (socialProviderData != null) {
List<SocialProviderData> filteredSocialProviderData = socialProviderData.stream().filter(providerData -> providerData.getIdentityProvider() != null && providerData.getAuthorizeUrl() != null).collect(Collectors.toList());
List<IdentityProvider> providers = filteredSocialProviderData.stream().map(SocialProviderData::getIdentityProvider).collect(Collectors.toList());
Map<String, String> authorizeUrls = filteredSocialProviderData.stream().collect(Collectors.toMap(o -> o.getIdentityProvider().getId(), SocialProviderData::getAuthorizeUrl));
// backwards compatibility
routingContext.put(OAUTH2_PROVIDER_CONTEXT_KEY, providers);
routingContext.put(SOCIAL_PROVIDER_CONTEXT_KEY, providers);
routingContext.put(SOCIAL_AUTHORIZE_URL_CONTEXT_KEY, authorizeUrls);
}
// continue
routingContext.next();
});
});
}
Aggregations