May 13 2022 12:30 AM
We are using simple jQuery to get the access token from Azure AD. But we are facing the CORS error we are not understanding what we are doing wrong.
Here is the code:
$.ajax({
type: "POST",
URL: "https://login.microsoftonline.com/xxxx-xxxx-xxxx-xxxx/oauth2/token",
headers: {
"Content-Type": "application/x-www-form-URL encoded; charset=utf-8",
"Access-Control-Allow-Origin": "*"
},
crossDomain: true,
data: {
"client_id": "xxxx-xxxx-xxxx-xxxx",
"resource": "https://xxxxx.crm.dynamics.com",
"client_secret": "client secret",
"grant-type": "client credentials"
},
success: function (data, textStatus, xhr) {
var results = data;
},
error: function (jqXHR, exception) {
var msg = jqXHR.status;
}
});