aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@mellanox.com>2020-06-14 22:27:21 -0300
committerJason Gunthorpe <jgg@nvidia.com>2020-06-22 20:24:18 -0300
commitcbdacc5965fc401f7401b977aef806230bf556ef (patch)
tree8691d8d02ab159f6b2fa48a0b5c78ab4a51d87a2
parentb9445b60cb0a1abd1bc437f213a284dfa03fbb74 (diff)
downloadcloud_mdir_sync-cbdacc5965fc401f7401b977aef806230bf556ef.tar.gz
cloud_mdir_sync-cbdacc5965fc401f7401b977aef806230bf556ef.tar.bz2
cloud_mdir_sync-cbdacc5965fc401f7401b977aef806230bf556ef.zip
OAUTH: Only start one webbrowser tab for concurrent authentications
Starting a browser tab per authentication attempt makes a mess, so long as there is something in auth_redirs then the active browser tab will eventually get redirected to the new auth being added. Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
-rw-r--r--cloud_mdir_sync/gmail.py5
-rw-r--r--cloud_mdir_sync/oauth.py14
-rw-r--r--cloud_mdir_sync/office365.py5
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)