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

support notBefore and expiresIn as strings #364

Merged
merged 3 commits into from
Aug 10, 2023
Merged

Conversation

relvao
Copy link
Member

@relvao relvao commented Aug 10, 2023

Closes #363

uses https://github.com/lukeed/ms underneath

Had to adjust the tests, update the docs and implement the ms lib

@@ -27,9 +27,11 @@ Create a signer function by calling `createSigner` and providing one or more of

- `mutatePayload`: If set to `true`, the original payload will be modified in place (via `Object.assign`) by the signing function. This is useful if you need a raw reference to the payload after claims have been applied to it but before it has been encoded into a token. Default is `false`.

- `expiresIn`: Time span (in milliseconds) after which the token expires, added as the `exp` claim in the payload as defined by the [section 4.1.4 of RFC 7519](https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4). This will override any existing value in the claim.
- `expiresIn`: Time span (in milliseconds or text describing time) after which the token expires, added as the `exp` claim in the payload as defined by the [section 4.1.4 of RFC 7519](https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4). This will override any existing value in the claim.
Copy link
Member

Choose a reason for hiding this comment

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

rather, or in addition to providing explicit example, mention the library we use to parse the string format of the time. it's a popular library so mentioning that one is more explanatory than providing explicit examples

@@ -355,6 +355,20 @@ test('it respects payload exp claim (if supplied), overriding the default expire
t.end()
})

test('it supports expiresIn as a string', t => {
Copy link
Member

Choose a reason for hiding this comment

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

minor: use async tests so you don't have to remember to call t.end to end the test. simply making the test function async achieves that. I appreciate you are complying with the existing convention in this codebase, but I prefer we update it to the new syntax. t.end is only useful when doing assertions in callbacks, which is a niche use case

Copy link
Member

@simoneb simoneb left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@relvao relvao merged commit 18a90ac into master Aug 10, 2023
7 checks passed
@relvao relvao deleted the support_string_expiresIn branch August 10, 2023 16:02
@rubiin
Copy link
Contributor

rubiin commented Aug 10, 2023

Woah . That was quick 🔥

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.

Feature request: Support time in string format similar to jsonwebtoken
3 participants