-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Expose signer #193
Expose signer #193
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.
I think it might be more idiomatic to expose it as app.signCookie
as well, similar to how unsignCookie
is defined in
Line 61 in dffa0ea
fastify.decorate('unsignCookie', unsignCookie) |
Wdyt?
Co-authored-by: Matteo Collina <[email protected]>
In this case, it seems to me, there will be 2 problems
As for me the main problem is naming in this case How do you suggest it looks like? |
I'm essentially ok with this change, so we can land this. |
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
In principle, |
Given we already have Lines 60 to 61 in dffa0ea
|
in this case, how should the |
I think there is already |
I want to clarify: in our project, some cookies are also signed/unsigned with so called "dynamic secret" - user specific info, so now we use Therefore, if we add that's what I was talking about - the conflict of names... |
How are you passing these through? I don't know how somebody could do dynamic/user specific cookie signatures with this module. Have you got a reduced example for this? How about adding a test with the full usage you are envisioning those new exposed functions? This plugin's most basic use case has one (or more) secrets for all users. In this case providing |
I think these are private cases of our architects and they are not widely used, so I agree
After I added the fastify.decorate('signCookie', signCookie) ran into a problem in the test test('create signed cookie manually using signCookie decorator', (t) => {
const fastify = Fastify()
fastify.register(plugin, { secret: 'secret' })
fastify.get('/test1', (req, reply) => {
reply.send({
unsigned: req.unsignCookie(req.cookies.foo)
})
})
fastify.inject({
method: 'GET',
url: '/test1',
headers: { cookie: `foo=${fastify.signCookie('bar')}` }
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 200)
t.same(JSON.parse(res.body), { unsigned: { value: 'bar', renew: false, valid: false } })
})
})
|
What stacktrace are you getting? |
I don't see that exposed anywhere. |
I can not push the code changes due to failed tests |
|
Co-authored-by: Matteo Collina <[email protected]>
Co-authored-by: Matteo Collina <[email protected]>
Co-authored-by: Matteo Collina <[email protected]>
Basically you need |
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
I got it - I relied on the style and code of existing tests, was surprised, but copied the code as it is) |
cookie.js
Outdated
/** | ||
* Module exports. | ||
* @public | ||
*/ | ||
|
||
exports.parse = parse | ||
exports.serialize = serialize | ||
exports.signerFactory = signerFactory | ||
exports.sign = sign | ||
exports.unsign = unsign |
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.
I landed #194 and now this conflicts. Coul you move these exports to the plugin.js
file instead?
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.
Ок
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.
How then should the import of utilities look like?
const cookie = require('@fastify/cookie');
const { signerFactory , sign, unsign } = cookie;
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.
that works
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.
Do I understand correctly that exporting to plugin.js should it look like this?
/**
* These export configurations enable JS and TS developers
* to consume fastify-cookie in whatever way best suits their needs.
* Some examples of supported import syntax includes:
* - `const fastifyCookie = require('fastify-cookie')`
* - `const { fastifyCookie } = require('fastify-cookie')`
* - `import * as fastifyCookie from 'fastify-cookie'`
* - `import { fastifyCookie } from 'fastify-cookie'`
* - `import fastifyCookie from 'fastify-cookie'`
*/
fastifyCookie.fastifyCookie = fastifyCookie
fastifyCookie.default = fastifyCookie
module.exports = fastifyCookie
fastifyCookie.fastifyCookie.signerFactory = signerFactory;
fastifyCookie.fastifyCookie.sign = sign;
fastifyCookie.fastifyCookie.unsign = unsign;
module.exports.signerFactory = signerFactory;
module.exports.sign = sign;
module.exports.unsign = unsign;
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.
Either
fastifyCookie.signerFactory = signerFactory;
fastifyCookie.sign = sign;
fastifyCookie.unsign = unsign;
or
plugin.signerFactory = signerFactory;
plugin.sign = sign;
plugin.unsign = unsign;
Can we actually integrate cookie-signer into our codebase? I mean the code is trivial. Also why do they replace the characters when signing? |
We could theoretically also allow to set the algorithms of the signer, if we integrate it into this package |
I believe they are stripping |
But |
It will works with or without the If you believe it is wrong, I suggest you to open a issue in their repo for clarification. |
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
In this PR, I propose to re-export
signerFactory
,sign
andunsign
utilities to expand the capabilities of manual sign/unsign cookiesChecklist
npm run test
andnpm run benchmark
and the Code of conduct