Closed Extarys closed 5 years ago
@Extarys even I'm facing the same issue, apparently this lib doesn't support encryption of json/objects only simple string works.
@solancer thanks I feel less alone. In the mean time I switched to branca, way easier to implement. For now it will do the job:
function encodeToken(key, payload) {
const branca = require("branca")(key)
payload.tid = payload.tid ? payload.tid : uuid()
if (payload.exp) {
payload.exp = payload.iat + payload.exp * 60
} else {
payload.ext = 60 * 60 * 24 // Default 1 day
}
return branca.encode(notepack.encode(payload))
}
I use notepack
as it produce a shorter output and is the fastest library out there.
I will try notepack with paseto eventually but I don't see the need to rush.
I will try a string instead once I have a shorter to-do list :)
It does appear that encoder.encrypt accepts a string or buffer and doesn't automatically encode other types for you. I think this makes sense given PASETO's goal, which is to provide Platform-Agnostic Security Tokens. Adding stringification via JSON.stringify, notepack, etc. might be too opinionated for this project.
Can you confirm if replacing const token = await encoder.encrypt(message, sk)
with const token = await encoder.encrypt(JSON.stringify(message), sk)
resolves this issue? You can even use notepack there because encrypt() accepts a string or a buffer.
Thanks @neodon I cannot believe I fall for this and didn't think about providing a simple string. I guess I'm just used of using JSON for everything.
@Extarys - At the moment I don't have support for JSON encoding directly, but it is intended at some point. My time to maintain this library has fallen off to some minimum maintenance, but I'm hoping to find a window at some point to drop it in.
I understand. But now that we found why it wasn't working, it's quite easy to implement how we want to convert our object to a string on our end.
Thanks for the time you put into this library, I understand the time constraint.
I'm trying to generate a key and use that for the token, but everything below the
encrypt
method doesn't work."paseto.js": "^0.1.3",
Output:
It may just be me but I find it as difficult as JWT to use for now :laughing: