41

I was doing my development with Google Drive API using [localhost:8080]. Suddenly I felt to test it in my local deployment sandbox and it has IP address as [192.168.1.1:8080]. And as per that I changed the credential in developer console client callback URL. I am using OAuth2WebServerFlow to get the refresh token using user consent. Then in future I am using the refresh token and OAuth2WebServerFlow to authenticate the user. But I was surprised - I got the error:

  1. That’s an error. Error: invalid_request device_id and device_name are required for private IP:

I don't know what is happening or how can I fix it. What is going on, I don't understand

phenomenon.aurora
  • 471
  • 1
  • 5
  • 11
  • 1
    Looks like this thread http://stackoverflow.com/questions/22638427/hwioauthbundle-google-login-device-id-and-device-name-for-a-webapp has same issue. – phenomenon.aurora Jul 14 '14 at 12:16
  • I was wandering if we have any ways to figure this out. – phenomenon.aurora Jul 15 '14 at 04:49
  • Any one please do share if any know how on this ? – phenomenon.aurora Jul 16 '14 at 16:40
  • Hi thanks for the edit, and am also waiting if any one shares some spare know how on this. – phenomenon.aurora Jul 18 '14 at 05:48
  • Sorry to say ! I have tried many ways to figure out but not a single steps in success from the readings. And I expected some response in case if any help from google side but its no use. Or is it a kind of not solvable issue. – phenomenon.aurora Jul 20 '14 at 11:46
  • Looks like this issue is a known unresolved bug to the api. Still am looking for some hints to what is this issue. – phenomenon.aurora Jul 21 '14 at 17:05
  • I tried today to fit a public ip address like https://62.1.4.5/oauth2callback, and in surprise it get me an error. So looks like we cannot fit a IP in the redirect. Any ways ? – phenomenon.aurora Jul 22 '14 at 11:34
  • I found a similar problem in http://stackoverflow.com/questions/10215863/why-is-google-oauth-returning-invalid-redirect-uri-in-my-rails-app?s=134cbffe-f268-4d1f-a8f7-1843196370ad, but are the sites which gives the domain names feasible for deployment ? – phenomenon.aurora Jul 23 '14 at 08:10

6 Answers6

52

An alternative to editing a hosts file is to use the "Magic DNS" service https://nip.io/

nip.io is a magic domain name that provides wildcard DNS for any IP address. Say your LAN IP address is 10.0.0.1:

         10.0.0.1.nip.io   resolves to   10.0.0.1      (dot syntax)
    192-168-1-250.nip.io   resolves to   192.168.1.250 (dash syntax)
         0a000803.nip.io   resolves to   10.0.8.3      (hex syntax)
 foo.bar.10.0.0.1.nip.io   resolves to   10.0.0.1      (subdomains)
app-192-168-1-250.nip.io   resolves to   192.168.1.250 (prefixes)

With this service, you can specify a public-looking domain that resolves to a private address.

In the Console, if your Redirect URI was (what you wish you had anyways):

http://192.168.1.1:8080/auth/google_oath2/callback

Replace it with:

http://192.168.1.1.nip.io:8080/auth/google_oath2/callback

"Redirect URIs" does not seem to accept wildcards, so the entire private ip-xip.io needs to be specified in the console.

whitehat101
  • 2,428
  • 23
  • 18
  • Nice idea, but does not resolve on some providers/networks: http://andycroll.com/mac/ruby/xip-io-doesnt-work-on-bt/ – Fafaman Jan 13 '16 at 14:42
  • That is a three year old blog post and the author is speculating that a particular piece of hardware ("something to do with their network using the BT HomeHub DNS") was causing issues. I have yet to run into issues at home or in office, and I don't know what would motivate anyone to intentionally block this service. – whitehat101 Jan 13 '16 at 19:44
  • This was just to point the fact that is does not work with some providers: free.fr in my case. – Fafaman Jan 14 '16 at 14:54
  • 1
    This works! and better than editing hosts file IMHO, because for Android or iOS development it is hard to change the hosts file unless you root it. This is MUCH easier. – Rosdi Kasim Nov 08 '17 at 07:42
  • Works perfect! Thank you – Rodrigo E. Principe Nov 29 '17 at 11:25
  • This works, but at the end it redirects to that nip.io address and i cant get the data returned. How to fix that? – Shile Feb 23 '18 at 14:59
  • xip.io doesn't work now – nikicat Jan 10 '23 at 15:55
18

Google will not accept a local (private) IP address when doing Oauth calls. My workaround was to add an entry in my Windows hosts file for the local IP:

\Windows\System32\drivers\etc

192.168.1.2   fakedomain.com

then register fakedomain.com with Google in their dev console. That appears as a "real" domain to them, but will still resolve in your browser to the local IP. I'm sure a similar approach on Mac or Linux would also work.

Josh Diehl
  • 2,913
  • 2
  • 31
  • 43
  • Its like, thou the work around may work, but the next question comes with the feasibility of the deploying in the real world scenarios. Right now I just got settled that any how a domain name is required for the users client Api access, thanx for the reply. – phenomenon.aurora Oct 03 '14 at 16:51
  • 2
    Won't help for devices – Sebastian Sastre Jun 06 '15 at 22:58
  • For anyone that need to call the fakedomain from an Android device, you must be root and edit /system/etc/hosts. It worked on Android emulator – daniherculano Jan 07 '21 at 11:27
7

Edit: Only relevant when developing locally.

Ok, I'm having the same problem on my Mac. Following steps resolved the issue

maxkoryukov
  • 4,205
  • 5
  • 33
  • 54
philmaweb
  • 514
  • 7
  • 13
3

I got the same error until I changed it from an IP address to a domain name, (192.168.1.113 to localhost in my case) so it looks like Google won't accept bare IP addresses.

Use a domain name for your sandbox, or setup a local domain server if you don't have one.

Mikee
  • 61
  • 5
2

Worth noting that on a Mac you can do the same thing by editing as root:

/private/etc/hosts

Add a similar line as mentioned above

192.168.60.10   fakedomain.com
Alex Gilleran
  • 597
  • 3
  • 12
ejvaudio
  • 93
  • 1
  • 6
0

Modify your file hosts at \Windows\System32\drivers\etc\hosts

add "192.168.1.2 fakedomain.com" into hosts file
restart your windows

Update google console 192.168.1.2 update to fakedomain.com

brew
  • 11
  • 3