-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
fix for passing Buffer object as secretOrPublicKey #47
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Can you please also add a test for this?
Added support for signing tokens with a Buffer object and relevant tests. Please let me know if that works. |
jwt.js
Outdated
@@ -53,15 +53,17 @@ function fastifyJwt (fastify, options, next) { | |||
signOptions && | |||
signOptions.algorithm && | |||
signOptions.algorithm.includes('RS') && | |||
typeof secret === 'string' | |||
(typeof secret === 'string' || | |||
Buffer.isBuffer(secret)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buffer.isBuffer(secret)) | |
secret instanceof Buffer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcollina why?
Co-Authored-By: lwojcik <1711174+lwojcik@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Buffer enables byte array to be used as a secret, including base64 encoding. On the readme of node-jsonwebtoken, search for "base64". This is an essential feature of Please review |
@mcollina I will patch this in if you are good to go |
go for it!
Il giorno ven 15 mar 2019 alle 08:14 Cemre Mengu <notifications@github.com>
ha scritto:
… @mcollina <https://github.com/mcollina> I will patch this in if you are
good to go
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#47 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADL4-Ghks6LlOrXlZNfOZ3rfYHJTqXaks5vW0hugaJpZM4bsFOt>
.
|
Hi!
While moving one of my projects from Express to Fastify I noticed
fastify-jwt
doesn't handleBuffer
objects passed asoptions.secret
in a correct way, causing JWT verification attempts to fail. I'm working with a Twitch.tv extension and it expects me to verify tokens with Buffer objects. I was able to do it withjsonwebtoken
andBuffer.from(...)
, butfastify-jwt
throwsError('missing private key and/or public key')
.I made a quick fix that causes the project to pass
Buffer
objects directly tosecretOrPublicKey
variable, making it possible to successfuly verify JWTs in cases like the one I described above.Alternatively,!Buffer.isBuffer(secret)
can also be used as a condition.