CORS error while integrating the Azure AD with jQuery

New Contributor

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.

BhararthJanjanam_0-1652426483332.png

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;
}
});

 

0 Replies