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.
Quick token for a test suite
Section titled “Quick token for a test suite”jwtop create --alg HS256 --secret testsecret \ --sub user-42 --iss myapp --exp 1h --iatCapture the output in a variable:
export TEST_TOKEN=$(jwtop create --alg HS256 --secret testsecret \ --sub user-42 --exp 1h --iat)Token with custom claims
Section titled “Token with custom claims”Use --claim key=value (repeatable) to add any payload field:
jwtop create --alg HS256 --secret testsecret \ --sub user-42 \ --claim role=admin \ --claim plan=pro \ --claim verified=true \ --claim account_id=9001Values are auto-parsed: 9001 becomes an integer, true becomes a boolean, everything else stays a string.
Short-lived tokens (expiry testing)
Section titled “Short-lived tokens (expiry testing)”# Expires in 30 seconds — useful for testing expiry handlingjwtop create --alg HS256 --secret testsecret --sub user-1 --exp 30sGenerate a signing key or secret
Section titled “Generate a signing key or secret”jwtop genkey produces key material with enforced minimum-strength parameters
(RSA ≥ 2048 bits, HMAC secret ≥ the MAC output size, crypto/rand only):
# Random HS256 secret for a test suiteexport 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.pemSee the genkey reference for every flag.
Asymmetric key tokens (RS256 / ES256)
Section titled “Asymmetric key tokens (RS256 / ES256)”# Generate a key pair oncejwtop 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 tokenjwtop create --alg RS256 --key test-private.pem --sub user-42 --exp 1h
# Verify itjwtop verify $TOKEN --key test-private.pem.pubIn GitHub Actions
Section titled “In GitHub Actions”- 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"- name: Install jwtop run: go install github.com/cerberauth/jwtop@latest
- name: Generate test JWT run: | TOKEN=$(jwtop create --alg HS256 \ --secret "$TEST_SECRET" \ --sub ci-user --exp 1h) echo "TEST_TOKEN=$TOKEN" >> "$GITHUB_ENV" env: TEST_SECRET: ${{ secrets.TEST_SECRET }}