HWIOAuthBundle Google login device_id and device_name for a webapp

user3460035 picture user3460035 · Mar 25, 2014 · Viewed 9k times · Source

I am working on a Symfony2 app. I'm using FOSUserBundle to handle authentication and recently integrated it with FOSUserBundle using this tutorial: https://gist.github.com/danvbe/4476697 .

The problem is: I can login using the google api on localhost and everything works fine.

However when I try to login on a real server I get:

Error: invalid_request

device_id and device_name are required for private IP: http://<server_ip>/login/check-google

Request details:

response_type=code
scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile
redirect_uri=http://<server_ip>/login/check-google
client_id=<my_id>

Google documents don't mention these two parameters. I tried to manually send a request with device_id being a UUID and device_name set to "notes". The response I get this time is:

Error: invalid_request

Device info can be set only for native apps.

Request details:

cookie_policy_enforce=false
response_type=code
device_name=notes
scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile
redirect_uri=http://<server_ip>/login/check-google
device_id=4b3403665fea6
client_id=<my_id>

Now, what am I doing wrong?

Answer

Josh Diehl picture Josh Diehl · Sep 24, 2014

Google will not accept a local (private) IP address when doing Oauth or API 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 it with Google in their dev console. That appears as a "real" domain to them, but will still resolve in your browser or code to the local IP. I'm sure a similar approach on Mac or Linux would also work.