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

can create but not validate a JWT with a non-object payload #83

Closed
hankatola opened this issue Sep 26, 2023 · 3 comments
Closed

can create but not validate a JWT with a non-object payload #83

hankatola opened this issue Sep 26, 2023 · 3 comments

Comments

@hankatola
Copy link

[email protected] djwt/mod.ts,  the validate function throws an error when the payload argument in the JWT that has been created with the create function is a string instead of a generic object, i.e.

const jwt = await create(header, "foo", key) // works
const verifiedJWT = await verify(jwt, key) // throws error "The jwt claims set is not a JSON object" from line 186

In order to prevent both further confusion and invalid jwts from being created, if the payload argument must be an object, the error should be thrown in the create function, i.e.

const jwt2 = await create(header, {msg: "foo"}, key) // should (and does) work
const jwt3 = await create(header, "foo", key) // should throw error `The jwt payload is not an object`

If payload argument is not required to be a generic object (i.e. strings/numbers/etc... should be acceptable), then the validate function needs to be adjusted.

@timonson
Copy link
Member

timonson commented Nov 4, 2023

Hi @hankatola ,

are you using JavaScript or TypeScript?

In TS I am getting this error:

error: TS2345 [ERROR]: Argument of type 'string' is not assignable to parameter of type 'Payload'.
console.log(await create(header, "foo", key));

But I agree that it should throw in JS, as well.

@hankatola
Copy link
Author

JavaScript

@timonson
Copy link
Member

timonson commented Nov 5, 2023

Thank you @hankatola ,

I fixed your issue with #84 .

Please let me know if you have further issues, especially with JavaScript.

@timonson timonson closed this as completed Nov 5, 2023
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

No branches or pull requests

2 participants