A simple development/testing tool for generating JWT tokens to test the Music Albums API.
Generates JWT tokens with custom claims for testing authorization in the main Music Albums API.
The Identity API requires Jwt:Key (min 32 characters). The key must match the one used by the main Music Albums API, otherwise tokens won't validate. On startup, the app fails fast if the key is missing or too short.
The AppHost reads jwt-key from its user-secrets and injects it as Jwt:Key into both services — set it once and both API and Identity API pick it up:
cd src/MusicAlbums.AppHost
dotnet user-secrets set "jwt-key" "your-secret-key-min-32-chars"
cd ..
aspire startExposed on http://localhost:5003 and https://localhost:5004.
Configure the secret on the Identity API project itself, then run:
cd tools/Identity.Api
dotnet user-secrets set "Jwt:Key" "your-secret-key-min-32-chars"
dotnet runEndpoint: POST /token
Validation:
userIdis required (must be present in the payload) and must be a valid GUID (not all zeros)
Request:
{
"userId": "d8663e5e-7494-4f81-8739-6e0de1bdb96f",
"email": "admin@test.com",
"customClaims": {
"admin": "true",
"trusted_member": "true"
}
}Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Admin:
{
"userId": "00000000-0000-0000-0000-000000000001",
"email": "admin@test.com",
"customClaims": {
"admin": "true",
"trusted_member": "true"
}
}Member:
{
"userId": "00000000-0000-0000-0000-000000000002",
"email": "member@test.com",
"customClaims": {
"trusted_member": "true"
}
}Regular User:
{
"userId": "00000000-0000-0000-0000-000000000003",
"email": "user@test.com",
"customClaims": {}
}Copy the token and use it in requests to the Music Albums API:
curl -H "Authorization: Bearer YOUR_TOKEN_HERE" \
https://localhost:5002/api/albumsWith aspire start running in another terminal:
curl -X POST https://localhost:5004/token \
-H "Content-Type: application/json" \
-d '{
"userId": "550e8400-e29b-41d4-a716-446655440000",
"email": "test@test.com",
"customClaims": {}
}'- Has no authentication
- Has no user database
- Generates tokens for anyone
- For local/testing only
Tokens expire after 8 hours.