Google OAuth2 Command Line Example

Google has an OAuth2 client example here

I am completely new to OAuth2, and I would like this example to work before I switch to OAuth2 integration with my application. I have done the following:

  • Register a test application
  • Get client id and client privacy
  • Set these values ​​in client_secrets.json
  • Run the test application: python moderator.py

The application opens a browser where I can (as a user) allow the application access to my account. But Google complains so much (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 assume that localhost: 8080 comes from an internal web server running moderator.py. My question is: did anyone get this example to work? What other components do I need (apache configuration, DNS, ...)

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

+7
source share
4 answers

First of all, I'm sorry if my answer is not very accurate, because I am also very new to OAuth (and even python) ... and also sorry if it came too late, I usually do not have access here.

You tried to use this (worked for me): REDIRECT_URI = 'urn: ietf: wg: oauth: 2.0: oob'

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

Here I have a code snippet with a full OAuth stream.

+2
source

In OAuth 2.0, the redirect_uri parameter is usually registered with the provider. The provider should also use https-only redirect_uri.

You need to register redirect_uri with Google here: https://code.google.com/apis/console/?pli=1#access

0
source

Perhaps try registering your external IP address with Google (some port porting on your router may be required)? If this fails, perhaps you can use Python SimpleServer, register your IP address and force this server to handle the redirect.

0
source

Your redirect_uri has the value ' http: // localhost: 8080 / ' because you pass the flags parameter by default (I don't know how to describe it) to run_flow (stream, storage, flags)

if you look at the define function for the run_flow () function, you will find the following:

 It presumes it is run from a command-line application and supports the following flags: ``--auth_host_name`` (string, default: ``localhost``) Host name to use when running a local web server to handle redirects during OAuth authorization. ``--auth_host_port`` (integer, default: ``[8080, 8090]``) Port to use when running a local web server to handle redirects during OAuth authorization. Repeat this option to specify a list of values. ``--[no]auth_local_webserver`` (boolean, default: ``True``) Run a local web server to handle redirects during OAuth authorization. 
0
source

All Articles