Currently I try to make login using angular 2 to spring oauth2.
I get this error when click login in my angular:
XMLHttpRequest cannot load http://localhost:8080/REM/oauth/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
Angular
login(username: string, password: string) {
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
headers.append('Accept', 'application/json');
let options = new RequestOptions({ headers: headers });
let params = new URLSearchParams();
params.append('grant_type', "password");
params.append('client_id', "client");
params.append('client_secret', "secret");
params.append('username', "user");
params.append('password', "pass");
return this.http.post(this.urlLogin, params.toString(), options).map(this.extractData);}
CORS
<mvc:cors>
<mvc:mapping path="/**" allowed-origins="http://localhost:3000, *"
allowed-methods="POST, GET, PUT, DELETE"
allowed-headers="X-Requested-With, Content-Type, X-Codingpedia,Authorization, Accept, Origin"
allow-credentials="false" max-age="3600" />
</mvc:cors>
Kindly find full server configuration at: https://github.com/robbyrahmana/Config