I am making a http POST request from an angular 8 app (which is running on localhost) to an auth API endpoint to which I have no access. I need to get a token from this endpoint to validate the user. The request is shown below
login(username: string, password: string) {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
})
};
const body = new HttpParams()
.set('grant_type', 'password')
.set('username', username)
.set('password', password);
return this.http.post<any>(`https://api-url`, body, httpOptions)
.pipe(map(user => {
// login successful if there's a jwt token in the response
if (user && user.access_token) {
// Work with user details
}
return user;
}));
}
I get an error
Access to XMLHttpRequest at 'https://api-url' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
When I make the same request from Postman, it works perfectly and I get the response from that endpoint with a token. I don't exactly know what is causing the issue. My screenshots from postman request are shown below. Please help me out with this.