Google APIs - how to redirect a url to my local host

I am working on integrating google login into Phonegap application using Google OAuth. It happens that when creating a client ID for my application, I have to select โ€œInstalled applicationโ€ and then the application type โ€œOtherโ€, since I create my application using Phonegap.

This gives me two redirect URIs such as " urn:ietf:wg:oauth:2.0:oob " and " http://localhost ". I am not going to go with " urn:ietf:wg:oauth:2.0:oob ", as it requires the user to copy the code and return it to the application. Another option I have is redirecting to localhost.

The problem here is, how do I redirect the URL to localhost when I'm on the iPad? I tried using different redirect URIs, but Google does not allow me to use them. It only adheres to redirecting to localhost (or adding some port numbers), which I don't have.

Does anyone have workarounds? Are there any methods to accomplish this task? I am stuck. Please help.

+4
source share
2 answers

You can also use rewrite rules.

For example, I need this callback for Google: http://local.dev/users/login-google

So, I set this URL in the google console: http://localhost/JUMP/local.dev/users/login-google

And in apache a simple redirect:

 RewriteEngine on RewriteRule ^JUMP/(.+)$ http://$1 [R,L] 
+3
source

I have had the same issue recently. I also needed to understand that for the Twitter API ( answer found here ).

For google, I found two ways to fix the problem.

  • Google will accept the localhost callback address. For example, if you are on the xampp server and your redirection is stored in C:\xampp\htdocs\nozzle\callbacks\google.php , then your redirection will be indicated in the request (and in the Google API Console ): http://localhost/nozzle/callbacks/google.php Solution to the problem.
  • If you work on a vhosted site : redirect to a live site (or somewhere in the structure of your local hosts) to communicate with google api, then serialize this data and send it to your url on the local virtual host.

Option 2 requires a more detailed explanation. Here's a breakdown:

  • I am developing locally on a virtual host. My data for my application is not in the localhost folder ( http://myapp.dev ). So I needed another solution that would allow me to continue to develop locally on vhost, but also make requests to the Google APIs.
  • Setup: the first call is made from http://myapp.dev/ , but I use my live server address for redirection. After authorization from a user, Google redirects back to my site, where I make an additional api call. This information is returned (again to my website) and I then serialize this information and redirect to http://myapp.dev/callback as a request by adding data = and put the serialized data at the end of this call. Then it goes to my vhost site, and I return the data using $ _REQUEST ['data'], non-sterilize it, and I am good to go.
  • This may seem like a lot of work, but for me and my team itโ€™s worth continuing to work on the spot until we are ready to live.

In addition, I think you could do the same process through the localhost address and not live, but I have not tested this. But if you do this with a live site, your entire team will be able to make the same requests from their local vhosts if they are also vhosted at http://myapp.dev

Foot Note: I am using the socialmedia-oauth-login tool to access the Google APIs.

+3
source

All Articles