-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Allow CORS requests to JWK Set endpoint #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report @dgt-amexio. I'm able to access
I'm curious why you need to call the endpoint from a JS application? Can you provide more details on your use case/flow? |
Hello, My use case is to assess whether this library could be used as the backbone of a custom OpenID Connect service.
When attempting to perform authentication, the following calls are performed from my Angular app to the SB app (let's suppose this SB app is accessible on https://server) :
The question is "how could I configure spring-authorization-server to define the proper Access-Control-Allow-Origin strategy ? |
Thanks for the feedback @dgt-amexio. As a temporary workaround, instead of We'll address this issue soon. |
@dgt-amexio We decided NOT to provide a default configuration for CORS in However, I added a minor enhancement that will allow you to inherent the default configuration and enhance it with your custom CORS configuration. Here is a sample of the full configuration: @Configuration(proxyBeanMethods = false)
public class AuthorizationServerConfig {
@EnableWebSecurity
public class AuthorizationServerSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerSecurity.applyDefaultConfiguration(http);
http.cors().configurationSource(corsConfigurationSource());
}
}
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("http://localhost:8080");
config.addAllowedHeader("*");
config.addAllowedMethod("GET");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/oauth2/**", config);
return source;
}
// @formatter:off
@Bean
public RegisteredClientRepository registeredClientRepository() {
RegisteredClient registeredClient = RegisteredClient.withId(UUID.randomUUID().toString())
.clientId("messaging-client")
.clientSecret("secret")
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
.redirectUri("http://localhost:8080/authorized")
.scope("message.read")
.scope("message.write")
.clientSettings(clientSettings -> clientSettings.requireUserConsent(true))
.build();
return new InMemoryRegisteredClientRepository(registeredClient);
}
// @formatter:on
@Bean
public KeyManager keyManager() {
return new StaticKeyGeneratingKeyManager();
}
// @formatter:off
@Bean
public UserDetailsService users() {
UserDetails user = User.withDefaultPasswordEncoder()
.username("user1")
.password("password")
.roles("USER")
.build();
return new InMemoryUserDetailsManager(user);
}
// @formatter:on
} Let me know if you have any questions. |
works like a charm ! |
Describe the bug
CORS issue with /oauth2/jwks endpoint
To Reproduce
Integrate spring-authorization-server in a SpringBoot Application
(following example provided in repo : https://github.com/spring-projects-experimental/spring-authorization-server/tree/master/samples/boot/oauth2-integration/authorizationserver)
Call the /oauth2/jwks endpoint from a JS application (or through any REST Client)
Expected behavior
The associated endpoint should allow CORS requests, but it doesn't.
Usual Spring mechanisms tested, but I seems that the JwkSetEndpointFilter behaviour could not be overriden to allow CORS requests.
Question : how could the service be configured in order to allow CORS requests on /oauth2/jwks ?
Sample
Use https://github.com/spring-projects-experimental/spring-authorization-server/tree/master/samples/boot/oauth2-integration/authorizationserver
The text was updated successfully, but these errors were encountered: