mike-engel / jwt-cli

A super fast CLI tool to decode and encode JWTs built in Rust
MIT License
1.08k stars 65 forks source link

encode always errors with "Invalid JSON provided!" on 6.0.0 #290

Closed morremeyer closed 1 year ago

morremeyer commented 1 year ago

Summary

When I try to set an expiration for a token in 6.0.0, it always errors with

❯ jwt encode --secret "@${GITHUB_APP_SECRET_PATH}" -e "+60 sec" -i "${GITHUB_APP_ID}" --alg RS256
thread 'main' panicked at 'Invalid JSON provided!', src/translators/encode.rs:122:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This is on macOS Ventura 13.5.2

Steps to reproduce

Have a valid pem file on your machine. Then, run

export SECRET_PATH="path_to_your_file"

jwt encode --secret "@${SECRET_PATH}" -e "+60 sec" -i "0123456789" --alg RS256
jwt encode --secret "@${SECRET_PATH}" -e "60" -i "0123456789" --alg RS256

and see that both output

thread 'main' panicked at 'Invalid JSON provided!', src/translators/encode.rs:122:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

However,

jwt encode --secret "@${SECRET_PATH}" -i "0123456789" --alg RS256

will work.

Expected behavior

Setting an expiration should work.

AlexSeefeldt commented 1 year ago

Hi @morremeyer, I had this same issue, and I think I know what the problem is. The -e option requires an equal sign rather than whitespace between the option and the argument (e.g. -e="+60 sec"), so your examples should look like this:

jwt encode --secret "@${SECRET_PATH}" -e="+60 sec" -i "0123456789" --alg RS256
jwt encode --secret "@${SECRET_PATH}" -e="60" -i "0123456789" --alg RS256

Hope this helps.

mike-engel commented 1 year ago

Thanks @AlexSeefeldt. This was an ugly side-effect of the update from clap 3 to 4 and the way that expires argument works. It may be able to change back in the future. It's documented in the help output, but it's not incredibly helpful