diff options
-rw-r--r-- | cloud_mdir_sync/gmail.py | 5 | ||||
-rw-r--r-- | cloud_mdir_sync/oauth.py | 14 | ||||
-rw-r--r-- | cloud_mdir_sync/office365.py | 5 |
3 files changed, 14 insertions, 10 deletions
diff --git a/cloud_mdir_sync/gmail.py b/cloud_mdir_sync/gmail.py index 15ba7e3..121e3b6 100644 --- a/cloud_mdir_sync/gmail.py +++ b/cloud_mdir_sync/gmail.py @@ -6,7 +6,6 @@ import datetime import functools import logging import secrets -import webbrowser from typing import Dict, List, Optional, Set import aiohttp @@ -147,10 +146,6 @@ class GmailAPI(oauth.Account): scopes=self.scopes, login_hint=self.user) - print( - f"Goto {self.cfg.web_app.url} in a web browser to authenticate" - ) - webbrowser.open(url) q = await self.cfg.web_app.auth_redir(url, state, self.redirect_url) diff --git a/cloud_mdir_sync/oauth.py b/cloud_mdir_sync/oauth.py index 0ab30ae..716e7c0 100644 --- a/cloud_mdir_sync/oauth.py +++ b/cloud_mdir_sync/oauth.py @@ -4,6 +4,7 @@ import base64 import hashlib import os import secrets +import webbrowser from abc import abstractmethod from typing import TYPE_CHECKING, Dict, List, Optional @@ -59,6 +60,19 @@ class WebServer(object): redirects back to the localhost server. The final query paremeters will be returned by this function""" queue = asyncio.Queue() + + # If this is the first auth to start then automatically launch a + # browser, otherwise assume the already running browser will take care + # of things + if not self.auth_redirs: + print( + f"Goto {self.url} in a web browser to authenticate (opening browser)" + ) + webbrowser.open(url) + else: + print( + f"Goto {self.url} in a web browser to authenticate (reusing browser)" + ) self.auth_redirs[state] = (url, queue, redir_url) return await queue.get() diff --git a/cloud_mdir_sync/office365.py b/cloud_mdir_sync/office365.py index d76c891..030254b 100644 --- a/cloud_mdir_sync/office365.py +++ b/cloud_mdir_sync/office365.py @@ -7,7 +7,6 @@ import logging import os import pickle import secrets -import webbrowser from typing import Any, Dict, Optional, Union import aiohttp @@ -187,10 +186,6 @@ class GraphAPI(oauth.Account): scopes=self.graph_scopes + self.owa_scopes, login_hint=self.user) - print( - f"Goto {self.cfg.web_app.url} in a web browser to authenticate" - ) - webbrowser.open(url) q = await self.cfg.web_app.auth_redir(url, state, self.redirect_url) |