use of io.micronaut.security.oauth2.configuration.endpoints.EndpointConfiguration in project micronaut-security by micronaut-projects.
the class OauthClientCondition method matches.
@Override
public boolean matches(ConditionContext context) {
AnnotationMetadataProvider component = context.getComponent();
BeanContext beanContext = context.getBeanContext();
if (beanContext instanceof ApplicationContext && component instanceof ValueResolver) {
Optional<String> optional = ((ValueResolver) component).get(Named.class.getName(), String.class);
if (optional.isPresent()) {
String name = optional.get();
OauthClientConfiguration clientConfiguration = beanContext.getBean(OauthClientConfiguration.class, Qualifiers.byName(name));
String failureMsgPrefix = "Skipped client creation for provider [" + name;
if (clientConfiguration.isEnabled()) {
if (clientConfiguration.getAuthorization().flatMap(EndpointConfiguration::getUrl).isPresent()) {
if (clientConfiguration.getToken().flatMap(EndpointConfiguration::getUrl).isPresent()) {
if (clientConfiguration.getGrantType() == GrantType.AUTHORIZATION_CODE) {
return true;
} else {
context.fail(failureMsgPrefix + "] because grant type is not authorization code");
}
} else {
context.fail(failureMsgPrefix + "] because no token endpoint is configured");
}
} else {
context.fail(failureMsgPrefix + "] because no authorization endpoint is configured");
}
} else {
context.fail(failureMsgPrefix + "] because the configuration is disabled");
}
return false;
}
}
return true;
}
use of io.micronaut.security.oauth2.configuration.endpoints.EndpointConfiguration in project micronaut-security by micronaut-projects.
the class DefaultOauthClient method authorizationRedirect.
@Override
public Publisher<MutableHttpResponse<?>> authorizationRedirect(HttpRequest<?> originating) {
AuthorizationRequest authorizationRequest = beanContext.createBean(OauthAuthorizationRequest.class, originating, clientConfiguration);
String authorizationEndpoint = clientConfiguration.getAuthorization().flatMap(EndpointConfiguration::getUrl).orElseThrow(() -> new ConfigurationException("Oauth client requires the authorization URL to be set in configuration"));
if (LOG.isTraceEnabled()) {
LOG.trace("Starting authorization code grant flow to provider [{}]. Redirecting to [{}]", getName(), authorizationEndpoint);
}
return Flux.just(redirectHandler.redirect(authorizationRequest, authorizationEndpoint));
}
use of io.micronaut.security.oauth2.configuration.endpoints.EndpointConfiguration in project micronaut-security by micronaut-projects.
the class OauthPasswordAuthenticationProvider method getTokenEndpoint.
/**
* Builds the secure endpoint from the client configuration.
*
* @param clientConfiguration The client configuration
* @return The token endpoint
*/
protected SecureEndpoint getTokenEndpoint(OauthClientConfiguration clientConfiguration) {
SecureEndpointConfiguration endpointConfiguration = clientConfiguration.getToken().orElseThrow(() -> new IllegalArgumentException("Token endpoint configuration is missing for provider [" + clientConfiguration.getName() + "]"));
List<AuthenticationMethod> authMethodsSupported = Collections.singletonList(endpointConfiguration.getAuthMethod().orElse(AuthenticationMethod.CLIENT_SECRET_BASIC));
String url = endpointConfiguration.getUrl().orElseThrow(() -> new IllegalArgumentException("Token endpoint URL is null for provider [" + clientConfiguration.getName() + "]"));
return new DefaultSecureEndpoint(url, authMethodsSupported);
}
use of io.micronaut.security.oauth2.configuration.endpoints.EndpointConfiguration in project micronaut-security by micronaut-projects.
the class OpenIdClientFactory method overrideFromConfig.
private void overrideFromConfig(DefaultOpenIdProviderMetadata configuration, OpenIdClientConfiguration openIdClientConfiguration, OauthClientConfiguration oauthClientConfiguration) {
openIdClientConfiguration.getJwksUri().ifPresent(configuration::setJwksUri);
oauthClientConfiguration.getIntrospection().ifPresent(introspection -> {
introspection.getUrl().ifPresent(configuration::setIntrospectionEndpoint);
introspection.getAuthMethod().ifPresent(authMethod -> configuration.setIntrospectionEndpointAuthMethodsSupported(Collections.singletonList(authMethod.toString())));
});
oauthClientConfiguration.getRevocation().ifPresent(revocation -> {
revocation.getUrl().ifPresent(configuration::setRevocationEndpoint);
revocation.getAuthMethod().ifPresent(authMethod -> configuration.setRevocationEndpointAuthMethodsSupported(Collections.singletonList(authMethod.toString())));
});
openIdClientConfiguration.getRegistration().flatMap(EndpointConfiguration::getUrl).ifPresent(configuration::setRegistrationEndpoint);
openIdClientConfiguration.getUserInfo().flatMap(EndpointConfiguration::getUrl).ifPresent(configuration::setUserinfoEndpoint);
openIdClientConfiguration.getAuthorization().flatMap(EndpointConfiguration::getUrl).ifPresent(configuration::setAuthorizationEndpoint);
openIdClientConfiguration.getToken().ifPresent(token -> {
token.getUrl().ifPresent(configuration::setTokenEndpoint);
token.getAuthMethod().ifPresent(authMethod -> configuration.setTokenEndpointAuthMethodsSupported(Collections.singletonList(authMethod.toString())));
});
EndSessionEndpointConfiguration endSession = openIdClientConfiguration.getEndSession();
if (endSession.isEnabled()) {
endSession.getUrl().ifPresent(configuration::setEndSessionEndpoint);
}
}
Aggregations