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

Use principal claims if the AT claims are unavailable #13

Open
jpda opened this issue Dec 10, 2024 · 0 comments
Open

Use principal claims if the AT claims are unavailable #13

jpda opened this issue Dec 10, 2024 · 0 comments

Comments

@jpda
Copy link

jpda commented Dec 10, 2024

We were using this before it was packaged into a library (thanks!) and now we're integrating this library and dropping most of the original code.

AccessTokenClaims on DPoPProofValidationContext is empty, causing the new lookup for cnf to fail in `ValidateHeader.'

The DPoPJwtBearerEvents.TokenValidated event is parsing the AT with a JsonWebTokenHandler, but we have encrypted JWTs which produces an empty array and causes the `DPoPValidation.

Since we are in the TokenValidated event, can we default to (or fall back to) the context's Principal claims? At that point the token has been decrypted and validated by the Jwt handler as we'd expect. Using context.Princpal.Claims works as expected, with the original claims from our AT.

Alternatively we could use handler.ValidateToken(TokenValidationParameters) but that would require us to re-configure our validation params to include the decryption key resolver, which seems duplicative.

I personally do not know of a reason why the context claims would be untrustworthy, particularly since handler.ReadJsonWebToken does no validation on the AT.

for example (from DPoPJwtBearerEvents.cs):

// TODO - Add support for introspection
var handler = new JsonWebTokenHandler();
var parsedToken = handler.ReadJsonWebToken(at);

var result = await _validator.Validate(new DPoPProofValidationContext
{
    Scheme = context.Scheme.Name,
    ProofToken = proofToken,
    AccessToken = at,
    // get the context claims here
    AccessTokenClaims = context.Principal?.Claims ?? parsedToken.Claims ?? [],
    Method = context.HttpContext.Request.Method,
    Url = context.HttpContext.Request.Scheme + "://" + context.HttpContext.Request.Host + context.HttpContext.Request.PathBase + context.HttpContext.Request.Path
});

thanks!

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

1 participant