Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[All] Add userdata_from_id_token as alternative to userdata_url #725

Merged
merged 9 commits into from
Feb 13, 2024

Conversation

benjimin
Copy link
Contributor

@benjimin benjimin commented Feb 2, 2024

This PR adds support for extracting claims from the id token, instead of by exchanging the access token with the userinfo endpoint. Addresses #487.

This is needed because some claims may only be available via the id token and not via the userinfo endpoint, for example, AWS Cognito only provides the group membership claim via the id token (i.e., needed to complete support for #706).

For background, OAuth2 was a standard for obtaining an access token ("authorisation not authentication") and OIDC extended this in two ways: by standardising a userinfo endpoint and by accompanying the access token with an id token. (Note this is only the core of OIDC; complete OIDC support also entails discovery mechanisms, etc.) To date, oauthenticator has always discarded the id token that it receives, and relied on the userinfo endpoint for performing authentication.

This PR requires the feature to be explicitly enabled by the admin, without introducing any additional config attribs. It uses a library which is already used elsewhere by JupyterHub.

@minrk
Copy link
Member

minrk commented Feb 9, 2024

Thank you! I think this is very sensible. Perhaps config would be clearer if we used an explicit special value, like e.g. userdata_url = ".id_token", rather than encoding this behavior as None, or even userdata_from_id_token = True that takes precedence over userdata_url.

@minrk minrk added the new label Feb 9, 2024
@consideRatio
Copy link
Member

consideRatio commented Feb 9, 2024

I think userdata_from_id_token = true is a good choice here

Thank you! I think this is very sensible. Perhaps config would be clearer if we used an explicit special value, like e.g. userdata_url = ".id_token", rather than encoding this behavior as None, or even userdata_from_id_token = True that takes precedence over userdata_url.

I think having a dedicated toggle userdata_from_id_token = True would be good, it would provide us with a clear place to document this behavior and make it findable

@consideRatio
Copy link
Member

consideRatio commented Feb 9, 2024

Is pyjwr an optional dep for azuread ? Then we can clean it up there. If that optinal dependency is empty, let's then leave it empty and comment its no longer in use.

Also i think we should add a lower bound to pyjwts major version, so we depend on pyjwt>=2 because i recall migrating to v2 from v1 was needed elsewhere

@minrk
Copy link
Member

minrk commented Feb 9, 2024

Is pyjwt an optional dep for azuread?

it is, we can promote it to an unconditional dependency with the same bounds.

setup.py Show resolved Hide resolved
@manics
Copy link
Member

manics commented Feb 12, 2024

Do you think we could add a test for this to help with future maintenance?

benjimin and others added 5 commits February 13, 2024 05:57
Note, the current mock setup delivers different handlers (for ingesting
sample users) depending on whether id tokens are intended to be supplied.
The fixtures (for preparing a mock client and preconfigured authenticator)
thus need specialisation depending on whether the id token is being used.
However, the current mock also requires that tests individually manage the
packaging of the id token when loading into the mock client's handler;
the handler syntax is different between the two cases. This means that to
test that JWT id tokens and JSON userinfo endpoints provide equivalent
behaviour requires changes in both the test (in the preamble) and in
fixtures (compared to unmodified tests). This has led to some code
duplication, which would be a target for future refactoring.
needed for audience verification
@minrk minrk changed the title Add ID Token support Add userdata_from_id_token as alternative to userdata_url Feb 13, 2024
@minrk
Copy link
Member

minrk commented Feb 13, 2024

@benjimin thanks for the test!

@minrk minrk merged commit d7e0756 into jupyterhub:main Feb 13, 2024
9 checks passed
@benjimin
Copy link
Contributor Author

Thanks for the assist and support!

@consideRatio consideRatio changed the title Add userdata_from_id_token as alternative to userdata_url [All] Add userdata_from_id_token as alternative to userdata_url Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants