Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/sso login ux #608

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
89f3d5b
fix (typecheck): fix typecheck issue
vaimdev Oct 17, 2024
cdeaf63
Merge branch 'master' into dev/sso_login_ux
vaimdev Oct 28, 2024
dbad147
feat: Add databricks helper class and functions
vaimdev Oct 28, 2024
799e93b
fix (refresh token, lint): Fix refresh token and lint issue
vaimdev Oct 28, 2024
e1737d8
fix (lint): fix lint issue
vaimdev Oct 29, 2024
caa7809
fix (databricks helper): fix missing function definition
vaimdev Oct 29, 2024
71c5eb1
fix (databricks helpers): fix function call namespace
vaimdev Oct 30, 2024
c187ead
wip (sso logic): Add SSO flow token verification in plot function, wh…
vaimdev Nov 5, 2024
412e944
wip (sso): fix whether to throw exception when fail to get token
vaimdev Nov 6, 2024
9283e8a
wip (sso): fix message display logic
vaimdev Nov 6, 2024
be26dee
fix (sso): fix flow
vaimdev Nov 6, 2024
5ea4841
fix (sso): fix display message flow
vaimdev Nov 6, 2024
8a482b5
fix (sso): Graph is not shown in dashboard due to only the first HTML…
vaimdev Nov 7, 2024
ab2794c
wip (sso): fix syntax error
vaimdev Nov 7, 2024
5b35284
wip (sso): debugging code
vaimdev Nov 8, 2024
8355b0f
wip (debug): add debug print
vaimdev Nov 8, 2024
1a2ab33
wip (fix): syntax error
vaimdev Nov 8, 2024
a536648
wip (debug):debugging print
vaimdev Nov 8, 2024
dd29430
wip (debug): debugging print
vaimdev Nov 8, 2024
36fcfea
wip (sso): attempt to display error in iframe
vaimdev Nov 8, 2024
4820620
wip (databricks): return error msg html in the case of plot with inva…
vaimdev Nov 8, 2024
2d6ad0b
wip (sso): display html message before throw exception
vaimdev Nov 8, 2024
05d0dff
wip(sso): fix error
vaimdev Nov 8, 2024
fd46826
wip (sso): fix syntax error
vaimdev Nov 9, 2024
4816fd6
wip (sso): clean up code
vaimdev Nov 9, 2024
bff2459
Update docstr for new/updated methods
sabizmil Nov 11, 2024
4b0b129
fix (lint): fix lint issue
vaimdev Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion graphistry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
ArrowFileUploader,
PyGraphistry,
from_igraph,
from_cugraph
from_cugraph,
databricks_sso_wait_for_token,
databricks_sso_login_init,
databricks_sso_login
)

from graphistry.compute import (
Expand Down
72 changes: 72 additions & 0 deletions graphistry/pygraphistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ def refresh(token=None, fail_silent=False):
logger.debug("2. @PyGraphistry refresh :relogin")
if isinstance(e, TokenExpireException):
print("Token is expired, you need to relogin")
PyGraphistry._config['api_token'] = None
PyGraphistry._is_authenticated = False
return PyGraphistry.relogin()

if not fail_silent:
Expand Down Expand Up @@ -2448,6 +2450,72 @@ def _handle_api_response(response):



# Databricks Dashboard SSO helper functions

class DatabricksHelper():

@staticmethod
def sso_repeat_get_token(repeat, wait):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public methods should have .rst-friendly docstrs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, we're trying to make all new code mypy-typed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, noted. I will add them in.

time.sleep(wait)

for i in range(repeat):
token = PyGraphistry.sso_get_token()
if token:
return token
time.sleep(2)

return

@staticmethod
def databricks_sso_wait_for_token(repeat=5, wait=20):
from IPython.display import display, HTML
if not PyGraphistry.api_token():
msg_html = '<br /><strong> .... </strong>'
if not PyGraphistry.DatabricksHelper.sso_repeat_get_token(repeat, wait):
msg_html = f'{msg_html}<br /><strong>Failed to get token after {repeat} .... </strong>'
raise Exception(f"Failed to get token after {repeat} retries")
msg_html = f'{msg_html}<br /><strong>Got token</strong>'
display(HTML(msg_html))
else:
display(HTML('<br /><strong>Token is valid, no waiting required.</strong>'))

@staticmethod
def databricks_sso_login_init(wait=20):
from IPython.display import display, HTML, clear_output

def init_login(wait):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

un-nest

clear_output()
token = PyGraphistry.api_token()
if token:
is_valid = PyGraphistry.verify_token()
if not is_valid:
print("***********token not valid, refresh token*****************")
display(HTML('<br /><strong>Refresh token ....</strong>'))
try:
PyGraphistry.refresh()
except Exception:
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error case handling may need thinking?


else:
print("Token is still valid")
display(HTML('<br /><strong>Token is still valid ....</strong>'))

else:
print("***********Prepare to sign in*****************")

msg_html = f'<br /><strong>Prepare to sign in ....</strong><br><strong>Please Login with the link appear later. Waiting for success login for {wait} seconds, please login within {wait} seconds....</strong><br /><strong>Please close the browser tab and come back to dashboard....</strong>'

display(HTML(msg_html))
init_login(wait)


@staticmethod
def databricks_sso_login(server="hub.graphistry.com", org_name=None, idp_name=None, retry=5, wait=20):
from IPython.display import clear_output
clear_output()
if not PyGraphistry.api_token():
PyGraphistry.register(api=3, protocol="https", server=server, is_sso_login=True, org_name=org_name, idp_name=idp_name, sso_timeout=None, sso_opt_into_type="display")


client_protocol_hostname = PyGraphistry.client_protocol_hostname
store_token_creds_in_memory = PyGraphistry.store_token_creds_in_memory
Expand Down Expand Up @@ -2501,6 +2569,10 @@ def _handle_api_response(response):
personal_key_secret = PyGraphistry.personal_key_secret
switch_org = PyGraphistry.switch_org

# databricks dashboard helper functions
databricks_sso_wait_for_token = PyGraphistry.DatabricksHelper.databricks_sso_wait_for_token
databricks_sso_login_init = PyGraphistry.DatabricksHelper.databricks_sso_login_init
databricks_sso_login = PyGraphistry.DatabricksHelper.databricks_sso_login


class NumpyJSONEncoder(json.JSONEncoder):
Expand Down
Loading