I’m creating a mobile app using Sencha Touch and PhoneGap. I want to be able to allow users to log into the app using their Google credentials but am hitting a brick wall with the initial request with the following error:
The redirect URI in the request: http://localhost did not match a registered URI.
My Google API account has the default 2 URIs registered (http://localhost and urn:ietf:wg:oauth:2.0:oob).
I have tried both of these with no success.
The request I am sending contains the following query string params:
- response_type: ‘code’
- client_id: <client id>
- redirect_uri: ‘http://localhost‘
- scope: ‘https://www.googleapis.com/auth/plus.me‘
The basic process is:
- build URL as above
- open new browser window (using ChildBrowser PhoneGap plugin)
- navigate to the URL
- at this point the Google login page shows and allows me to put in credentials
- after Login tap i am taken to an error page containing the above error.
I am testing this in the iPhone simulator and on my iPhone with the same result in both. The application doesn’t apear to run on the http://localhost url but on file:///var/mobile/Applications/<guid>/<app name>/www/index.html but there is no option to add this in the Google Console (..or is there? 🙂 )
Does anyone have any suggestions about why this isn’t working? I have little to no experience with using OAuth and Google’s APIs so any little hints are more than welcome!
Thanks in advance
Stuart
I suggest you to read this as the best starting point for Google API with OAuth2, and in your case you need this: OAuth2 for Devices.
Probably you are using the wrong endpoint, to request for a user code, you need to use the following endpoint:
This is an example using curl (in your case to authorize the access to the Google+ API):
You’ll get an answer like this:
Then you need to ask for authorization, showning the user the user_code and the verification_url to “pair” your app with the user account of the user. Here there is a good example of this or from the documentation:
The last step, ask for an access_token, using curl:
you’ll get an response like this:
and finally you can access the services you have granted (don’t forget to configure the access from the API console, in your case the Google+ API) with the access_token obtained.
Regarding the question of
The answer is yes, this is the expected behavior. This redirect_uri is telling you where to callback after successfully granted permissions to your app. In your case a mobile device.
In the case of “urn:ietf:wg:oauth:2.0:oob”, is not exactly a redirect. You need to “catch” or “hook” this, to simply continue your process, maybe this can help you or this.
Good luck!