Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: invalid_request device_id and device_name are required for private IP

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

like image 906
phenomenon.aurora Avatar asked Jul 14 '14 12:07

phenomenon.aurora


4 Answers

An alternative to editing a hosts file is to use the "Magic DNS" service http://xip.io/ or http://nip.io/ (see edit)

xip.io is a magic domain name that provides wildcard DNS for any IP address.Say your LAN IP address is 10.0.0.1. Using xip.io,

        10.0.0.1.xip.io   resolves to   10.0.0.1
    www.10.0.0.1.xip.io   resolves to   10.0.0.1
 mysite.10.0.0.1.xip.io   resolves to   10.0.0.1
foo.bar.10.0.0.1.xip.io   resolves to   10.0.0.1

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.xip.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.

I have no affiliation with xip.io; I'm just a satisfied user.

2016 Edit: I've heard reports of instability with the xip.io DNS servers. There is a copy-cat service nip.io that behaves exactly the same as xip.io, but during July 2016, nip.io had a 100% response rate while xip.io did not.

like image 72
whitehat101 Avatar answered Nov 14 '22 05:11

whitehat101


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.

like image 30
Josh Diehl Avatar answered Nov 14 '22 04:11

Josh Diehl


Edit: Only relevant when developing locally.

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

  • Go to your google development console https://console.developers.google.com/project, choose credentials and change the callback IP to a domain like http://myflask.com:5000/oauth2callback. In my case I am using a Flask application, so the 5000 port is necessary.

  • Next add to your private/etc/hosts file a new entry matching the above hostname to your IP, like so:

    # (example IP)
    172.1.1.1 myflask.com
    
  • Give Google a minute to update your credentials, and visit your site at http://myflask.com:5000

like image 6
philmaweb Avatar answered Nov 14 '22 05:11

philmaweb


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.

like image 2
Mikee Avatar answered Nov 14 '22 05:11

Mikee