diff --git a/docs/source/howto/rest.md b/docs/source/howto/rest.md index 6b5337a0..66f8595d 100644 --- a/docs/source/howto/rest.md +++ b/docs/source/howto/rest.md @@ -33,36 +33,13 @@ such as: To send requests using the JupyterHub API, you must pass an API token with the request. -The preferred way of generating an API token is by running: - -```bash -openssl rand -hex 32 -``` - -This `openssl` command generates a potential token that can then be -added to JupyterHub using `.api_tokens` configuration setting in -`jupyterhub_config.py`. - -```{note} -The api_tokens configuration has been softly deprecated since the introduction of services. -``` - -Alternatively, you can use the `jupyterhub token` command to generate a token -for a specific hub user by passing the **username**: - -```bash -jupyterhub token -``` - -This command generates a random string to use as a token and registers -it for the given user with the Hub's database. - -In [version 0.8.0](changelog), a token request page for -generating an API token is available from the JupyterHub user interface: +While JupyterHub is running, any JupyterHub user can request a token via the `token` page. +This is accessible via a `token` link in the top nav bar from the JupyterHub home page, +or at the URL `/hub/token`. :::{figure-md} -![token request page](../images/token-request.png) +![token request page](../images/token-page.png) JupyterHub's API token page ::: @@ -74,6 +51,40 @@ JupyterHub's token page after successfully requesting a token. ::: +### Register API tokens via configuration + +Sometimes, you'll want to pre-generate a token for access to JupyterHub, +typically for use by external services, +so that both JupyterHub and the service have access to the same value. + +First, you need to generate a good random secret. +A good way of generating an API token is by running: + +```bash +openssl rand -hex 32 +``` + +This `openssl` command generates a potential token that can then be added to JupyterHub configuration in `jupyterhub_config.py`. + +For external services, this would be registered with JupyterHub via configuration: + +```python +c.JupyterHub.services = [ + { + "name": "my-service", + "api_token": the_secret_value, + }, +] +``` + +At this point, requests authenticated with the token will be associated with The service `my-service`. + +```{note} +You can also load additional tokens for users via the `JupyterHub.api_tokens` configuration. + +However, this option has been softly deprecated since the introduction of services. +``` + ## Assigning permissions to a token Prior to JupyterHub 2.0, there were two levels of permissions: diff --git a/docs/source/images/token-page.png b/docs/source/images/token-page.png index de4b4721..a0d75fff 100644 Binary files a/docs/source/images/token-page.png and b/docs/source/images/token-page.png differ diff --git a/docs/source/images/token-request-success.png b/docs/source/images/token-request-success.png index c5efe2f1..8617261d 100644 Binary files a/docs/source/images/token-request-success.png and b/docs/source/images/token-request-success.png differ diff --git a/docs/source/images/token-request.png b/docs/source/images/token-request.png deleted file mode 100644 index 050614da..00000000 Binary files a/docs/source/images/token-request.png and /dev/null differ diff --git a/docs/source/tutorial/getting-started/services-basics.md b/docs/source/tutorial/getting-started/services-basics.md index ae23912e..bcb62d09 100644 --- a/docs/source/tutorial/getting-started/services-basics.md +++ b/docs/source/tutorial/getting-started/services-basics.md @@ -39,7 +39,7 @@ openssl rand -hex 32 In [version 0.8.0](changelog), a TOKEN request page for generating an API token is available from the JupyterHub user interface: -![Request API TOKEN page](/images/token-request.png) +![Request API TOKEN page](/images/token-page.png) ![API TOKEN success page](/images/token-request-success.png) diff --git a/share/jupyterhub/templates/token.html b/share/jupyterhub/templates/token.html index de34683f..0c209716 100644 --- a/share/jupyterhub/templates/token.html +++ b/share/jupyterhub/templates/token.html @@ -21,7 +21,7 @@ This note will help you keep track of what your tokens are for.

- + {% block expiration_options %} {% endblock expiration_options %} - You can configure when your token will be expired. + You can configure when your token will expire. @@ -62,8 +62,8 @@

API Tokens

- These are tokens with full access to the JupyterHub API. - Anything you can do with JupyterHub can be done with these tokens. + These are tokens with access to the JupyterHub API. + Permissions for each token may be viewed via the JupyterHub tokens API. Revoking the API token for a running server will require restarting that server.

@@ -72,7 +72,7 @@ - +
Note Last used CreatedExpires atExpires