openidconnect-rs icon indicating copy to clipboard operation
openidconnect-rs copied to clipboard

Access to raw claims without a struct?

Open colemickens opened this issue 8 months ago • 1 comments

Hi,

This might be an odd request, and it seems a bit at odd with this library's focus on safety and type-d-ness.

But, I'd like to be able to arbitrarily validate/verify JWTs and then access the claims as a raw serde_json::Value.

For context, we have an endpoint that:

  • accepts arbitary JWTs
  • looks at their iss to see if it's an allow-listed issuer
  • uses this library to validate the JWT
  • we pass the "raw claims" into a CEL engine and evaluate some expressions based on the issuer_uri

In this scenario, it's not really possible to pre-specify the shape of claims as a Rust struct.

I've done something a bit distasteful by splitting the JWT, decoding the inner chunk, saving it, and then using the library to validate the JWT as normal. And if that's successful, then using the raw claims I've saved myself.

It would be nice to leverage the type/safety-ish bits of this library but still be able to extract the "raw" claims as a Value from the validated type.

What do you think? Am I missing an obvious API that already allows this?

colemickens avatar Apr 01 '25 14:04 colemickens