aboutsummaryrefslogtreecommitdiffstats
path: root/cloud_mdir_sync/oauth.py
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 /cloud_mdir_sync/oauth.py
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>
Diffstat (limited to 'cloud_mdir_sync/oauth.py')
-rw-r--r--cloud_mdir_sync/oauth.py14
1 files changed, 14 insertions, 0 deletions
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()