Skip to content

Commit

Permalink
fix(auth): remove deprecated console-only auth flow
Browse files Browse the repository at this point in the history
  • Loading branch information
mwfarb committed Sep 1, 2023
1 parent 4b1f3b0 commit 1f4d88f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
44 changes: 11 additions & 33 deletions arena/auth.py
Expand Up @@ -76,27 +76,18 @@ def authenticate_user(self, web_host):
creds.refresh(Request())
session = AuthorizedSession(creds)
else:
# test for valid browser before starting browser-required auth-flow
try:
webbrowser.get()
except (webbrowser.Error) as err:
print("Console-only OS detected. {0}".format(err))
return True

# automated browser flow for local client
print("Requesting new Google authentication.")
if self._is_headless_client():
# console flow for remote client
flow = InstalledAppFlow.from_client_config(
json.loads(gauth_json), self._scopes)
creds = flow.run_console()
else:
# automated browser flow for local client
flow = InstalledAppFlow.from_client_config(
json.loads(gauth_json), self._scopes)
creds = flow.run_local_server(port=0)

# # alternate, run console flow with browser popup
# flow = InstalledAppFlow.from_client_config(
# json.loads(gauth_json), self._scopes, redirect_uri="urn:ietf:wg:oauth:2.0:oob")
# auth_url, _ = flow.authorization_url(prompt="consent")
# print("Please go to this URL: {}".format(auth_url))
# webbrowser.open(auth_url, new=1, autoraise=True)
# code = input("Enter the authorization code: ")
# flow.fetch_token(code=code)
# creds = flow.credentials
flow = InstalledAppFlow.from_client_config(
json.loads(gauth_json), self._scopes)
creds = flow.run_local_server(port=0)

session = flow.authorized_session()
with open(scene_gauth_path, "wb") as token:
Expand Down Expand Up @@ -185,19 +176,6 @@ def get_writable_scenes(self, web_host):
my_scenes = self._get_my_scenes(web_host, self._id_token)
return json.loads(my_scenes)

def _is_headless_client(self):
""" Determine headless or headed console.
"""
if "SSH_TTY" in os.environ or "SSH_CLIENT" in os.environ:
print("SSH connection detected, using headless auth.")
return True
try:
webbrowser.get()
return False
except (webbrowser.Error) as err:
print("Console-only OS detected. {0}".format(err))
return True

def _log_token(self):
"""
Update user with token in use.
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -29,8 +29,8 @@
"paho-mqtt~=1.5.1",
"requests~=2.28.1",
"webcolors~=1.3",
"google_auth_oauthlib~=0.5.2",
"google-auth~=1.35.0",
"google_auth_oauthlib~=1.0.0",
"google-auth~=2.22.0",
"PyJWT~=2.4.0"
],
classifiers=[
Expand Down

0 comments on commit 1f4d88f

Please sign in to comment.