Dodałem do aplikacji
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*");
}
}
Wysyłam dane ajaxem
$('body').on('submit', 'form[name="action-login"]', function () {
var login = '[email protected]';
var password = 'test';
var headers = {
"Authorization": USERNAME + ":" + PASSWORD,
"Accept": "application/json",
};
var data = {
'username': login,
'password': password,
'grant_type': 'password',
'client_secret': '123456',
'client_id': 'clientapp',
'scope': 'read%20write'
};
console.log(headers);
console.log(data);
$.ajax
({
type: "POST",
url: SITE_URL + "oauth/token",
dataType: 'json',
async: false,
headers: headers,
data: data,
success: function () {
alert('Ok!');
},
error: function (e) {
}
});
return false;
});
Cały czas mi leci
jquery-3.0.0.min.js:4 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://127.0.0.1' is therefore not allowed access. The response had HTTP status code 401.
Przed dodaniem mapowania CORS było to samo
Spring Boot 1.3.3