|
| 1 | +(tutorials:provider-specific:oidc)= |
| 2 | +(tutorials:provider-specific:generic:oidc)= |
| 3 | + |
| 4 | +# OpenID Connect (OIDC) Setup |
| 5 | + |
| 6 | +{class}`.OIDCOAuthenticator` is an extension of GenericOAuthenticator, |
| 7 | +but which loads some standard configuration from `.well-known/openid-configuration`. |
| 8 | +This means you'll have fewer options that you need to configure for most |
| 9 | +OIDC providers. |
| 10 | + |
| 11 | +## JupyterHub configuration |
| 12 | + |
| 13 | +Your `jupyterhub_config.py` file should look something like this: |
| 14 | + |
| 15 | +```python |
| 16 | +c.JupyterHub.authenticator_class = "oidc" |
| 17 | +c.OAuthenticator.oauth_callback_url = "https://[your-domain]/hub/oauth_callback" |
| 18 | +c.OAuthenticator.client_id = "[your oauth2 application id]" |
| 19 | +c.OAuthenticator.client_secret = "[your oauth2 application secret]" |
| 20 | +c.OIDCOAuthenticator.openid_provider_url = "https://yourprovider.example.org" |
| 21 | +``` |
| 22 | + |
| 23 | +`openid_provider_url` should be the base URL of your provider. |
| 24 | +OIDCOAuthenticator will fetch `{openid_provider_url}/.well-known/openid-configuration` |
| 25 | +to set up the following configuration: |
| 26 | + |
| 27 | +| OAuthenticator option | openid-configuration key | notes | |
| 28 | +| --------------------- | ------------------------ | ----------------------- | |
| 29 | +| `authorize_url` | `authorization_endpoint` | | |
| 30 | +| `token_url` | `token_endpoint` | | |
| 31 | +| `jwks_uri` | `jwks_uri` | for verifying id tokens | |
| 32 | +| `jwt_issuer` | `issuer` | for verifying id tokens | |
| 33 | +| `userdata_url` | `userinfo_endpoint` | if defined (not always) | |
| 34 | + |
| 35 | +You can get the exact same behavior as `OIDCOAuthenticator` with the base `OAuthenticator`, if you set all of these parameters by hand. |
| 36 | + |
| 37 | +```{note} |
| 38 | +not all providers define `userinfo_endpoint`. |
| 39 | +You can _either_ set `c.OAuthenticator.userdata_url`, |
| 40 | +or set `c.OAuthenticator.userdata_from_id_token = True` to rely on the claims in the `id_token` of the token response. |
| 41 | +``` |
| 42 | + |
| 43 | +Examples of `openid_provider_url` for common providers: |
| 44 | + |
| 45 | +- auth0: `https://$yourdomain.auth0.com` |
| 46 | +- github: `https://github.com/login/oauth` |
| 47 | +- google: `https://accounts.google.com` |
| 48 | +- orcid: `https://orcid.org` |
| 49 | + |
| 50 | +## Additional configuration |
| 51 | + |
| 52 | +Typically, when configuring with OIDC, you'll need to configure the `scope`, which will always include `openid`. |
| 53 | +The remaining scopes may vary. |
| 54 | + |
| 55 | +The default `username_claim` for OIDCOAuthenticator is `sub`, |
| 56 | +but is very likely to vary, depending on your provider. |
| 57 | +Make sure that you use a _verified_ and _unique_ claim from your |
| 58 | + |
| 59 | +```python |
| 60 | +c.OIDCOAuthenticator.scope = ["openid", "email", "groups"] |
| 61 | +c.OIDCOAuthenticator.username_claim = "sub" # the default |
| 62 | +c.OIDCOAuthenticator.auth_state_groups_key = "oauth_user.groups" |
| 63 | +``` |
| 64 | + |
| 65 | +You will likely want to set the `user` |
| 66 | + |
| 67 | +And as with all Authenticators, you will need to `allow` specific users or groups. |
| 68 | + |
| 69 | +(tutorials:provider-specific:generic:orcid)= |
| 70 | +(tutorials:provider-specific:oidc:orcid)= |
| 71 | + |
| 72 | +## Setup for ORCID iD |
| 73 | + |
| 74 | +```{note} |
| 75 | +The `OAuthenticator` will by default lowercase your username. For example, an ORCID iD of `0000-0002-9079-593X` will produce a JupyterHub username of `0000-0002-9079-593x`. |
| 76 | +``` |
| 77 | + |
| 78 | +Follow the ORCID [API Tutorial](https://info.orcid.org/documentation/api-tutorials/api-tutorial-get-and-authenticated-orcid-id/) to create an application via the Developer Tools submenu after clicking on your name in the top right of the page. |
| 79 | + |
| 80 | +Edit your `jupyterhub_config.py` with the following: |
| 81 | + |
| 82 | +```python |
| 83 | +c.JupyterHub.authenticator_class = "oidc" |
| 84 | + |
| 85 | +# Fill these in with your values |
| 86 | +c.OIDCOAuthenticator.oauth_callback_url = "YOUR CALLBACK URL" |
| 87 | +c.OIDCOAuthenticator.client_id = "YOUR CLIENT ID" |
| 88 | +c.OIDCOAuthenticator.client_secret = "YOUR CLIENT SECRET" |
| 89 | + |
| 90 | +c.OIDCOAuthenticator.login_service = "ORCID iD" # Text of login button |
| 91 | +c.OIDCOAuthenticator.openid_provider_url = "https://orcid.org" |
| 92 | +c.GenericOAuthenticator.scope = ["/authenticate", "openid"] |
| 93 | +``` |
| 94 | + |
| 95 | +The default `username_claim` of `sub` selects the ORCID iD from the JSON response as the individual's JupyterHub username. An example response is below: |
| 96 | + |
| 97 | +```json |
| 98 | +{ |
| 99 | + "sub": "0000-0002-2601-8132", |
| 100 | + "name": "Credit Name", |
| 101 | + "family_name": "Jones", |
| 102 | + "given_name": "Tom" |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +Please refer to the [Authorization Code Flow](https://github.com/ORCID/ORCID-Source/blob/main/orcid-web/ORCID_AUTH_WITH_OPENID_CONNECT.md#authorization-code-flow) section of the ORCID documentation for more information. |
| 107 | + |
| 108 | +(tutorials:provider-specific:generic:awscognito)= |
| 109 | +(tutorials:provider-specific:oidc:awscognito)= |
| 110 | + |
| 111 | +## Setup for AWS Cognito |
| 112 | + |
| 113 | +First visit AWS official documentation on [Getting started with user pools] for |
| 114 | +info on how to register and configure a cognito user pool and an associated |
| 115 | +OAuth2 application. |
| 116 | + |
| 117 | +[Getting started with user pools]: https://docs.aws.amazon.com/cognito/latest/developerguide/getting-started-user-pools.html |
| 118 | + |
| 119 | +Set the above settings in your `jupyterhub_config.py`: |
| 120 | + |
| 121 | +```python |
| 122 | +c.JupyterHub.authenticator_class = "oidc" |
| 123 | +c.OAuthenticator.oauth_callback_url = "https://[your-host]/hub/oauth_callback" |
| 124 | +c.OAuthenticator.client_id = "[your oauth2 application id]" |
| 125 | +c.OAuthenticator.client_secret = "[your oauth2 application secret]" |
| 126 | + |
| 127 | +c.OAuthenticator.login_service = "AWS Cognito" |
| 128 | +c.OAuthenticator.username_claim = "login" |
| 129 | +c.OIDCOAuthenticator.openid_provider_url = "https://your-AWSCognito-domain" |
| 130 | +``` |
0 commit comments