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

Update auth-helper libs and improve lib usability #50

Merged

Conversation

DaughterOfMars
Copy link

Currently, the auth-helper crate does not expose enough of the underlying jsonwebtoken lib (it should just re-export, as it is meant to be used in place of jsonwebtoken), and some of the functionality is too restrictive. The ClaimsBuilder pattern is entirely unnecessary, and it is more useful to simply have full access to the Claims fields. Similarly, the JsonWebToken should expose the inner string.

Additionally, I have added a sealed trait (BuildValidation) to allow builder-lite functionality for the Validation struct, and accept that struct rather than a restrictive set of claims in the JsonWebToken::validate method.

jwt.validate(
    Validation::default()
        .with_issuer("issuer")
        .with_audience("audience")
        .with_subject("subject")
        .validate_nbf(true),
    b"secret"
)

Furthermore, I have removed the possibility for a panic when creating Claims due to SystemTime::duration_since, as the appropriate way to handle that is simply to default the duration (not that it should be possible for this to fail).

Lastly, prior to the changes there was no way to avoid validating the Subject field. However, this should be optional (as with the other fields), particularly because stateless interactions do not allow servers to maintain this information or validate it.

auth-helper/Cargo.toml Show resolved Hide resolved
auth-helper/src/jwt.rs Outdated Show resolved Hide resolved
auth-helper/src/jwt.rs Outdated Show resolved Hide resolved
auth-helper/src/jwt.rs Show resolved Hide resolved
auth-helper/src/jwt.rs Outdated Show resolved Hide resolved
… more helper fns to claims. Fix issued at field in error.
Alex6323
Alex6323 previously approved these changes Jun 9, 2022
@thibault-martinez thibault-martinez merged commit 1e9e258 into iotaledger:main Jun 20, 2022
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

4 participants