Search code examples
phpoauth-2.0google-apigoogle-oauthgoogle-api-php-client

Google OAuth - device_id and device_name are required for private IP


I have seen this page and plenty others, but all propose solution not suitable for me. I have same problem that the one in link I provided.

I am trying to use Google+ API functions, so users can log in to my page with Google account.

When I had redirect_uri to localhost:

$client->setRedirectUri("https://localhost/...");

everything worked. But then I changed it to local ip 192.168.1.10 and get error (on url https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=https%3A%2F%2F192.168.1.10.......)

  1. That’s an error.

Error: invalid_request

device_id and device_name are required for private IP:

I don't know what should I do. I use PHP server wrappers. I can not change etc/hosts because I am also trying my code on mobile (Android, IPAD). So, local IP is necessary, to test it on Mobile. I want to avoid setting up a test page on some real server, because testing web page on localhost is the fastest way, when still developing the page.


Solution

  • If you cannot change the hosts file of some of your devices, I guess your best bet is to use a local DNS server to fake a domain, just like you would do with an entry in your /etc/hosts. This answer should help you with this:

    https://unix.stackexchange.com/a/64944

    If you set your devices to use your computer as nameserver it should be possible to spoof a domain and use this domain for testing oauth2 authentication.

    Here is some more information about this error: http://developers.blog.box.com/2012/12/19/going-beyond-oauth2-byod-in-the-enterprise/

    device_id and devive_name are mentioned in the specs as well: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-31#section-3.2.1