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

Add authorization url that checks if the user is authorized to access jupyterhub #19

Merged
merged 2 commits into from
Oct 2, 2023
Merged
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
14 changes: 14 additions & 0 deletions jupyterhub_magpie_authenticator/jupyterhub_magpie_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class MagpieAuthenticator(Authenticator):
- c.JupyterHub.authenticator_class = 'jupyterhub_magpie_authenticator.MagpieAuthenticator'
- c.MagpieAuthenticator.magpie_url = "magpie:2000" # url where magpie is running (does not need to be public)
- c.MagpieAuthenticator.public_fqdn = "www.example.com" # fqdn of server where magpie is running

You may also optionally choose to set an `authorization_url` which is a URL that can be used to check whether the
user logged in to Magpie has permission to access jupyterhub:
- c.MagpieAuthenticator.authorization_url = "http://twitcher:8000/ows/verify/jupyterhub"
"""
default_provider = "ziggurat"
magpie_url = Unicode(
Expand All @@ -35,6 +39,12 @@ class MagpieAuthenticator(Authenticator):
config=True,
help="Public fully qualified domain name. Used to set the magpie login cookie."
)
authorization_url = Unicode(
default=None,
config=True,
help="optional URL that can be used to check whether the user logged in to Magpie has permission to access "
"jupyterhub"
)

def get_handlers(self, app):
return [
Expand All @@ -52,6 +62,10 @@ async def authenticate(self, handler, data):
response = requests.post(signin_url, data=post_data)

if response.ok:
if self.authorization_url:
auth_response = requests.get(self.authorization_url, cookies=response.cookies.get_dict())
if not auth_response.ok:
return None
for cookie in response.cookies:
handler.set_cookie(name=cookie.name,
value=cookie.value,
Expand Down