Expose signer#193
Conversation
Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
|
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. |
|
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 <matteo.collina@gmail.com>
Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
Co-authored-by: Matteo Collina <matteo.collina@gmail.com>
|
Basically you need |
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
| exports.serialize = serialize | ||
| exports.signerFactory = signerFactory | ||
| exports.sign = sign | ||
| exports.unsign = unsign |
There was a problem hiding this comment.
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.
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.
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.
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. |

In this PR, I propose to re-export
signerFactory,signandunsignutilities to expand the capabilities of manual sign/unsign cookiesChecklist
npm run testandnpm run benchmarkand the Code of conduct