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
Terminal window
# Generate a key pair once
openssl genrsa -out test-private.pem 2048
openssl rsa -in test-private.pem -pubout -out test-public.pem
# Mint a token
jwtop create --alg RS256 --key test-private.pem --sub user-42 --exp 1h
# Verify it
jwtop verify $TOKEN --key test-public.pem
- 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"