Getting popup box when trying to get Access token

When trying to use the HTTP basic auth post I am getting this popup and no matter when I enter can not get past it?

            var FreeAgentConsumerKey = '@ViewBag.FreeAgentConsumerKey';
            var FreeAgentConsumerSecret = '@ViewBag.FreeAgentConsumerSecret';
            var GrantType = '@ViewBag.GrantType';
            var Code = '@ViewBag.Code';
            var ReturnUrl = '@ViewBag.ReturnUrl';
            var SendToUrl = '@ViewBag.SendToUrl';
            $.ajax({
                type: 'POST',
                url: SendToUrl,
                data: { username: 'John', password: 'Smith', grant_type: GrantType, code: Code, redirect_uri: ReturnUrl },
                dataType: "json",
                contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Authorization", "Basic" + btoa(FreeAgentConsumerKey + ":" + FreeAgentConsumerSecret));
                },
                xhrFields: {
                    withCredentials: true
                },
                success: function (result) {
                    var token = result;
                },
                error: function (req, status, error) {
                    alert(error);
                }
            });

Ignore the username: ‘John’, password: ‘Smith’ replaced these to be username: FreeAgentConsumerKey , password: FreeAgentConsumerSecret

Hi Richard,

In the authorization header, it looks like you might need a space between “Basic” and the hash of client ID + secret: xhr.setRequestHeader("Authorization", "Basic " + btoa(FreeAgentConsumerKey + ":" + FreeAgentConsumerSecret)).

Since you’re already sending an authorization header, you should not need the username and password in the data attribute.

Could you also double check that the URL you are sending the request to ends in /v2/token_endpoint?

Hope this helps.

Ioan

https://api.sandbox.freeagent.com/v2/token_endpoint that is where I’m sending the request too,

Updated code:

$.ajax({
type: ‘POST’,
url: SendToUrl,
data: { grant_type: GrantType, code: Code, redirect_uri: ReturnUrl },
dataType: “json”,
contentType: ‘application/x-www-form-urlencoded;charset=UTF-8’,
beforeSend: function (xhr) {
xhr.setRequestHeader(“Authorization”, "Basic " + btoa(FreeAgentConsumerKey + “:” + FreeAgentConsumerSecret));
},
xhrFields: {
withCredentials: true
},
success: function (result) {
debugger;
var token = result;
},
error: function (req, status, error) {
debugger;
alert(error);
}
});

Hi there,
I am getting exactly the same problem - any resolution?