user-jwts is a .NET CLI tool for generating JWTs that authenticate requests to a local API. It acts as a small identity provider, creating signing key material and tokens your API can validate without connecting to a production identity provider. section 25.4
Run the command from the project folder to prepare a local token workflow:
- Run dotnet user-jwts create. The tool enables User Secrets when necessary, stores signing key material, updates appsettings.Development.json, and prints a JWT. section 25.4.1
- Use the generated token in an Authorization header formatted as Bearer <token>. Incorrect header spelling, spacing, prefix, or token content produces a 401 Unauthorized response. section 25.4.1
- Add bearer security requirements to OpenAPI so Swagger UI can attach the token to subsequent requests. section 25.5
Customize a token
Use dotnet user-jwts create --name tester --claim role=admin --scope recipes.read to change the subject name and add claims or scopes. Repeat --claim or --scope for additional values. Use --output token when a script needs only the token, or --output json when it needs creation details. section 25.4.2
dotnet user-jwts create
Inspect the core command used to generate a local JWT. section 25.4.1
Generated JWT configurations are stored outside the project alongside User Secrets, but the tokens are not encrypted. Use list, clear, remove, print, and key to manage them; resetting the signing key invalidates earlier tokens. Keep these tokens for local testing and configure a real identity provider for production. section 25.4.3
