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

Discover access token audiences #17469

Open
wants to merge 2 commits into
base: save-oidc-tokens-to-open-project-database
Choose a base branch
from

Conversation

NobodysNightmare
Copy link
Contributor

@NobodysNightmare NobodysNightmare commented Dec 16, 2024

Ticket

https://community.openproject.org/projects/cross-application-user-integration-stream/work_packages/60162

What are you trying to accomplish?

This PR is an extension of previous work in #16940. We want to be able to use tokens stored in the corresponding database model for access to third party services, such as Nextcloud.

There are different ways that we can use these existing tokens for that. The case handled in this PR is that the token might already be immediately usable for use in certain services, which we can discover from the token's audience.

What approach did you choose and why?

We are expecting the access token to be a JWT that we can parse and verify using the metadata we have configured for the corresponding OIDC provider. While there is no guarantee that access tokens can be parsed as JWTs, it's very common to find when dealing with an OIDC IDP, since those are required to provide their ID tokens as JWTs, so the "infrastructure" for signing JWTs exists anyways.

To perform the parsing I extracted previously existing code from the JwtOidc warden strategy into a new parser service and adapted it to the common needs of the warden strategy and our new code.

Merge checklist

  • Added/updated tests
    • For JWT parsing
    • For audience discovery
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@NobodysNightmare NobodysNightmare changed the title Discover audiences Discover access token audiences Dec 16, 2024
@NobodysNightmare NobodysNightmare force-pushed the discover-audiences branch 3 times, most recently from d31e204 to efc65c8 Compare December 16, 2024 13:40
# +

module OpenIDConnect
class ProviderTokenParser
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am starting to become unhappy about names.

I called the UserToken like that, because it's a token that grants access in the name of the user.

I called the ProviderTokenParser like that, because it only allows proper parsing of JWTs that were issued by a configured provider (they are not parseable without knowing the provider).

But now looking at both names next to each other, it doesn't seem to make sense, because there are no tokens to do stuff in the name of a provider. It seems counter intuitive, that the ProviderTokenParser would parse a UserToken and yet that's what it does...

@NobodysNightmare NobodysNightmare force-pushed the discover-audiences branch 2 times, most recently from d4c2af6 to 178b622 Compare December 17, 2024 08:19
@NobodysNightmare NobodysNightmare requested a review from a team December 17, 2024 09:07
@NobodysNightmare NobodysNightmare force-pushed the save-oidc-tokens-to-open-project-database branch from 1ab8a1c to 06f4d7d Compare December 18, 2024 07:56
JWT parsing is rather involved, because we need to fetch
proper certificates first. We will need to parse JWTs in
a different context than authorization as well,
so it makes sense to have the parsing centralized.

This also allowed to add specs for this previously
not (unit) tested piece of code.
We want to know for which purposes tokens can
be used. Assuming that we receive JWTs as access tokens,
it's possible to read their audience and thus check
where these tokens are usable.

Importantly, it's still possible that an access token
is not a JWT, so we have to allow that as well. The
code could be extended in the future to send such tokens
to the introspection endpoint of the IDP, hoping to receive
an audience list as a result of that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant