0

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.

Issue in client side

Response received from server side

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.).

Antti29
  • 2,953
  • 12
  • 34
  • 36
  • We have our own client side login page to enter UserName and Password to get the access and refresh token back by using Azure oauth2/token endpoint. But the suggested article asking to use adal to use oauth2/authorize endpoint that gives an id_token. With this we need to ask user to provide it's credential once the token is expired. Please suggest how to get Access and Refresh token back from oauth2/token endpoint. – Amit Kumar Agrawal Nov 01 '17 at 12:42

1 Answers1

1

Refer to: No 'Access-Control-Allow-Origin' header with Microsoft Online Auth

Perhaps you're getting the issue because you're accessing it from localhost.

Axar
  • 521
  • 1
  • 3
  • 11
  • Yes we are accessing it from localhost, but we also tried to deploy the same into server and tried the same from there, we still faces the same issue. – Amit Kumar Agrawal Nov 01 '17 at 08:09