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

feat: Replacing jsonwebtoken with fast-jwt #184

Merged
merged 29 commits into from
Nov 25, 2021
Merged

Conversation

radomird
Copy link
Contributor

@radomird radomird commented Oct 19, 2021

Replacing the jsonwebtoken with more performant fast-jwt library.

Since options for fast-jwt are somewhat different, I will update the options exposed through fastify-jwt.

Important note: This is a BREAKING CHANGE, so after this PR is approved and merged, a new major version of the plugin will be released.

Closes #174
Closes #166

Update 10-11-2021: fast-jwt has been updated to support password protected private keys, This PR includes those changes as well.

Checklist

@radomird radomird marked this pull request as ready for review October 25, 2021 14:43
jwt.d.ts Outdated Show resolved Hide resolved
test/test.test.js Outdated Show resolved Hide resolved
jwt.js Outdated Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Important note: fast-jwt DOES NOT support passphrase protected private keys yet! For this reason the test cases covering this scenario were (temporarily) commented out.

This needs to be fixed before landing

@radomird
Copy link
Contributor Author

radomird commented Oct 26, 2021

Opened an issue in fast-jwt about the passphrase protected private keys support.
nearform/fast-jwt#116

@radomird radomird requested a review from climba03003 October 26, 2021 10:53
jwt.js Show resolved Hide resolved
@jsumners
Copy link
Member

@mcollina is there anything specific you would like me to review here? I am not familiar with this module. Cursorily, you have already covered what I would say: it needs 1:1 feature parity before it can be accepted.

@simoneb
Copy link
Contributor

simoneb commented Oct 26, 2021

@mcollina @jsumners yes this is being worked on, feature parity will first need a change in fast-jwt to support password protected private keys, which are currently not supported. See nearform/fast-jwt#117.

Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

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

LGTM. We wait for nearform/fast-jwt#117 before landing.

Copy link
Member

@darkgl0w darkgl0w left a comment

Choose a reason for hiding this comment

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

LGTM !

Some suggestions:

  • We should take the opportunity offered by this PR to rework the file structure of the plugin and move jwt.test-d.ts to test/types/jwt.test-d.ts, rename test/test.test.js to test/jwt.test.js and update the corresponding references in package.json file.
  • Update to require at least fastify >= 3.0.0 (currently it requires fastify >= 3.0.0-alpha-1) in jwt.js file module export.
  • We should add an explicit warning in the README.md stating that we migrated from jsonwebtoken to fast-jwt and that it may break "exotic" implementations even though it is a 1:1 feature implementation.

NB: this PR superseeds and closes #166 too.

test/test.test.js Outdated Show resolved Hide resolved
test/test.test.js Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

Overall LGTM, a couple of inline comments (some may be outdated as it took me a while to review this and you may have addressed some of them already).

One main question: shall we write a short migration guide so users know what to change when upgrading?

README.md Outdated Show resolved Hide resolved
jwt.d.ts Show resolved Hide resolved
@@ -1,5 +1,5 @@
import { DecoderOptions, KeyFetcher, SignerCallback, SignerOptions, VerifierCallback, VerifierOptions } from 'fast-jwt'
Copy link
Contributor

Choose a reason for hiding this comment

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

given the many changes in typings, let's make sure we are running typing checks in CI and that we have tests in place for typing

jwt.test-d.ts Outdated Show resolved Hide resolved
Copy link
Member

@darkgl0w darkgl0w left a comment

Choose a reason for hiding this comment

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

Added some changes suggestions to types. (mostly string time span related)

jwt.test-d.ts Outdated Show resolved Hide resolved
jwt.test-d.ts Outdated Show resolved Hide resolved
jwt.d.ts Outdated Show resolved Hide resolved
jwt.d.ts Outdated Show resolved Hide resolved
jwt.d.ts Outdated Show resolved Hide resolved
jwt.d.ts Outdated Show resolved Hide resolved
jwt.d.ts Outdated Show resolved Hide resolved
jwt.d.ts Outdated Show resolved Hide resolved
jwt.d.ts Outdated Show resolved Hide resolved
jwt.d.ts Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

README.md Show resolved Hide resolved
@mcollina
Copy link
Member

You might want to run some benchmarks using wrk or autocannon.

radomird and others added 2 commits November 18, 2021 10:11
Added new types for Sign and Verify Options, updated typings test

Co-authored-by: darkgl0w <31093081+darkgl0w@users.noreply.github.com>
@radomird
Copy link
Contributor Author

radomird commented Nov 18, 2021

I think we are good to go. After the workflow is approved and the tests are green - the PR can be merged.

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

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

LGTM, just a suggestion on the readme

README.md Outdated Show resolved Hide resolved
@simoneb
Copy link
Contributor

simoneb commented Nov 19, 2021

LGTM, just a suggestion on the readme

Yes absolutely, I suggested the same. We should have a section in the readme or other sensible place and link it from the release notes

@radomird
Copy link
Contributor Author

@Eomm @simoneb & @darkgl0w I've updated the README with breaking changes and also all of the examples in the README have been updated to use the new option names.

Copy link
Member

@darkgl0w darkgl0w left a comment

Choose a reason for hiding this comment

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

Seems good to me ^^
I have left a few nits

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
radomird and others added 3 commits November 19, 2021 15:00
Co-authored-by: darkgl0w <31093081+darkgl0w@users.noreply.github.com>
Co-authored-by: darkgl0w <31093081+darkgl0w@users.noreply.github.com>
Copy link
Member

@darkgl0w darkgl0w left a comment

Choose a reason for hiding this comment

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

That's way better with a separate file 👍

UPGRADING.md Outdated Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Could you add a bit of a migration guide at the top of the README?

There are a few API changes here

@simoneb
Copy link
Contributor

simoneb commented Nov 21, 2021

Could you add a bit of a migration guide at the top of the README?

There are a few API changes here

There's an UPGRADING.md doc added in this PR

UPGRADING.md Show resolved Hide resolved
Co-authored-by: darkgl0w <31093081+darkgl0w@users.noreply.github.com>
@radomird
Copy link
Contributor Author

Folks, I think the PR is, finally, ready to be merged. If some small issues arise after the release, we will address them separately.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@radomird
Copy link
Contributor Author

Can anyone with write access merge the PR? I don't have sufficient access level to do this 😄
@mcollina

Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

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

No blocking for me. LGTM.

@Uzlopak
Copy link
Contributor

Uzlopak commented Nov 24, 2021

Neat!

I assume that @lukeed will be happy to read that his package will be used in a this fastify-plugin. (Pinging him on purpose ;) )

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit c3a30aa into fastify:master Nov 25, 2021
@lukeed
Copy link

lukeed commented Nov 25, 2021

Nice! :) thanks for the ping

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.

Should this plugin use fast-jwt?