from jupyterhub.auth import Authenticator
import os
class CustomAuthenticator(Authenticator):
auth_url = 'https://'
jwt_token = 'token'
def authenticate(self, handler, data):
url = self.auth_url
headers = {
'Authorization': f'Bearer {self.jwt_token}'
}
response = requests.get(url, headers=headers)
print("Authentication request sent.")
print("Response JSON:", response.json())
print("--------response----------", response.headers.get('Content-Type'))
if response.status_code == 200:
print("Authentication successful.")
content_type = response.headers.get('Content-Type', '')
user_info = response.json()
username = next((claim['value'] for claim in user_info if claim['type'] == 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'), None)
if username:
print("Authenticated username:", username)
redirect_url = "/spawn"
# print("Redirecting to:", redirect_url)
request.redirect(redirect_url)
return # Ensure no further processing occurs
else:
print("Username not found in the response.")
return None
else:
print("Authentication failed.")
return None
c.JupyterHub.authenticator_class = CustomAuthenticator
c.JupyterHub.xsrf_cookies = True
After login need to redirect to next page that is not happening getting some errors
super().finish(*args, **kwargs) File “/usr/local/lib/python3.12/site-packages/tornado/web.py”, line 1205, in finish raise RuntimeError(“finish() called twice”) RuntimeError: finish() called twice