Skip to content
This repository has been archived by the owner on Aug 16, 2018. It is now read-only.
/ google_auth Public archive

A Python3 library for handling Google authentication for services such as Google Drive and Google Docs

Notifications You must be signed in to change notification settings

rewardStyle/google_auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

google_auth

A Python3 library for handling Google authentication for services such as Google Drive and Google Docs

Required configuration

In order to authenticate with Google API services ( such as Google Drive ), this module requires a valid client_secret.json file in the working directory of the application using the module.

This file can be obtained from [email protected] and will resemble this:

{"installed":{"client_id":"xxxxx.apps.googleusercontent.com","project_id":"carbon-inkwell-194003","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"xxxxx","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}

Use Cases

This module is intended to serve as a universal means of authenticating with Google services such as Google Drive and Google Sheets.

It is probably best used as a submodule within other libraries that are purpose-built for accessing those Google services.

Usage

In a module which needs to authenticate with Google:

import httplib2
from google_auth import get_credentials

credentials = get_credentials('myUniqueAppName')
http = credentials.authorize(httplib2.Http())

If no valid credentials have been stored, then the module will complete the OAuth2 flow ( with Google ) in order to obtain new credentials ( stored locally as client_credentials.json ).

Scopes

This module has default Scopes defined. HOWEVER -- scopes can be passed into get_credentials() as a named argument for users who wish to specify different Scopes:

credentials = get_credentials('myUniqueAppName', scopes=('foo', 'bar'))

The WHYs

Why was this module developed ?

Authenticating ( and subsequently using ) Google services can be somewhat arcane, at least from within Python applications.

This module was developed to make authentication as simple as possible.

Why use OAuth2?

( AKA, "Why not use simple token authentication?" )

Using Google API keys are only usable for accessing public resources in Google. Accessing private resources ( Sheets, Docs, etc. ) requires OAuth2.

Important Note: Authenticating via OAuth2 from scratch requires manual intervention the first time.

Reference

https://developers.google.com/sheets/api/quickstart/python

About

A Python3 library for handling Google authentication for services such as Google Drive and Google Docs

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages