Ho un problema CORS quando provo ad autenticare il mio server spring chiamando l'endpoint "oauth/token". Il server risponde con una risposta 401Errore CORS con l'autenticazione OAuth nel server Spring
XMLHttpRequest cannot load http://localhost:8080/oauth/token.
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:8000' is therefore not allowed access.
The response had HTTP status code 401.
Questo è come mi chiamo il server:
login: function(credentials) {
var data = "username=" + encodeURIComponent(credentials.username) + "&password="
+ encodeURIComponent(credentials.password) + "&grant_type=password&scope=read%20write&" +
"client_secret=mySecretOAuthSecret&client_id=awhyapp";
return $http.post('http://localhost:8080/oauth/token', data, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
"Access-Control-Allow-Origin": "*",
"Authorization": "Basic " + Base64.encode("awhyapp" + ':' + "mySecretOAuthSecret")
}
}).success(function (response) {
var expiredAt = new Date();
expiredAt.setSeconds(expiredAt.getSeconds() + response.expires_in);
response.expires_at = expiredAt.getTime();
localStorageService.set('token', response);
return response;
});
OauthConfigurations:
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/oauth/token").permitAll()
.and()
.exceptionHandling()
.authenticationEntryPoint(authenticationEntryPoint)
.and()
.logout()
.logoutUrl("/api/logout")
.logoutSuccessHandler(ajaxLogoutSuccessHandler)
.and()
.csrf()
.requireCsrfProtectionMatcher(new AntPathRequestMatcher("/oauth/authorize"))
.disable()
.headers()
.frameOptions().disable()
.and()
.authorizeRequests()
.antMatchers("/api/authenticate").permitAll()
.antMatchers("/api/register").permitAll()
.antMatchers("...").permitAll()
}
}
ho seguito la risposta a questa domanda (Add headers to oauth/token response (spring-security)), ma il mio problema è che non importa come configuro la mia classe Filter, quelle funzioni non vengono mai chiamate anche se imposto la priorità più alta con l'annotazione @Order .
mi sono bloccato con la stessa identica questione ... Avere hai trovato una soluzione? –