📦 Tkn
Tkn is a cli tool that creates signed
JSON Web Tokens from a JSON
or YAML
description.
The JWT can be signed via secret or RSA key and with different
algorithms.
The following algorithms are supported:
- HS256
- HS384
- HS512
- RS256
- RS384
- RS512
- PS256
- PS384
- PS512
💾 Install
go install github.com/abecodes/tkn@latest
💻 Example
A JWT can be described via JSON
:
{
"headers": { "KID": "01SwHRh9DRhSevAE" },
"payload": {
"iss": "admin",
"sub": "1337",
"exp": 16459032010,
"iat": 1645903201,
"Roles": ["ADMIN", "USER"],
"Test": ["another", "array", "here"],
"hello": "world"
}
}
or YAML
:
headers:
KID: 01SwHRh9DRhSevAE
payload:
iss: admin
sub: '1337'
exp: 16459032010
iat: 1645903201
Roles:
- ADMIN
- USER
Test:
- another
- array
- here
hello: world
Signing with a secret
tkn -token token.json -secret '6w9z$C&F)J@NcRfTjWnZr4u7x!A%D*G-' -alg hs256
Signing with a RSA key
tkn -t token.yaml -k path/to/keyfile.pem -a rs256
Output
Tkn will print the generated token as well as secret or public key that
can be used to verify its integrity.
-----BEGIN JWT TOKEN-----
eyJLSUQiOiIwMVN3SFJoOURSaFNldkFFIiwiYWxnIjoiSFMyNTYiLCJ0eXAiOiJKV1QiLCJ5b2xvIjoxMjN9.eyJSb2xlcyI6WyJBRE1JTiIsIlVTRVIiXSwiVGVzdCI6WyJhbm90aGVyIiwiYXJyYXkiLCJoZXJlIl0sImV4cCI6MTY0NTkwMzIwMTAsImhlbGxvIjoid29ybGQiLCJpYXQiOjE2NDU5MDMyMDEsImlzcyI6ImFkbWluIiwic3ViIjoiMTMzNyJ9.thTxEWqPozH2WWmiBaVvHIi4tTTAYDBbt4GA3nhhzKY
-----END JWT TOKEN-----
-----BEGIN SECRET-----
6w9z$C&F)J@NcRfTjWnZr4u7x!A%D*G-
-----END SECRET-----
📋 Options
Parameter |
Description |
Default |
-a -alg |
algorithm used to sign the token |
RS256 |
-k -key |
path to a RSA private key |
null |
-s -secret |
secret used to sign the token |
null |
-t -token |
path to a JSON/YAML description of the token |
./token.yaml |