Microsoft identity platform and OAuth 2.0 Resource Owner Password Credentials

Atul Chaudhary 1 Reputation point
2022-09-22T13:18:30.877+00:00

Hi,
I am using One Drive API Name is (Microsoft identity platform and OAuth 2.0 Resource Owner Password Credentials).
API:
https://login.microsoftonline.com/{tenant_ID}/oauth2/token

Everything is working but when I am trying to his this API after putting all data in header like this:
var settings = {
"url": "https://login.microsoftonline.com/{ID}/oauth2/token",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Access-Control-Allow-Origin": "*"
},
"data": {
"grant_type": "password",
"client_id": "{client_id}",
"client_secret": "client_secret",
"resource": "https://graph.microsoft.com",
"username": "username",
"password": "password"
}
};
$.ajax(settings).done(function (response) {
debugger;
alert("test1");
console.log(response);
});

I was using this API by AJAX. But it throws error like this:

Access to XMLHttpRequest at 'https://login.microsoftonline.com//oauth2/token?grant_type=&client_id=&client_secret=&resource=https%3A%2F%2Fgraph.microsoft.com&username=&password=' from origin 'http://localhost:39741' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I also tried by putting access-control-allow-origin in web.config file like this:
243941-abc.png

please help me to find out this issue

Microsoft Security | Microsoft Authenticator
Microsoft Security | Microsoft Graph
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.