# /authorize endpoint returns CORS error in Node.JS Application

**URL:** <https://community.auth0.com/t/authorize-endpoint-returns-cors-error-in-node-js-application/124682>\
**Category:** Get Help\
**Tags:** regular-database-connections, connections\
**Created:** [January 11, 2024, 7:27pm UTC](https://community.auth0.com/t/authorize-endpoint-returns-cors-error-in-node-js-application/124682 "2024-01-11T19:27:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafael4](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rafael4/32/60772_2.png) [@rafael4](https://community.auth0.com/u/rafael4)\
**Post date:** [January 11, 2024, 7:27pm UTC](https://community.auth0.com/t/authorize-endpoint-returns-cors-error-in-node-js-application/124682/1 "2024-01-11T19:27:49Z")

</div>

I have a node.js express application with the following /token endpoint that can redirect to auth0 authorize endpoint

```auto
router.post('/token', limiter, oauth2Validations.validateCreateToken, (req, res) => {
  const authInfo = _.clone(req.body)

  const ip = req.ip
  authInfo.ip = ip.split(',')[0]
  if (!req.oidc.isAuthenticated()) {
    return res.oidc.login({
      authorizationParams: {
        connection: 'Username-Password-Authentication',
      },
    })
  }

  usersApp
    .oauth2PasswordAuth(authInfo)
    .then((payload) => {
      res.status(200).json(payload)
    })
    .catch((err) => {
      processError(res, err)
    })
})

```

When i call this endpoint and redirects to auth0, i always receive a CORS error:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/e/2/e24b8989d06a38981b0f90999c2756a5ba7f3d69.png)

I am running the api in localhost:3000 and frontend in localhost:3001, and already set both in Allowed Origins (CORS)

![image](https://global.discourse-cdn.com/auth0/original/3X/7/b/7bca5f615c2b2dd2936fc2e55f0113651eb4f28c.png)

If i just get the /authorize url and copy and paste into a tab in the browser, it works

Somebody can belp?

---

<div class="post-metadata">

**Author:** ![gauthamsv5](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@gauthamsv5](https://community.auth0.com/u/gauthamsv5)\
**Post date:** [January 13, 2024, 2:42am UTC](https://community.auth0.com/t/authorize-endpoint-returns-cors-error-in-node-js-application/124682/3 "2024-01-13T02:42:54Z")

</div>

Hi. Thanks for reaching out to community.

This does not look like a normal CORS issue. Browsers create a preflight request if it is needed. It’s an OPTIONS request like below and is sent before the actual request message.

OPTIONS method is not supported on the /authorize endpoint as it is expected that the browser will request the page directly and not via an xhr request.

Some alternatives here would be:

- A redirect flow to /authorize with prompt=none
- getTokenSilently() method if using the auth0-spa-js SDK
- a refresh token flow (this can do an xhr request to /oauth/token)

Let us know if this works.

Thanks,  
Gautham

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 27, 2024, 2:43am UTC](https://community.auth0.com/t/authorize-endpoint-returns-cors-error-in-node-js-application/124682/4 "2024-01-27T02:43:42Z")

</div>

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