# Fail to request access token from Auth0

**URL:** <https://community.auth0.com/t/fail-to-request-access-token-from-auth0/82583>\
**Category:** Get Help\
**Tags:** jwt\
**Created:** [April 28, 2022, 7:20pm UTC](https://community.auth0.com/t/fail-to-request-access-token-from-auth0/82583 "2022-04-28T19:20:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhujiajun62](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/zhujiajun62/32/36964_2.png) [@zhujiajun62](https://community.auth0.com/u/zhujiajun62)\
**Post date:** [April 28, 2022, 7:20pm UTC](https://community.auth0.com/t/fail-to-request-access-token-from-auth0/82583/1 "2022-04-28T19:20:20Z")

</div>

I follow the test instruction to request a token from auth0 with jQUERY.

 ![4d15b3b7-78f5-406f-845c-e419a258d795-mobile](https://global.discourse-cdn.com/auth0/original/3X/5/5/55ec8b5f29688d91b32687d38f6dea22beae4c48.png)  
But I got the error message: Access to XMLHttpRequest at ‘[https://xxx.auth0.com/oauth/token](https://xxx.auth0.com/oauth/token)’ from origin ‘[http://localhost:3000](http://localhost:3000)’ has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.

My application setting:

 ![CORS](https://global.discourse-cdn.com/auth0/original/3X/2/f/2f434dba30f9b8c88bf9c301ef37c7d17062420a.png)  
Please help me, I am struggling to request a token from Auth0.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [April 28, 2022, 9:23pm UTC](https://community.auth0.com/t/fail-to-request-access-token-from-auth0/82583/3 "2022-04-28T21:23:33Z")

</div>

Hello @zhujiajun62 welcome to the community!

> [@zhujiajun62](#):
>
> I follow the test instruction to request a token from auth0 with jQUERY.

Do you mind sharing the documentation you are working with?

What happens if you attempt to obtain a token using the same credentials using cURL?

Let us know!

---

<div class="post-metadata">

**Author:** ![zhujiajun62](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/zhujiajun62/32/36964_2.png) [@zhujiajun62](https://community.auth0.com/u/zhujiajun62)\
**Post date:** [April 29, 2022, 4:34am UTC](https://community.auth0.com/t/fail-to-request-access-token-from-auth0/82583/4 "2022-04-29T04:34:54Z")

</div>

Hi, tyf,  
Thanks for the reply.  
Here is my test code to request the token.

```auto
submitPost = (event) => {
    event.preventDefault();
    var settings = {
      "async": true,
      "crossDomain": true,
      "url": "https://dev-royzhu.us.auth0.com/oauth/token",
      "method": "POST",
      "headers": {
        "content-type": "application/json",
        "Access-Control-Allow-Origin": "http://localhost:3000/"
      },
      "data": "{\"client_id\":\"wRxxxxxxxxxxxxxxxxCG\",\"client_secret\":\"j4_xxxxxxxxxxWkCokt-dmrDlbwCxxxxxxxUUvLt_sO28W-ZP\",\"audience\":\"boardgameforum\",\"grant_type\":\"client_credentials\"}"
    }

    $.ajax(settings).done(function (response) {
      console.log(response);
    });
  }

```

With your suggestion, I edit the curl and send it, out but the result I got is “invalid JSON”.

If you need more information, please let me know.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [April 29, 2022, 9:07pm UTC](https://community.auth0.com/t/fail-to-request-access-token-from-auth0/82583/5 "2022-04-29T21:07:42Z")

</div>

No problem, happy to help where I can!

I’m not seeing anything that stands out in your code aside from the extra header `"Access-Control-Allow-Origin": "http://localhost:3000/"` - What happens if you remove that?

Do you mind trying the curl that from our article on [Getting Access Tokens](https://auth0.com/docs/secure/tokens/access-tokens/get-access-tokens#example-post-to-token-url)? I’m just trying to rule out any issues with obtaining a token in and of itself - CORS can sometimes be a red herring of sorts.

Keep us posted!

---

<div class="post-metadata">

**Author:** ![zhujiajun62](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/zhujiajun62/32/36964_2.png) [@zhujiajun62](https://community.auth0.com/u/zhujiajun62)\
**Post date:** [April 29, 2022, 11:50pm UTC](https://community.auth0.com/t/fail-to-request-access-token-from-auth0/82583/6 "2022-04-29T23:50:31Z")

</div>

Hi, tyf,

Thank you for your reply. It works after removing the headers.  
But I have another question, right now, I have the token in respons[“access\_token”], and I want to do another ajax and add the token to the header. However, I assign it to a var but it is a local var. Can you advise how to pass this token to another ajax request?

Thank you very much.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [May 14, 2022, 11:51pm UTC](https://community.auth0.com/t/fail-to-request-access-token-from-auth0/82583/7 "2022-05-14T23:51:31Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
