| 1 |
# Authenticating a flask service with JupyterHub |
| 2 |
|
| 3 |
Uses `jupyterhub.services.HubOAuth` to authenticate requests with the Hub in a [flask][] application. |
| 4 |
|
| 5 |
## Run |
| 6 |
|
| 7 |
1. Launch JupyterHub and the `whoami service` with |
| 8 |
|
| 9 |
jupyterhub --ip=127.0.0.1 |
| 10 |
|
| 11 |
2. Visit http://127.0.0.1:8000/services/whoami/ |
| 12 |
|
| 13 |
After logging in with your local-system credentials, you should see a JSON dump of your user info: |
| 14 |
|
| 15 |
```json |
| 16 |
{ |
| 17 |
"admin": false, |
| 18 |
"groups": [], |
| 19 |
"kind": "user", |
| 20 |
"name": "queequeg", |
| 21 |
"scopes": [ |
| 22 |
"access:services!service=whoami", |
| 23 |
"read:users:groups!user=queequeg", |
| 24 |
"read:users:name!user=queequeg" |
| 25 |
], |
| 26 |
"session_id": "a32e59cdd7b445759c58c48e47394a38" |
| 27 |
} |
| 28 |
``` |
| 29 |
|
| 30 |
This relies on the Hub starting the whoami service, via config (see [jupyterhub_config.py](./jupyterhub_config.py)). For ordinary users to access this service, they need to be given the appropriate scope (again, see [jupyterhub_config.py](./jupyterhub_config.py)). |
| 31 |
|
| 32 |
A similar service could be run externally, by setting the JupyterHub service environment variables: |
| 33 |
|
| 34 |
JUPYTERHUB_API_TOKEN |
| 35 |
JUPYTERHUB_SERVICE_PREFIX |
| 36 |
|
| 37 |
[flask]: http://flask.pocoo.org |