Error: invalid_request device_id and device_name are required for private IP

后端 未结 6 461
眼角桃花
眼角桃花 2020-11-30 08:53

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

相关标签:
6条回答
  • 2020-11-30 09:10

    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

    0 讨论(0)
  • 2020-11-30 09:15

    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.

    0 讨论(0)
  • 2020-11-30 09:18

    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
    
    0 讨论(0)
  • 2020-11-30 09:21

    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.

    0 讨论(0)
  • 2020-11-30 09:21

    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

    0 讨论(0)
  • 2020-11-30 09:23

    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.

    0 讨论(0)
提交回复
热议问题