- Go 85.9%
- HTML 13.6%
- Dockerfile 0.5%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
Build Docker Image / build (push) Successful in 1m28s
Reviewed-on: #12 Reviewed-by: pixel-board <pixel-board@m.ac.nz> |
||
| .forgejo/workflows | ||
| config | ||
| handlers | ||
| jwks | ||
| keys | ||
| metrics | ||
| .gitignore | ||
| Dockerfile | ||
| go.mod | ||
| go.sum | ||
| main.go | ||
| main_test.go | ||
| README.md | ||
| renovate.json | ||
test-token-service
A local OIDC JWT token service for development and testing. Issues signed JWTs and exposes standard OIDC discovery endpoints so your app can validate tokens against a real JWKS.
Quick start
go run .
This generates fresh RSA-2048 and EC P-384 signing keys on startup and begins serving on port 8080.
Configuration
All options can be set via flags or environment variables.
| Flag | Env var | Default | Description |
|---|---|---|---|
-port |
TOKEN_SERVICE_PORT |
8080 |
Port to listen on |
-issuer |
TOKEN_SERVICE_ISSUER |
http://localhost:<port> |
Issuer URL embedded in tokens |
-default-ttl |
TOKEN_SERVICE_DEFAULT_TTL |
3600 |
Default token lifetime (seconds) |
-max-ttl |
TOKEN_SERVICE_MAX_TTL |
86400 |
Maximum token lifetime (seconds) |
-metrics-port |
TOKEN_SERVICE_METRICS_PORT |
0 (off) |
Port to serve Prometheus metrics on |
Endpoints
POST /token
Issues a signed JWT. Requires Content-Type: application/json.
Request body:
{
"alg": "RS256",
"sub": "user-123",
"aud": "my-service",
"expires_in": 3600,
"claims": {
"email": "user@example.com",
"role": "admin"
}
}
| Field | Type | Required | Description |
|---|---|---|---|
alg |
string | yes | Signing algorithm: RS256 or ES384 |
sub |
string | no | Subject claim |
aud |
string or array | no | Audience — single string or array of up to 10 strings |
expires_in |
integer | no | Token lifetime in seconds (capped at max-ttl) |
claims |
object | no | Additional claims to embed in the token |
Response:
{
"access_token": "<jwt>",
"token_type": "Bearer",
"expires_in": 3600
}
Constraints:
alg=noneand all other algorithms are rejected- Reserved claims (
iss,iat,exp,nbf,jti,sub,aud,alg,kid,typ) cannot appear inclaims claimsobject must be ≤ 4 KB when JSON-encodedsubmust be ≤ 255 characters- Each
audentry must be ≤ 255 characters; max 10 entries - Request body is capped at 64 KB
GET /.well-known/openid-configuration
Returns the OIDC discovery document pointing at this service.
GET /.well-known/jwks.json
Returns the public keys as a JSON Web Key Set. Use this URI when configuring your app's token verifier.
Example
# Issue a token
TOKEN=$(curl -s -X POST http://localhost:8080/token \
-H 'Content-Type: application/json' \
-d '{"alg":"RS256","sub":"alice","aud":"my-api","claims":{"role":"admin"}}' \
| jq -r .access_token)
# Inspect the token (header + payload, no verification)
echo $TOKEN | cut -d. -f1,2 | tr '.' '\n' | base64 -d 2>/dev/null | jq
Metrics
Prometheus metrics are off by default. Set a metrics port to serve them at GET /metrics on that port. They are never served on the main port, and the metrics port serves nothing else. The service refuses to start if the metrics port can't be bound or equals the main port.
TOKEN_SERVICE_METRICS_PORT=9090 go run .
curl localhost:9090/metrics
| Metric | Labels | Description |
|---|---|---|
test_token_service_tokens_issued_total |
alg: RS256, ES384 |
Tokens issued |
test_token_service_token_requests_refused_total |
reason: content_type, body, alg, sub, aud, expires_in, claims, server_error |
POST /token requests answered with an error |
test_token_service_jwks_requests_total |
Fetches of /.well-known/jwks.json |
|
test_token_service_discovery_requests_total |
Fetches of /.well-known/openid-configuration |
body covers invalid JSON and bodies over 64 KB; server_error means signing failed. All label values are reported from startup, at 0. The standard Go runtime (go_*) and process (process_*) metrics are included too.
Docker
Build and run standalone:
docker build -t test-token-service .
docker run --rm -p 8080:8080 test-token-service
To use in another project's docker-compose.yml:
services:
token-service:
build:
context: ../test-token-service # adjust path as needed
ports:
- "8080:8080"
environment:
TOKEN_SERVICE_ISSUER: http://token-service:8080
Set TOKEN_SERVICE_ISSUER to the container's service name so tokens embed the correct iss claim — your app's JWKS verifier needs to reach that same URL to fetch /.well-known/jwks.json.
Development
go test ./...
Keys are ephemeral — regenerated on every restart. This service is intended for local development only and should not be used in production.