Google API - Redirect URI with an internal IP

2019-06-17 02:49发布

问题:

I'm creating an app using Google calendar API. Everything works fine on my local apache install, using localhost:8888/pathtoapp as the redirect URI.

I want to migrate the app to another machine on my local network. I tried changing the URI to the local ip of the new apache install. I get the following error...

Error: invalid_request
Invalid parameter value for redirect_uri: Raw IP addresses not allowed: http://192.168.0.17/pathtoapp/

Any ideas on how I can use an internal IP as a redirect URI or other ways around it?

Thanks.

回答1:

Looks like the API is not allowing you to use IP addresses. Try to use network name not ip address. If you don't have access to the name, create an alias on your local machine for that specific IP.



回答2:

It's not possible...you have to stick in a domain name on a public server for testing...seems stupid to me as well :-P

Duplicate of this: Can a public IP address be used as Google OAuth redirect URI?



回答3:

[development environment suitable solution]

Whilst the Google Console will not allow you to have an IP as a redirect URI:

Invalid Redirect: http://10.100.1.1 must end with a public top-level domain (such as .com or .org)

you can create a host name entry which redirect you a valid domain to another the desired IP address:

$ vim /etc/hosts

Append: 10.100.1.1 localhost.com www.localhost.com

Now you can access your site from localhost.com or www.localhost.com and have localhost.com as the redirect URI.



回答4:

For window OS, this error can be removed by adding host entry in your system so google will think it as coming from the given hostname

Take your global IP address say: 106.200.247.101 (or google what is my IP, you will get it) go to C:\Windows\System32\drivers\etc\hosts on windows and add a new entry as below

eg: 106.200.247.101 abc.com

Then you will be able to refer to using given hostname



回答5:

Use localhost:port/redirectpath to test on local machine.