# Getting popup box when trying to get Access token

**URL:** <https://api-discuss.freeagent.com/t/getting-popup-box-when-trying-to-get-access-token/850>\
**Category:** Uncategorized\
**Created:** [7 November 2017 11:32 UTC](https://api-discuss.freeagent.com/t/getting-popup-box-when-trying-to-get-access-token/850 "2017-11-07T11:32:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardCompleat](https://api-discuss.freeagent.com/letter_avatar_proxy/v4/letter/r/46a35a/32.png) [@RichardCompleat](https://api-discuss.freeagent.com/u/RichardCompleat)\
**Post date:** [7 November 2017 11:32 UTC](https://api-discuss.freeagent.com/t/getting-popup-box-when-trying-to-get-access-token/850/1 "2017-11-07T11:32:49Z")

</div>

![](https://freeagent-api-discuss-assets-production.s3.dualstack.eu-west-1.amazonaws.com/original/1X/1c5b5bc4bc99bffc987c0cf2c6d36d729eedf56a.png)

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);
                }
            });
```

---

<div class="post-metadata">

**Author:** ![RichardCompleat](https://api-discuss.freeagent.com/letter_avatar_proxy/v4/letter/r/46a35a/32.png) [@RichardCompleat](https://api-discuss.freeagent.com/u/RichardCompleat)\
**Post date:** [7 November 2017 11:46 UTC](https://api-discuss.freeagent.com/t/getting-popup-box-when-trying-to-get-access-token/850/2 "2017-11-07T11:46:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ioan\_Serban](https://api-discuss.freeagent.com/user_avatar/api-discuss.freeagent.com/ioan_serban/32/148_2.png) [@Ioan\_Serban](https://api-discuss.freeagent.com/u/Ioan_Serban)\
**Post date:** [7 November 2017 11:56 UTC](https://api-discuss.freeagent.com/t/getting-popup-box-when-trying-to-get-access-token/850/3 "2017-11-07T11:56:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RichardCompleat](https://api-discuss.freeagent.com/letter_avatar_proxy/v4/letter/r/46a35a/32.png) [@RichardCompleat](https://api-discuss.freeagent.com/u/RichardCompleat)\
**Post date:** [7 November 2017 12:30 UTC](https://api-discuss.freeagent.com/t/getting-popup-box-when-trying-to-get-access-token/850/4 "2017-11-07T12:30:11Z")

</div>

[https://api.sandbox.freeagent.com/v2/token\_endpoint](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);  
}  
});

---

<div class="post-metadata">

**Author:** ![Andrey\_Tchiorniy](https://api-discuss.freeagent.com/user_avatar/api-discuss.freeagent.com/andrey_tchiorniy/32/157_2.png) [@Andrey\_Tchiorniy](https://api-discuss.freeagent.com/u/Andrey_Tchiorniy)\
**Post date:** [15 November 2017 17:32 UTC](https://api-discuss.freeagent.com/t/getting-popup-box-when-trying-to-get-access-token/850/5 "2017-11-15T17:32:21Z")

</div>

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