From d0eb4e094672c8465f855ea4e05bf71662702bd1 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 3 Feb 2017 17:01:20 +0100 Subject: [PATCH] add `/api/user` handler for identifying the requester --- jupyterhub/apihandlers/users.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jupyterhub/apihandlers/users.py b/jupyterhub/apihandlers/users.py index 74730f0f..6bbfbeca 100644 --- a/jupyterhub/apihandlers/users.py +++ b/jupyterhub/apihandlers/users.py @@ -12,6 +12,18 @@ from ..utils import admin_only from .base import APIHandler +class SelfAPIHandler(APIHandler): + """Return the authenticated user's model + + Based on the authentication info. Acts as a 'whoami' for auth tokens. + """ + @web.authenticated + def get(self): + user = self.get_current_user() + print(user) + self.write(json.dumps(self.user_model(user))) + + class UserListAPIHandler(APIHandler): @admin_only def get(self): @@ -272,6 +284,7 @@ class UserAdminAccessAPIHandler(APIHandler): default_handlers = [ + (r"/api/user", SelfAPIHandler), (r"/api/users", UserListAPIHandler), (r"/api/users/([^/]+)", UserAPIHandler), (r"/api/users/([^/]+)/server", UserServerAPIHandler),