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

Gp02 forward #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 21 additions & 11 deletions dlauthenticator/dlauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# GCDLAUTHENTICATOR -- GC JupyterHub authenticator - ISS


__version__ = '0.4.0'
__author__ = 'Mike Fitzpatrick <[email protected]>'
__version__ = '0.4.1'
__author__ = 'Mike Fitzpatrick <[email protected]>'


import os
Expand All @@ -29,24 +29,26 @@

if DEF_SERVICE_ROOT is None:
THIS_HOST = socket.gethostname()
if THIS_HOST[:5] == 'dldev':
DEF_SERVICE_ROOT = "https://dldev.datalab.noirlab.edu"
elif THIS_HOST[:6] == 'dltest':
DEF_SERVICE_ROOT = "https://dltest.datalab.noirlab.edu"
if THIS_HOST[:4] == 'gp02':
DEF_SERVICE_ROOT = f"https://gp02.datalab.noirlab.edu"
else:
DEF_SERVICE_ROOT = "https://datalab.noirlab.edu"
DEF_SERVICE_ROOT = f"https://datalab.noirlab.edu"

# Typically the terraform environment will set the
# JHUB_DN_NAME env variable
JHUB_DNS_NAME = os.environ.get('JHUB_DNS_NAME')
if JHUB_DNS_NAME is None:
if THIS_HOST[:4] == 'gp02':
DEF_SERVICE_ROOT = f"https://datalab.noirlab.edu"
DL_LOGIN_NEXT_URL = f"https://gp02.datalab.noirlab.edu"
elif JHUB_DNS_NAME is None:
DL_LOGIN_NEXT_URL = f"{DEF_SERVICE_ROOT}/devbooks/"
else:
DL_LOGIN_NEXT_URL = f"https://{JHUB_DNS_NAME}"

DEF_SERVICE_URL = DEF_SERVICE_ROOT + "/auth"



# Make the runtime path to the debug user file accessible only to somebody
# with admin privs on the machine running the authenticator.

Expand Down Expand Up @@ -165,15 +167,19 @@ def post_authenticate(self, handler, data, token):
class DataLabAuthenticator(BaseDataLabAuthenticator):
"""
Data Lab Jupyter token authenticator.
Notice this class doesn't perform a log in proper, that happens on the datalab login
form, which sets a cookie with the login token in the browser, is that token the
one that is used in the is class to authenticate the user.
Notice this class doesn't perform a log in proper, that happens on the
datalab login form, which sets a cookie with the login token in the
browser, is that token the one that is used in the is class to
authenticate the user.
"""
post_logout_url = f"{DEF_SERVICE_ROOT}/account/logout.html"
invalid_token_url = f"{DEF_SERVICE_ROOT}/account/login.html?next={DL_LOGIN_NEXT_URL}"

def __init__(self, parent=None, db=None, _deprecated_db_session=None):
self.auto_login = True
self.log.info(f"THIS_HOST :{THIS_HOST}")
self.log.info(f"DEF_SERVICE_URL :{DEF_SERVICE_URL}")
self.log.info(f"DL_LOGIN_NEXT_URL :{DL_LOGIN_NEXT_URL}")

@gen.coroutine
def authenticate(self, handler, data):
Expand All @@ -188,6 +194,8 @@ def authenticate(self, handler, data):

# if we do not have the token then we can just route to login
if dl_token is None:
self.log.info(f"NULL token :{dl_token}")
self.log.info(f"NULL redirect :{self.invalid_token_url}")
handler.redirect(self.invalid_token_url)
return None

Expand All @@ -207,6 +215,8 @@ def authenticate(self, handler, data):
self.log.info(f"Using debug user info for user:{username}")
return self.post_authenticate(handler, debug_user_info, None)

self.log.info(f"Invalid token redirect :{dl_token}")
self.log.info(f"Invalid redirect :{self.invalid_token_url}")
handler.redirect(self.invalid_token_url)
return None
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='dlauthenticator',
version='0.4.0',
version='0.4.2',
description='Data Lab Authenticator for JupyterHub',
url='https://github.com/astro-datalab/dlauthenticator',
author='Mike Fitzpatrick',
Expand Down