Skip to content
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
Expand Up @@ -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
Expand All @@ -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()
Expand Down