I am currently working on asp.net web api and I am looking for a way to authenticate users using a bearer token.
On my login page, I submit the user information and then call my communication service function:
submitLogin():void{
this.user = this.loginForm.value;
this._commServe.login(this.user).subscribe(() => {
this.successMessage = "logged in";
},
error => this.errorMessage = <any>error
)
}
Here is the code for the login process:
login(user: User) {
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append( 'grant_type', 'password');
var body = JSON.stringify(user);
return this.http.post(baseUrl + "MeetingSchedulingService/Token"
, body, { headers: headers })
.catch(this.handleError);
}
However, I encounter the common issue of
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
, despite enabling cors on the service.
Can someone help me troubleshoot and fix the code above accordingly?
Thank you.