I want to authenticate against the oath2/token url using code:
var clientSecret = "-ZO8Q~r23Yr4N2e1TOUVvxxxxxxxxxxxxxxxx";
var tenantId = "b2a45cb3-xxxx-xxxx-xxxx-f125697c41e2";
var resource = "">xxxxxxxtest.api.crm4.dynamics.com";
var version = "9.2";
var webapiurl = `${resource}/api/data/${version}`;
var authurl = `login.microsoftonline.com/.../authorize`;
var microsoftTokenUrl = `login.microsoftonline.com/.../token`;
var grantType = "client_credentials";
$.support.cors = true;
function GetAuthroisationToken() {
var token = null;
$.ajax({
url: microsoftTokenUrl,
type: "POST",
contentType: "application/x-www-form-urlencoded",
crossDomain: true,
dataType: "json",
async: false,
data: {
resource: resource,
client_id: clientId,
client_secret: clientSecret,
grant_type: grantType,
},
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, xhr) {
token = data.access_token;
},
error: function (xhr, textStatus, errorThrown) {
alert(errorThrown);
},
});
return token;
}