# Confused about CORS and login button

**URL:** <https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382>\
**Category:** Friendly Help\
**Created:** [October 30, 2022, 1:23pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382 "2022-10-30T13:23:16Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![opertoonist](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@opertoonist](https://www.patreondevelopers.com/u/opertoonist)\
**Post date:** [October 30, 2022, 1:23pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/1 "2022-10-30T13:23:16Z")

</div>

Probably a simple answer to this, but at the moment I’m stumped — appreciate any help.

I’m getting a CORS error from my OAuth login button that’s calling `www.patreon.com/oauth2/authorize`. Based on [this post](https://www.patreondevelopers.com/t/cors-issue-in-patreon-api-solved/97) I thought this was because the request was happening client-side. When I run the request server-side, however, I don’t get a CORS error, but I also don’t get the authorization pop-up. Further, when I look at the [Javascript server example](https://github.com/Patreon/patreon-js/blob/master/examples/server.js), it seems to be making a client-side request to kick off the authorization, like I’m trying to do.

So, what is causing the CORS error? The page with the login button is on the same domain that I’ve listed as the “Company Domain” in my Patreon client app. Is there somewhere else where I need to enter my domain in order to let the request go through?

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [November 1, 2022, 6:38am UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/2 "2022-11-01T06:38:40Z")

</div>

The domain and redirect uri that were specified for your client (app) at the api must match wherever you are starting the authorization process from. Checking that may help. Also check if there is any redirect happening after the flow is started from user-side.

---

<div class="post-metadata">

**Author:** ![opertoonist](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@opertoonist](https://www.patreondevelopers.com/u/opertoonist)\
**Post date:** [November 7, 2022, 2:06pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/3 "2022-11-07T14:06:56Z")

</div>

Thanks. I’ve checked and the domain matches. I’m using a subdomain and have tried it both with and without, with the same results. The redirect is correct as well, but no redirect is happening. I’m guessing from your reply that a client-side request is OK, but that in my case something is going wrong with the auth, correct?

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [November 7, 2022, 5:29pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/4 "2022-11-07T17:29:43Z")

</div>

Is the error being returned from the api, or are you encountering the error at [patreon.com](http://patreon.com) when you use your app to sign in?

---

<div class="post-metadata">

**Author:** ![opertoonist](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@opertoonist](https://www.patreondevelopers.com/u/opertoonist)\
**Post date:** [November 7, 2022, 5:50pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/5 "2022-11-07T17:50:34Z")

</div>

From [patreon.com](http://patreon.com), on making the request that I’m expecting will open up the authorization pop-up.

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [November 8, 2022, 12:02am UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/6 "2022-11-08T00:02:46Z")

</div>

Ok, so, you are clicking a button at your app, which takes the user to the Patreon authorization flow - and that’s where you get the CORS error. Is that correct?

---

<div class="post-metadata">

**Author:** ![opertoonist](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@opertoonist](https://www.patreondevelopers.com/u/opertoonist)\
**Post date:** [November 8, 2022, 12:36am UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/7 "2022-11-08T00:36:44Z")

</div>

I’m getting the error before the flow begins, meaning there’s no visible change for the user after clicking the button.

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [November 9, 2022, 1:58am UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/8 "2022-11-09T01:58:40Z")

</div>

So a pop up launches and the pop up loads the Patreon authorization page. And you get the error at that moment?

---

<div class="post-metadata">

**Author:** ![opertoonist](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@opertoonist](https://www.patreondevelopers.com/u/opertoonist)\
**Post date:** [November 9, 2022, 1:50pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/9 "2022-11-09T13:50:21Z")

</div>

No, I get the error before the pop-up launches.

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [November 10, 2022, 8:31pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/10 "2022-11-10T20:31:02Z")

</div>

If you get the error before the pop up launches and Patreon is contacted, that should not be related to the Patreon API but the details of your own app setup.

---

<div class="post-metadata">

**Author:** ![opertoonist](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@opertoonist](https://www.patreondevelopers.com/u/opertoonist)\
**Post date:** [November 12, 2022, 3:30pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/11 "2022-11-12T15:30:34Z")

</div>

If the request and the redirect are on different subdomains, could that cause a problem?

---

<div class="post-metadata">

**Author:** ![opertoonist](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@opertoonist](https://www.patreondevelopers.com/u/opertoonist)\
**Post date:** [November 14, 2022, 1:12am UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/12 "2022-11-14T01:12:32Z")

</div>

Here are some more specifics, since so far I’ve been unsuccessful at figuring out what’s going on.

This is the code that gets run when the user clicks the Patreon button in my app:

```auto
var params = 'response_type=code';
params += '&client_id=' + client_id;
params += '&scope=identity identity.memberships'
params += '&redirect_uri=https://[my_domain]/patreon/';
xhr.open('GET', 'https://www.patreon.com/oauth2/authorize?' + params, true);
xhr.send();

```

and this is the error message I get back:

`Failed to load resource: Cross-origin redirection to https://www.patreon.com/login?ru=%2Foauth2%2Fauthorize%3Fresponse_type%3Dcode%26client_id%3D[client_id]%26scope%3Didentity%2Bidentity.memberships%26redirect_uri%3Dhttps%253A%252F%252F[my_domain]%252Fpatreon%252F denied by Cross-Origin Resource Sharing policy: Origin https://studio.step.works is not allowed by Access-Control-Allow-Origin. Status code: 302`

As far as I can tell, everything is in order, and yet I’m still getting the CORS error… any help would be appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [November 14, 2022, 9:07pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/13 "2022-11-14T21:07:19Z")

</div>

This needs troubleshooting at your app or your client’s infra. If any other host, url etc is interfering during the opening of the pop up, such an error may happen. If its possible, do avoid a pop up and instead handle the login through normal pages loading (in different pages depending on the flow) or maybe by using react. (the former would be faster).

---

<div class="post-metadata">

**Author:** ![opertoonist](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@opertoonist](https://www.patreondevelopers.com/u/opertoonist)\
**Post date:** [November 15, 2022, 4:42am UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/14 "2022-11-15T04:42:23Z")

</div>

Apologies if I’m being dense, and I understand that you’re not able to help troubleshoot my app config. However, I’m not following what you mean when you say “do avoid a pop up,” as I’m not specifically requesting or implementing a pop-up, just making the request as formatted above. I’m not seeing how I would implement an alternative auth flow, as the only method I’m reading described in the [API docs](https://docs.patreon.com/#oauth) is to make such a request. My understanding was that the pop-up was Patreon’s response to a correctly formatted request, but instead I’m getting the error.

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [November 15, 2022, 10:51pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/15 "2022-11-15T22:51:41Z")

</div>

From the error message, it looks like something is preventing your flow from being redirected Patreon’s oAuth authorization flow rather than Patreon denying you anything. Or at the worst, studio.step.works is being denied by whatever is producing that message, or even Patreon api.

Try to confirm that this url is in the redirect url of your app details at Patreon clients page.

---

<div class="post-metadata">

**Author:** ![opertoonist](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@opertoonist](https://www.patreondevelopers.com/u/opertoonist)\
**Post date:** [November 16, 2022, 1:40pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/16 "2022-11-16T13:40:43Z")

</div>

I agree that this message would seem to indicate that the app is misconfigured, but I’ve triple-checked everything there. The domain and redirect URLs match exactly — though again, it would be helpful to know if subdomains should be included or not. Could you answer that?

Could there be an issue with the fact that step.works is an uncommon domain?

The fact that it’s a CORS problem seems to indicate that the process which dynamically allows my domain to call the OAuth flow using the info I provided when configuring the client isn’t working. I completely agree that the most likely cause is something misconfigured on my end, but I’ve checked and rechecked every point of failure that I know of, so it seems like something else may be the cause.

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [November 16, 2022, 10:19pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/17 "2022-11-16T22:19:30Z")

</div>

Subdomains should work, but an uncommon domain may be problematic yes. If you have any normal subdomain from which you can do a test, you can try creating an app and making a call with that subdomain.

---

<div class="post-metadata">

**Author:** ![opertoonist](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@opertoonist](https://www.patreondevelopers.com/u/opertoonist)\
**Post date:** [November 17, 2022, 1:12pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/18 "2022-11-17T13:12:23Z")

</div>

Yes! That was it. Got the auth flow going from a .com domain. So, now you know my next question… is there any possibility that .works could be added to the list of supported domains?

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [November 17, 2022, 10:17pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/19 "2022-11-17T22:17:45Z")

</div>

At the moment unlikely.

---

<div class="post-metadata">

**Author:** ![opertoonist](https://avatars.discourse-cdn.com/v4/letter/o/ecc23a/32.png) [@opertoonist](https://www.patreondevelopers.com/u/opertoonist)\
**Post date:** [December 2, 2022, 1:22pm UTC](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382/20 "2022-12-02T13:22:31Z")

</div>

OK, so my test above was not from a subdomain. Now I’m finding that if I create two identical auth links, one from the bare domain, and one from a subdomain of it, the link from the subdomain doesn’t work (same error as above), even though I have the subdomain specified in the client setup. So it seems like subdomains actually aren’t supported? Have you run into a case where they are?

[Next page](https://www.patreondevelopers.com/t/confused-about-cors-and-login-button/6382.md?page=2)
