oauth2client.tools module¶
Command-line tools for authenticating via OAuth 2.0
Do the OAuth 2.0 Web Server dance for a command line application. Stores the generated credentials in a common file that is used by other example apps in the same directory.
-
oauth2client.tools.
run_flow
(*args, **kwargs)[source]¶ Core code for a command-line application.
The
run()
function is called from your application and runs through all the steps to obtain credentials. It takes aFlow
argument and attempts to open an authorization server page in the user’s default web browser. The server asks the user to grant your application access to the user’s data. If the user grants access, therun()
function returns new credentials. The new credentials are also stored in thestorage
argument, which updates the file associated with theStorage
object.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.
The tools module defines an
ArgumentParser
the already contains the flag definitions thatrun()
requires. You can pass thatArgumentParser
to yourArgumentParser
constructor:parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, parents=[tools.argparser]) flags = parser.parse_args(argv)
Parameters: - flow – Flow, an OAuth 2.0 Flow to step through.
- storage – Storage, a
Storage
to store the credential in. - flags –
argparse.Namespace
, (Optional) The command-line flags. This is the object returned from callingparse_args()
onargparse.ArgumentParser
as described above. Defaults toargparser.parse_args()
. - http – An instance of
httplib2.Http.request
or something that acts like it.
Returns: Credentials, the obtained credential.