Aller au contenu

Generate tokens for testing

Ce contenu n’est pas encore disponible dans votre langue.

jwtop create lets you mint arbitrary JWTs from the command line — no server or auth infrastructure required. This is useful for seeding integration tests, populating CI environment variables, or reproducing production scenarios locally.

Terminal window
jwtop create --alg HS256 --secret testsecret \
--sub user-42 --iss myapp --exp 1h --iat

Capture the output in a variable:

Terminal window
export TEST_TOKEN=$(jwtop create --alg HS256 --secret testsecret \
--sub user-42 --exp 1h --iat)

Use --claim key=value (repeatable) to add any payload field:

Terminal window
jwtop create --alg HS256 --secret testsecret \
--sub user-42 \
--claim role=admin \
--claim plan=pro \
--claim verified=true \
--claim account_id=9001

Values are auto-parsed: 9001 becomes an integer, true becomes a boolean, everything else stays a string.

Terminal window
# Expires in 30 seconds — useful for testing expiry handling
jwtop create --alg HS256 --secret testsecret --sub user-1 --exp 30s

jwtop genkey produces key material with enforced minimum-strength parameters (RSA ≥ 2048 bits, HMAC secret ≥ the MAC output size, crypto/rand only):

Terminal window
# Random HS256 secret for a test suite
export TEST_SECRET=$(jwtop genkey --alg HS256)
# RSA key pair on disk: test-private.pem (0600) + test-private.pem.pub (0644)
jwtop genkey --alg RS256 --out test-private.pem

See the genkey reference for every flag.

Terminal window
# Generate a key pair once
jwtop genkey --alg RS256 --out test-private.pem
# (or: openssl genrsa -out test-private.pem 2048 && openssl rsa -in test-private.pem -pubout -out test-private.pem.pub)
# Mint a token
jwtop create --alg RS256 --key test-private.pem --sub user-42 --exp 1h
# Verify it
jwtop verify $TOKEN --key test-private.pem.pub
- name: Generate test JWT
uses: cerberauth/jwtop-action@v1
id: jwt
with:
args: create --alg HS256 --secret ${{ secrets.TEST_SECRET }} --sub ci-user --exp 1h
- name: Export token
run: echo "TEST_TOKEN=${{ steps.jwt.outputs.result }}" >> "$GITHUB_ENV"