Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subdomain in Google Console Redirect URIs

I have an web application that uses google api (google drive). The application is used by many clients and every client has an subdomain to access the system.

So the domain is appdomain.com

And for users I have foo.appdomain.com, bar.appdomain.com, etc.appdomain.com.

But in google console redirect URI I have to manually put the redirect urls, is there any way I can use wildcards to redirect to make google accept any of subdomains like: *.appdomain.com ?

With this I can make the google authorization calls with the user subdomain in redirect_uri:

https://accounts.google.com/o/oauth2/auth?redirect_uri=http://foo.appdomain.com
like image 541
IPValverde Avatar asked Nov 30 '12 19:11

IPValverde


People also ask

How do I redirect a subdomain to a URL?

Under Modify a Subdomain, locate the domain you want to redirect, then click its Manage Redirection link on the right. In the text box, type the URL you would like visitors to be redirected to if they go to the subdomain sample1.hgexample.com. Click Save. You will see the redirected URL under the Redirection column.

Can you redirect subdomain to main domain?

If you want to redirect your subdomain to your main domain, you can do this by editing your . htaccess file. Add the following lines of code to the file, replacing example.com with your actual domain name: RewriteEngine On RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [NC] RewriteRule ^(.


2 Answers

Wildcard matching subdomains is not supported in Google OAuth. You could try using the state parameter and include the user-specific information there. This parameter will be returned to you in the response. More information on state here.

like image 128
vlatko Avatar answered Sep 25 '22 16:09

vlatko


You can create a master subdomain to get all google auth responses and redirect to correct subdomain using the "state" query parameter.

For example create google.mydomain.com and use it as your valid "Redirect URI" and Apache will can redirect this url to each user with redirect (or rewrite) feature.

More info about apache redirects in http://www.simonecarletti.com/blog/2009/01/apache-query-string-redirects/

Here the code I'm using:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^google\.
RewriteCond %{QUERY_STRING} state=([a-z0-9]+)
RewriteRule ^(.*)$ http://%1.mydomain.com/$1 [L]
like image 33
Lito Avatar answered Sep 23 '22 16:09

Lito