1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JWT tokenをローカルでエンコードしたりデコードする

Last updated at Posted at 2025-07-10

概要

  • jwt tokenで認可するAPIがある
  • API使わず、さっとローカルにてエンコードでデコードしたいってなったときになんかないかなーって探したらあった
  • Node.jsで開発しているけど、Rustのほうを選択した
  • 環境はMacです

最初見つけたやつ

結構前

次見つけたやつ

よさそう

インストール

$ brew install mike-engel/jwt-cli/jwt-cli
$ brew link --overwrite jwt-cli # node.jsのやつ先にインストールしたので、パス入れ替えのため

使う

$ NOW=$(date +%s)
$ EXP=$((NOW + 86400))
$ SECRET="abcdefg"
$ jwt encode \
    --secret "abcdefg" \
    -A "HS256" "{\"hoge\":\"app\",\"auth_time\":$NOW}" \
    | jwt decode -

Token header
------------
{
  "typ": "JWT",
  "alg": "HS256"
}

Token claims
------------
{
  "auth_time": 1752181706,
  "hoge": "app",
  "iat": 1752189794
}

雑感

よかった

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?