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.

Source Distribution

pygauth-0.1.1.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

pygauth-0.1.1-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page