Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google OAuth2 command-line example

Google has an example of an OAuth2 client here

I am completelly new to OAuth2 and I would like to get this example working before I move to integrate OAuth2 with my application. What I have done is the following:

  1. Register a test application
  2. Get Client ID and Client Secret
  3. Configure those values into client_secrets.json
  4. Run the test app: python moderator.py

The application opens up a browser, where I can (as a user) authorize the application to access my account. But Google is complaining like this (400 Bad Request):

Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:8080/ did not match a registered redirect URI
Learn more
Request Details
from_login=1
scope=https://www.googleapis.com/auth/moderator
response_type=code
access_type=offline
redirect_uri=http://localhost:8080/
approval_prompt=auto
as=-xxxxxxxxxxxxx
pli=1
client_id=xxxxxxxxxxx.apps.googleusercontent.com
authuser=0
hl=en

I guess the localhost:8080 is coming from an internal web server started by moderator.py. My question is: has somebody goten this example to work? What other components do I need (apache configuration, DNS, ...)

I am very confused with OAuth2 and any help would be greatly appreciated.

like image 989
blueFast Avatar asked Jul 12 '12 15:07

blueFast


People also ask

What is oauth2 example?

OAuth 2.0 allows users to share specific data with an application while keeping their usernames, passwords, and other information private. For example, an application can use OAuth 2.0 to obtain permission from users to store files in their Google Drives. This OAuth 2.0 flow is called the implicit grant flow.


1 Answers

First of all, sorry if my answer isn't very precise, because I'm also very new to OAuth (and even python)... and also sorry if it came too late, I don't usually access here.

Have you tried using this (worked for me): REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'

Check this: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi

Here I have a piece of code with a complete OAuth flow working.

like image 55
GabrielF Avatar answered Oct 03 '22 10:10

GabrielF