Skip to content

Commit

Permalink
Merge pull request #3 from girder/handle-non-gui-envs
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna authored Feb 2, 2022
2 parents 2242c26 + 5fe12a8 commit cdd4ca7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions girder_cli_oauth_client/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
from pathlib import Path
from typing import Dict, Optional
from urllib.parse import urlencode, urlparse
Expand Down Expand Up @@ -96,8 +97,13 @@ def maybe_restore_login(self) -> Optional[AuthHeaders]:
return self.auth_headers

def login(self) -> AuthHeaders:
# TODO: try catch webbrowser.Error, print the url?
webbrowser.open(self._get_authorization_url())
auth_url = self._get_authorization_url()
if os.environ.get('DISPLAY'):
webbrowser.open(auth_url)
else:
print('visit the following url in a browser:')
print(auth_url)

code = input('enter the code shown in your browser: ')
self._session.token = self._get_oauth_token(code)
self._save()
Expand Down

0 comments on commit cdd4ca7

Please sign in to comment.