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 30sAsymmetric key tokens (RS256 / ES256)
Section titled “Asymmetric key tokens (RS256 / ES256)”# Generate a key pair onceopenssl genrsa -out test-private.pem 2048openssl rsa -in test-private.pem -pubout -out test-public.pem
# Mint a tokenjwtop create --alg RS256 --key test-private.pem --sub user-42 --exp 1h
# Verify itjwtop verify $TOKEN --key test-public.pemIn 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 }}