dotkit 1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet tool install --global dotkit --version 1.0.0
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
dotnet tool install --local dotkit --version 1.0.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=dotkit&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package dotkit --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
dotkit
A .NET CLI tool that installs and configures JWT Authentication in ASP.NET Core Web API projects with a single command.
Features
- Installs
Microsoft.AspNetCore.Authentication.JwtBearerNuGet package - Adds
Jwtsection toappsettings.jsonwith auto-generated secret key - Creates
JwtSettingsandJwtServiceready-to-use classes - Injects JWT authentication, DI registration, and middleware into
Program.cs - Configures User Secrets for
SecretKey,Issuer, andAudience(or writes them toappsettings.jsonvia--no-user-secrets) - Logs progress to console and rolling files via Serilog
Installation
dotnet tool install --global dotkit
Usage
dotkit install [options]
Options
| Option | Description | Default |
|---|---|---|
--project |
Path to the Web API project directory | Current directory |
--secret-key |
JWT secret key (32+ chars) | Auto-generated (64 chars base64) |
--issuer |
Token issuer | Project name |
--audience |
Token audience | Project name |
--no-user-secrets |
Write values to appsettings.json instead of User Secrets |
false |
--verbose |
Enable debug-level logging | false |
Examples
# Default: stores values in User Secrets
dotkit install
# Custom values
dotkit install --project ./MyApi --issuer "MyApp" --audience "MyApp"
# Write values directly to appsettings.json (skip User Secrets)
dotkit install --no-user-secrets --secret-key "your-32-char-min-key-here..."
What it does
- Detects the ASP.NET Core Web API project (must target
Microsoft.NET.Sdk.Web) - Installs
Microsoft.AspNetCore.Authentication.JwtBearerNuGet package - Merges
Jwtsection intoappsettings.json - Creates
Configuration/JwtSettings.csandServices/JwtService.cs - Injects into
Program.cs:- Required
usingdirectives builder.Services.AddAuthentication().AddJwtBearer()withTokenValidationParametersbuilder.Services.Configure<JwtSettings>(...)builder.Services.AddScoped<JwtService>()app.UseAuthentication()andapp.UseAuthorization()
- Required
- Configures
SecretKey,Issuer, andAudiencevia User Secrets (orappsettings.json)
After running, inject JwtService in any controller and call GenerateAccessToken() to issue JWTs.
Secret storage modes
| Mode | appsettings.json |
User Secrets |
|---|---|---|
| User Secrets (default) | Placeholder (CHANGE_ME...) |
Real key, issuer, audience |
--no-user-secrets |
Real key, issuer, audience | Not configured |
Lifecycle
dotkit install [options]
│
▼
┌─────────────────────┐
│ Initialize Serilog │ → %TEMP%\dotkit\logs\dotkit-YYYYMMDD.log
└─────────┬───────────┘
▼
┌─────────────────────┐
│ ProjectDetector │ ← Reads .csproj from directory
│ .Detect() │
└─────────┬───────────┘
▼
┌─────────────────────┐
│ JwtInstaller │ ← dotnet add package
│ .InstallAsync() │ Microsoft.AspNetCore.Authentication.JwtBearer
└─────────┬───────────┘
▼
┌─────────────────────┐
│ JsonEditor │ ← Merges Jwt section from template
│ .UpdateAppSettings │ into existing appsettings.json
│ (key?,iss?,aud?) │ (real values if --no-user-secrets,
└─────────┬───────────┘ placeholder if User Secrets)
▼
┌─────────────────────┐
│ TemplateInstaller │ ← Creates:
│ .InstallTemplates │ Configuration/JwtSettings.cs
│ │ Services/JwtService.cs
└─────────┬───────────┘
▼
┌─────────────────────┐
│ ProgramEditor │ ← Injects into Program.cs:
│ .UpdateProgramAsync│ - usings for .Configuration and .Services
│ │ - AddAuthentication + AddJwtBearer
│ │ - Configure<JwtSettings>
│ │ - AddScoped<JwtService>
│ │ - app.UseAuthentication/Authorization
└─────────┬───────────┘
▼
┌─────────────────────┐
│ UserSecretsManager │ ← (only if NOT --no-user-secrets)
│ .ConfigureAsync │ dotnet user-secrets init
│ │ set Jwt:SecretKey
│ │ set Jwt:Issuer
│ │ set Jwt:Audience
└─────────┬───────────┘
▼
✓ Installation completed successfully
Possible errors
ProjectDetector
| Error | Cause |
|---|---|
Directory '{path}' not found. |
--project points to a non-existent directory |
No .csproj file was found. |
Directory contains no .csproj file |
Program.cs was not found. |
Project has no Program.cs |
The selected project is not an ASP.NET Core Web API. |
.csproj doesn't use Microsoft.NET.Sdk.Web |
JsonEditor
| Error | Cause |
|---|---|
Template not found: {path} |
appsettings.json template missing from Templates/ |
Template JSON is invalid. |
Template is not valid JSON |
Template does not contain 'Jwt' section. |
Template has no Jwt property |
Existing appsettings.json contains invalid JSON. |
Target project's appsettings.json has malformed JSON |
JwtInstaller
| Error | Cause |
|---|---|
Failed to install Microsoft.AspNetCore.Authentication.JwtBearer: ... |
dotnet add package failed (no connection, incompatible version, etc.) |
UserSecretsManager
| Error | Cause |
|---|---|
Error: dotnet user-secrets init --project ... |
Could not initialize User Secrets (permissions, SDK) |
Error: dotnet user-secrets set --project ... |
Could not set a secret |
Runtime errors (in the generated project, NOT in the tool)
| Error (project runtime) | Cause |
|---|---|
JWT settings not configured. |
Jwt section in appsettings.json was not loaded correctly |
IDX10720: key size must be greater than '256' bits |
SecretKey < 32 characters (only if someone modified the placeholder) |
SecretKey not found. / Issuer not found. / Audience not found. |
JwtService instantiated without configured values |
Exit code
0→ success1→ any error (message and exception are logged)
Requirements
- .NET 10 SDK or later
- An ASP.NET Core Web API project targeting
net10.0
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.