Skip to content

Make set_issuer and set_audience require aud, iss claims#520

Open
mikkel3000 wants to merge 2 commits into
Keats:masterfrom
mikkel3000:feature/493-set_spec_claims
Open

Make set_issuer and set_audience require aud, iss claims#520
mikkel3000 wants to merge 2 commits into
Keats:masterfrom
mikkel3000:feature/493-set_spec_claims

Conversation

@mikkel3000

Copy link
Copy Markdown

Addresses #493

set_audience and set_issuer convenience functions now adds aud and iss to required_spec_claims.

@mikkel3000 mikkel3000 force-pushed the feature/493-set_spec_claims branch from e73b62c to a5a4aab Compare June 18, 2026 16:52
@arckoor arckoor self-requested a review June 18, 2026 17:13

@arckoor arckoor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should be fine, without some more doc on set_required_spec_claims opens up the door for another footgun because that method unconditionally overwrites everything, it's not additive.
The entire interface is imo weirdly split between using methods on Validation, and setting some attributes directly. Thoughts @Keats?

Comment thread src/validation.rs Outdated
Comment on lines -856 to -821
validation.set_required_spec_claims(&["exp", "iss"]);
validation.leeway = 5;
validation.set_issuer(&["iss no check"]);
validation.set_audience(&["iss no check"]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could be augmented by not adding "iss" manually
Though then you can just remove the entire set_required_spec_claims

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Okay, updated the PR.

@Keats

Keats commented Jun 20, 2026

Copy link
Copy Markdown
Owner

The entire interface is imo weirdly split between using methods on Validation, and setting some attributes directly. Thoughts @Keats?

The API of the Validation struct is a bit confusing IMO (and has been adding things without too much thought put into it) and was always something I wanted to redo but never spent time on. It would be good to see what something designed from scratch for all the current features would look like.

Addresses Keats#493

set_audience and set_issuer convenience functions now adds `aud` and `iss` to `required_spec_claims`.
@mikkel3000 mikkel3000 force-pushed the feature/493-set_spec_claims branch from a5a4aab to 6f4a9d5 Compare June 21, 2026 07:19
@mikkel3000

Copy link
Copy Markdown
Author

The entire interface is imo weirdly split between using methods on Validation, and setting some attributes directly. Thoughts @Keats?

The API of the Validation struct is a bit confusing IMO (and has been adding things without too much thought put into it) and was always something I wanted to redo but never spent time on. It would be good to see what something designed from scratch for all the current features would look like.

Does that mean you do not want to use this change, and wait for a larger refactor of the validation API?
I agree that the API is confusing, but i think a proper re-implementation would (and should) bring multiple breaking changes.

@Keats

Keats commented Jun 22, 2026

Copy link
Copy Markdown
Owner

I agree that the API is confusing, but i think a proper re-implementation would (and should) bring multiple breaking changes.

There is a new major version coming so it would be fine.
I won't have time to implement it myself but would happily review it if someone else does it.

@arckoor

arckoor commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

I'd like to try and get v11 out this month if possible, as it contains changes that others have been waiting for for quite a while
I'll try to get something ready in the next few days for this (anyone else is welcome as well if you're faster than me), but if it doesn't happen in this version it should also be fine, I'm considering another breaking version to address the whole EncodingKey::from_der situation, which the validation rewrite could then also be a part of

@mikkel3000

Copy link
Copy Markdown
Author

I'd like to try and get v11 out this month if possible, as it contains changes that others have been waiting for for quite a while I'll try to get something ready in the next few days for this (anyone else is welcome as well if you're faster than me), but if it doesn't happen in this version it should also be fine, I'm considering another breaking version to address the whole EncodingKey::from_der situation, which the validation rewrite could then also be a part of

I will have a go at it and update this PR soon 👍

The previous api mixed convencience methods and direct setting of attributes, which made some functionality confusing.
This refactor only allows building the Validation using methods, trying to make it hard for the user to go wrong.
It removes the opportunity of setting issuer or audience without requiring their existence.
It also removes audience as a required claim, the user should call .with_audience method instead.
This commit is still a WIP, places which needs further work or documentation are marked // TODO:

This is a breaking change.
@mikkel3000

Copy link
Copy Markdown
Author

I'd like to try and get v11 out this month if possible, as it contains changes that others have been waiting for for quite a while I'll try to get something ready in the next few days for this (anyone else is welcome as well if you're faster than me), but if it doesn't happen in this version it should also be fine, I'm considering another breaking version to address the whole EncodingKey::from_der situation, which the validation rewrite could then also be a part of

I have made a suggested API change, there is still polishing and documentation to be done, but the methods are mostly finished.
If you like this style and want me to continue this implementation, I will happily do that.

@arckoor

arckoor commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

From a quick glance direction seems fine, but I'm not sure about the builder style
I do like it and it makes sense using it for most things, but imo it encourages inline construction, while Validation is (like EncodingKey and DecodingKey) meant to be constructed once and then reused (the hashsets make it sort of expensive to repeatedly construct)
Offering a less inline friendly api by taking &mut self like the previous version did might push people in the right direction

@arckoor arckoor requested review from Keats and Copilot June 22, 2026 22:45
@arckoor arckoor removed the request for review from Copilot June 22, 2026 22:46
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

Successfully merging this pull request may close these issues.

3 participants