-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from google.oauth2.credentials import Credentials | ||
from google_auth_oauthlib.flow import InstalledAppFlow | ||
from googleapiclient.discovery import build | ||
|
||
from fmtr.tools.logging_tools import logger | ||
|
||
|
||
class Authenticator: | ||
""" | ||
Authenticate via link or saved token | ||
""" | ||
|
||
PATH = None | ||
SCOPES = [] | ||
SERVICE = None | ||
VERSION = None | ||
|
||
@classmethod | ||
def auth(cls): | ||
msg = f'Doing auth for service {cls.SERVICE} ({cls.VERSION})...' | ||
logger.info(msg) | ||
|
||
PATH_CREDS = cls.PATH / 'credentials.json' | ||
PATH_TOKEN = cls.PATH / 'token.json' | ||
|
||
if PATH_TOKEN.exists(): | ||
data_token = PATH_TOKEN.read_json() | ||
credentials = Credentials.from_authorized_user_info(data_token, cls.SCOPES) | ||
else: | ||
flow = InstalledAppFlow.from_client_secrets_file(PATH_CREDS, cls.SCOPES) | ||
credentials = flow.run_local_server(open_browser=False) | ||
PATH_TOKEN.write_text(credentials.to_json()) | ||
service = build(cls.SERVICE, cls.VERSION, credentials=credentials) | ||
return service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.0.7 | ||
1.0.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters