I have an external API (which I can not control), which generates the Token. I tested it from .NET WEB API and able to get the token and everything is fine. But when I am trying to access same API endpoint (with Client ID, Client Secret, grant_type and scope) from my Angular 11 front end application, I am getting CORS error as below.
" Access to XMLHttpRequest at '' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."
My Angular code to call API endpoint is :-
callToken()
{
var data="grant_type=client_credentials";
var auth = btoa("ClientID:ClientSecret");
var reqHeader=new HttpHeaders({
'Authorization': 'Basic ' + auth,
'Content-Type': 'application/x-www-form-urlencoded'
});
return this.http.post('API EndPoint', data,{headers: reqHeader});
}
I have tried mutiple options but nothing is working. Same code is working fine in DOTNET.