alexanoid
alexanoid

Reputation: 25842

Google oauth subdomains

I have implemented Google oAuth on the site (example.com). Everything works fine except auth from subdomains on my site(I have a thousands of subdomains). When the user tries to authorize via subdomain, for example

fr.example.com
product1.example.com
product2.de.example.com

I receive an error from Google -

The redirect URI in the request did not match a registered redirect URI

How it could be solved ?

Upvotes: 16

Views: 24209

Answers (5)

Team Aditdude
Team Aditdude

Reputation: 1

In the Authorized JavaScript origins field, enter the origin for your app. You can enter multiple origins to allow for your app to run on different protocols, domains, or subdomains. You cannot use wildcards. In the example below, the second URL could be a production URL.

http://localhost:8080 or https://myproductionurl.example.com

https://developers.google.com/identity/sign-in/web/server-side-flow

Upvotes: 0

Raja
Raja

Reputation: 1

That's because Google's OAuth does not support wildcard sub-domain matching .You can redirect the one static page of all sub-domain and after authenticate or get access token of OAuth then you return on your sub-domain page with access token.

Upvotes: 0

KajMagnus
KajMagnus

Reputation: 11686

The other answers have already clarified that the cause of the troubles is that Google's OpenAuth doesn't support wild card sub domains. However, what you're asking is how can it be solved? Well, you have two choices, according to this email thread:

  1. Provide a single OAuth2 handling endpoint for all subdomains. That is, you'd have a main domain and endpoint, via which you do authentication also for the sub domains. When done authenticating, you redirect back to the sub domain. There's supposedly an OpenAuth state parameter, in which you can encode the sub domain name. This is what I did, here's the code: https://github.com/debiki/debiki-server/blob/master/app/controllers/LoginWithOpenAuthController.scala

  2. You can have each sub domain register independently with Google.

Which option you'll choose depends on which brand the Google users are asked to approve. The main domain, or a sub domain?

Upvotes: 14

Owen Cao
Owen Cao

Reputation: 8183

The redirect URI must exactly match one of the values listed for this project in the Google Developers Console (including the http or https scheme, case, and trailing '/'). So it will not support sub domains if you don't add them in Developers Console.

Upvotes: 2

anfab
anfab

Reputation: 1636

That's because Google's OAuth does not support wildcard subdomain matching. You can refer to more documentation here

Upvotes: 12

Related Questions