liveBook · Manning

User-jwts

As explained in ASP.NET Core in Action, 3e

dotnet user-jwts create is a .NET CLI command that generates a JWT for local API testing.

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

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains creation, configuration, request headers, customization, storage, management commands, and Swagger UI integration.
Examples
Uses dotnet user-jwts create, customized claims and scopes, bearer headers, Postman, and Swagger UI requests.
What it assumes
Assumes a project with JWT authentication configured; enables User Secrets automatically when creating the first token.
What you can do after
Operate/configure local JWT testing by generating, customizing, attaching, inspecting, and managing tokens.
How it connects
Connects JWT bearer authentication with User Secrets, OpenAPI, Swagger UI, authorization headers, and identity providers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.