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

Make family public #351

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Make family public #351

wants to merge 3 commits into from

Conversation

brymko
Copy link

@brymko brymko commented Dec 11, 2023

A patch to hopefully fix all the AlgorithmFamily confusion. We ran into a very similar issue which i think are many describing here. But i noticed that we specifically like to pin the validation of the jwt to the decoding/encoding key that is being used. But unfortunately this is currently not possible without adding more state tracking for our keys, which is annoying given that they already store this information.

This patch will publicize a method to get the AlgorithmFamily from both encoding & decoding key. And also adds a method to AlgorithmFamily that will return a list of all algorithms which are part of the family

@Keats
Copy link
Owner

Keats commented Dec 11, 2023

Can you add a snippet of how you would use that?

@brymko
Copy link
Author

brymko commented Dec 11, 2023

We're using the following primitives to setup correct validation and encoding parameters based on the key given:

fn validation_from_decoding_key(key: &jsonwebtoken::DecodingKey) -> jsonwebtoken::Validation {
    let mut ret = jsonwebtoken::Validation::default();

    ret.algorithms = key.family().algorithms().to_vec();

    ret
}

fn header_from_encoding_key(key: &jsonwebtoken::EncodingKey) -> jsonwebtoken::Header {
    jsonwebtoken::Header {
        alg: *key
            .family()
            .algorithms()
            .first()
            .expect("No algorithms found there must be atleast one algorithm per family"),
        ..jsonwebtoken::Header::default()
    }
}

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.

None yet

2 participants