Skip to content

Commit

Permalink
fix: #539 - databricks login link and timer switch to javascript to h…
Browse files Browse the repository at this point in the history
…andle async better
  • Loading branch information
DataBoyTX committed Jan 17, 2024
1 parent 360a9eb commit 1b05c8f
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions graphistry/pygraphistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,34 @@ def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type):
"""

if in_ipython() or in_databricks() or sso_opt_into_type == 'display': # If run in notebook, just display the HTML
# from IPython.core.display import HTML
from IPython.display import display, HTML
display(HTML(f'<a href="{auth_url}" target="_blank">old: Login SSO</a>'))
display(Markdown(f'[new: Login SSO]({auth_url})'))
print("Please click the above URL to open browser to login")
print(f"If you cannot see the URL, please open browser, browse to this URL: {auth_url}")
print("Please close browser tab after SSO login to back to notebook")
# return HTML(make_iframe(auth_url, 20, extra_html=extra_html, override_html_style=override_html_style))

# this function was required due to bug where databricks notebooks do not display the html link while a timer is running
def display_link_and_timer(auth_url, sso_timeout):
html_content = f"""
<a href="{auth_url}" target="_blank">Graphistry SSO Login</a><br><br>
<div id='timerDiv'>Timer starts...</div>
<script>
function startTimer(timeoutDuration) {{
var seconds = timeoutDuration;
var interval = setInterval(function() {{
document.getElementById('timerDiv').innerText = seconds + " seconds remaining";
seconds--;
if (seconds < 0) {{
clearInterval(interval);
document.getElementById('timerDiv').innerText = "Timer Expired.";
}}
}}, 1000);
}}
startTimer({sso_timeout});
</script>
"""
display(HTML(html_content))

display_link_and_timer(auth_url, sso_timeout)

elif sso_opt_into_type == 'browser':
print("Please minimize browser after your SSO login and go back to pygraphistry")

Expand Down

0 comments on commit 1b05c8f

Please sign in to comment.