mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 15:33:02 +00:00
Updated the reference flask example to include token auth
This commit is contained in:
@@ -200,7 +200,9 @@ or via the `JUPYTERHUB_API_TOKEN` environment variable.
|
|||||||
|
|
||||||
Most of the logic for authentication implementation is found in the
|
Most of the logic for authentication implementation is found in the
|
||||||
[`HubAuth.user_for_cookie`](services.auth.html#jupyterhub.services.auth.HubAuth.user_for_cookie)
|
[`HubAuth.user_for_cookie`](services.auth.html#jupyterhub.services.auth.HubAuth.user_for_cookie)
|
||||||
method, which makes a request of the Hub, and returns:
|
and in the
|
||||||
|
[`HubAuth.user_for_token`](services.auth.html#jupyterhub.services.auth.HubAuth.user_for_token)
|
||||||
|
methods, which makes a request of the Hub, and returns:
|
||||||
|
|
||||||
- None, if no user could be identified, or
|
- None, if no user could be identified, or
|
||||||
- a dict of the following form:
|
- a dict of the following form:
|
||||||
@@ -252,8 +254,11 @@ def authenticated(f):
|
|||||||
@wraps(f)
|
@wraps(f)
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
cookie = request.cookies.get(auth.cookie_name)
|
cookie = request.cookies.get(auth.cookie_name)
|
||||||
|
token = request.headers.get(auth.auth_header_name)
|
||||||
if cookie:
|
if cookie:
|
||||||
user = auth.user_for_cookie(cookie)
|
user = auth.user_for_cookie(cookie)
|
||||||
|
elif token:
|
||||||
|
user = auth.user_for_token(token)
|
||||||
else:
|
else:
|
||||||
user = None
|
user = None
|
||||||
if user:
|
if user:
|
||||||
|
Reference in New Issue
Block a user