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

Support for subject- less tokens (client credential grant) #1

Open
bmcclory opened this issue Nov 5, 2021 · 2 comments
Open

Support for subject- less tokens (client credential grant) #1

bmcclory opened this issue Nov 5, 2021 · 2 comments

Comments

@bmcclory
Copy link

bmcclory commented Nov 5, 2021

Hello there! Thanks for creating this library. Question about:

context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Unable to parse subject claim - IdentityServer requires subject claim for extension grants");

I understand from the error message (and my own digging) that IdentityServer4 indeed makes it difficult to create a custom GrantValidationResult for a subject- less token. Its pipeline for attaching claims to tokens is primarily aimed at (human) users -- principals with a subject claim. The IProfileService, and the configured claims for scopes/resources, are only invoked for token requests with a subject.

By design, IdentityServer4 does not emit a subject claim for tokens issued via the client credentials grant. So out of the box, this library cannot exchange tokens that are issued from that flow.

Question: Is there any particular reason for this limitation -- i.e. some security reason why it wouldn't make sense to exchange "client" tokens in the same manner as "user" tokens? Would you accept a PR to add support for "client" token exchange?

@andrewclymer
Copy link

andrewclymer commented Nov 5, 2021 via email

@bmcclory
Copy link
Author

bmcclory commented Nov 5, 2021

Hi Andy, thanks for the quick reply.

In a microservices architecture with an API gateway, external clients should have restricted access: They can only obtain tokens for the "gateway" audience. The gateway would use its credentials to obtain tokens for the backend microservice audience(s).

Furthermore, IdentityServer4 allows applications to define "Client Claims", which by default are emitted in the token in "client credential" flow (or all flows when AlwaysSendClientClaims option is enabled). This is where Token Exchange becomes interesting: Rather than having the gateway simply request a new token as itself, we'd like any client claims associated with the original client to be preserved (reissued) in the new token.

From an audit / traceability standpoint, it'd also be interesting to see an act claim on issued tokens, to record the fact that "gateway" is acting on behalf of the original client.

On a related note, the idea of preserving client claims during Token Exchange might make sense in general, not just this client credential special case. This library (per specification?) already impersonates the original client (by using its client_id, and tucks the exchange requestors client ID into the act claim). Perhaps other claims associated with the original client (i.e. configured client claims) should be impersonated in the same way. We can override the UpdateRequest method in the TokenExchangeExtensionGrantValidator to achieve that behavior. But we can't overcome the limitation of "subject- less" tokens without replacing the entire validator with our own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants