My goal is to programmatically obtain an access token from Azure Active Directory in an Angular 6 application using the method below.
let body1 = new FormData()
body1.append("resource", environment.config.clientId)
body1.append("grant_type", "client_credentials")
body1.append("client_id", environment.config.clientId)
body1.append("client_secret", "*****")
return this._http.post("https://login.microsoftonline.com/" + environment.config.tenant + "/oauth2/token", body1)
While I successfully obtained an access token through this method in Postman, I encountered CORS blockage when attempting the same in my application. The error message is as follows.
Failed to load https://login.microsoftonline.com/*****/oauth2/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://localhost:4200' is therefore not allowed access.
I am seeking guidance on how to enable CORS on Azure Active Directory for all domains.