I am trying to generate access_token
from Azure.
Error Message:
Failed to load https://login.microsoftonline.com/......../oauth2/token: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:61697' is therefore not allowed access.
Code snippet:
function SubmitForm() {
var data = {
'grant_type': "password",
'client_id': "<client_id>",
'username': "<username>@<tenant>.onmicrosoft.com",
'password': "<password>",
'resource': "<resource>",
'redirect_uri': "http://localhost:55871/"
}
$.ajax({
url: "https://login.microsoftonline.com/<tenant_id>/oauth2/token",
type: "POST",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
crossDomain: true,
beforeSend: setHeader,
success: function(d) {
console.log(d);
},
error: function (a, b, c) {
console.log(a, b, c);
}
});
}
Similarly I tried for jQuery and AngularJS as well but fall into the same error.
Can you help us in getting an access_token
along with refresh_token
from Azure using any client side scripting which is browser independant?
Note: The same piece of code is only working with IE (not with Chrome, Edge, Safari etc.).