Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enables Using Environment Variable for Authorization - Issue #49 #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions simplegmail/gmail.py
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ def __init__(
access_type: str = 'offline',
noauth_local_webserver: bool = False,
_creds: Optional[client.OAuth2Credentials] = None,
use_envvars: bool = False
) -> None:
self.client_secret_file = client_secret_file
self.creds_file = creds_file
@@ -79,6 +80,13 @@ def __init__(
# completes for the first time.
if _creds:
self.creds = _creds
elif use_envvars:
# This requires that the environment variable
# 'SIMPLEGMAIL_CREDENTIALS' be set to an already authorized
# gmail_token.json contents. This gives the refresh token
# that can be used indefinitely until revoked.
self.creds = client.OAuth2Credentials.from_json(
os.environ.get('SIMPLEGMAIL_CREDENTIALS'))
else:
store = file.Storage(self.creds_file)
self.creds = store.get()