32

I am trying to use the Codeigniter spark ( http://getsparks.org/packages/oauth2/versions/HEAD/show) to allow users to login to my php site with fb and google.

My local dev site (on wampserver) is called mysite.dev, for which I have a etc/hosts file like :

127.0.0.1       mysite.dev

Facebook login works absolutely fine. But when I try logging with google, google complains : Invalid parameter value for redirect_uri: Non-public domains not allowed: http://mysite.dev/index.php/oauth2/session/google where oauth2 is my controller and session is the function where I specify fb/google, etc

any clues/hints?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
SIndhu
  • 677
  • 3
  • 15
  • 21
  • Have a similar issue here as well, any good workaround as I can not use localhost, but rather need a custom domain name like: project.company. I would rather not go changing all the developers hostnames to project.company.com – Maksim Luzik Oct 27 '14 at 13:09
  • Possible duplicate of [Oauth - how to test with local urls?](http://stackoverflow.com/questions/10456174/oauth-how-to-test-with-local-urls) – scipilot Jun 16 '16 at 00:25

5 Answers5

20

I got around this by adding a hosts file record for the domain with the dev part at the front rather than the end (which I usually do too):

/etc/hosts

127.0.0.1 localhost.mydomain.com

/etc/apache vhost

ServerName mydomain.com.localhost
ServerAlias localhost.mydomain.com

Then tell google to use:

http://localhost.mydomain.com/index.php/oauth2/session/google
scipilot
  • 6,681
  • 1
  • 46
  • 65
8

When you create client ID for web applications in Google APIs Console you can add allowed Redirect URIs. It accepts localhost urls and others as well.

Naveed
  • 1,191
  • 10
  • 22
  • 52
    Google accepts localhost, but not custom domain like example.somecustomtopleveldomain Which is kind of shame, because if you have multiple web projects, you usually assign custom domain name, like project1.something which does not work. – Maksim Luzik Oct 27 '14 at 13:06
5

Google API Console does not allow 'mysite.dev'.

Petercopter
  • 1,218
  • 11
  • 16
5

Adding

127.0.0.1 localhost.mydomain.com

to my hosts file and

http://localhost.mydomain.com/oauth2callback

to "Authorized redirect URIs" worked for me

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • 1
    This worked for me. In Laravel, you also need to add it to your Homestead.yaml file like so `- map: localhost.mydomain.com to: /home/vagrant/your-path-here/mydomain/public` and then provision – padawanTony Apr 08 '20 at 14:09
0

If you only want to run the OAuth process once on your dev site, there is a quick workaround.

Login to your Google Cloud Console, visit APIs & Services⁩ ▸ Credentials ⁩ ▸ OAuth 2.0 Client IDs ⁩ ▸ Authorised Redirect URIs and a New URI with the following value:

http://localhost/index.php/oauth2/session/google

Then navigate to your dev site using localhost rather than mysite.dev as the domain. Go through the OAuth process on localhost. Google should now accept your return URI. Once successfully authorised, you can go back to using mysite.dev.