instructure / paseto

A paseto implementation in rust.
MIT License
151 stars 14 forks source link

Proposed additions to the builder implementation to make adding claims more flexible... #45

Closed rrrodzilla closed 2 years ago

rrrodzilla commented 2 years ago

Motivation (required)

What existing problem does the pull request solve?

Hi, thanks for this great Paseto implementation. One issue which frustrated me when using the builder is that I need to add additional claims one at a time using the set_claim method. This requires each individual specific claim to be known when using the builder to assemble a token. In order to make my code as reusable as possible, and potentially buried within a crate or bin of its own, I need to be able to dynamically inject an arbitrary list of claims I want to include from elsewhere. To do so, I've added two new methods to use either in place of or in conjunction with the set_claim method. The first simply pluralizes the method and is called set_claims and receives as an input a HashMap of Values to extend the existing internal extra_claims attribute of the builder. the std::iter::Extend trait is used to merge the values into the existing HashMap. The second method is named set_claims_by_closure and does the same as the set_claims method however instead of receiving a HashMap as an input to extend, it receives a closure which returns a HashMap and is then used to extend the internal HashMap.

Test Plan (required)

I"ve added a test for each method: 1can_construct_a_token_chrono_with_claims_closure() 1can_construct_a_token_chrono_with_claims_hashmap() For each, I've essentially just copied the can_construct_a_token_chrono() test and updated how the claims are created and set, and then verified they existed after the token was decrypted.

All tests currently pass.

Thanks for your consideration.

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.