Skip to main content

A Python helper library for Google Authentication

Project description

PygAuth

A Python helper library for Google Authentication

Usage

Get Service Account Credentials

get_sa_creds(sa_file: Union[str, Path], scopes: List[str] = None)

sa_file: file to read SA creds from
scopes: list of scopes to auth with
Examples:
pygauth.get_sa_creds("creds.json") # get sa creds with no scopes
pygauth.get_sa_creds("creds.json", scopes=["drive"]) # get sa creds using shorthand scope
pygauth.get_sa_creds("creds.json", scopes=["https://www.googleapis.com/auth/drive"]) # get sa creds using longhand scope

Get User Account Credentials

From File:
get_user_creds_file(creds_file: Union[str, Path], scopes: List[str] = None, create_cache: bool = True, refresh_cache: bool = False, remote: bool = False)

creds_file: file to read oauth portal credentials from
scopes: list of scopes to auth with
create_cache: whether to use the .pygauth cache file
refresh_cache: overwrites whatever is cached with a new value automatically
remote: whether to use remote auth or local auth (use when on a headless server)
From Dict:
get_user_creds_dict(creds_dict: Dict[str, str], scopes: List[str] = None, create_cache: bool = True, refresh_cache: bool = False, remote: bool = False)

creds_dict: dictionary of oauth portal credentials
scopes: list of scopes to auth with
create_cache: whether to use the .pygauth cache file
refresh_cache: overwrites whatever is cached with a new value automatically
remote: whether to use remote auth or local auth (use when on a headless server)
Examples:
>>> creds_dict = json.load(open("credentials.json"))
>>> creds = pygauth.get_user_creds_file("credentials.json", scopes=["drive"]) # authenticate using file
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth ...
>>> creds = pygauth.get_user_creds_dict(creds_dict, scopes=["iam"]) # authenticate using dict
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth ...
>>> creds = pygauth.get_user_creds_file("credentials.json", scopes=["drive"]) # authenticate using file
# doesn't ask for another login since this scope has already been authenticated

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pygauth, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size pygauth-0.1.1-py3-none-any.whl (4.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pygauth-0.1.1.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page