AuthenticateSwaggerUI.Core 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package AuthenticateSwaggerUI.Core --version 1.0.1
                    
NuGet\Install-Package AuthenticateSwaggerUI.Core -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AuthenticateSwaggerUI.Core" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AuthenticateSwaggerUI.Core" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="AuthenticateSwaggerUI.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AuthenticateSwaggerUI.Core --version 1.0.1
                    
#r "nuget: AuthenticateSwaggerUI.Core, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AuthenticateSwaggerUI.Core@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AuthenticateSwaggerUI.Core&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=AuthenticateSwaggerUI.Core&version=1.0.1
                    
Install as a Cake Tool

🛡️ Swagger & RapiDoc 2FA Authenticator for ASP.NET Core

A lightweight, secure middleware for ASP.NET Core applications that protects your Swagger UI and JSON endpoints using Basic Authentication combined with a Google Authenticator 2FA code. It also comes with built-in support for rendering beautiful RapiDoc documentation.

✨ Features

  • Two-Factor Authentication (2FA): Secures your API docs using a 6-digit Time-Based One-Time Password (TOTP) from Google Authenticator.
  • Built-in RapiDoc Support: Automatically serves a modern, dark-themed RapiDoc interface at the /docs endpoint.
  • Stateless Session Security: Uses a securely signed, tamper-proof, and HTTP-only session cookie to maintain authentication.
  • Static Asset Bypassing: Intelligently bypasses authentication for static UI assets (CSS, JS, images) to ensure fast rendering.
  • Environment Aware: Configurable to bypass or enforce authentication during development.

🚀 Getting Started & Configuration

1. Installation

Use the NuGet Package Manager to install AuthenticateSwaggerUI.Core.

PM> Install-Package AuthenticateSwaggerUI.Core

2. Register the Middleware in Program.cs

Add the middleware to your request pipeline. Make sure to place it before app.UseSwagger() and app.UseSwaggerUI().

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

// Configure the authentication middleware
app.AuthenticateSwaggerUI(
    twoFAUsername: "admin", // The username required in the Basic Auth prompt (Default: "admin"))
    twoFASecretKey: "YOUR_BASE32_ENCODED_GOOGLE_AUTH_SECRET", // The key entered into Google Authenticator (Use a UUID encoded in Base32 format recommended)
    cookeName: "ApiDocSession", // Name of the session cookie, Give a unique name to avoid conflicts with other cookies
    cookieSecret: "A_VERY_STRONG_RANDOM_SECRET_KEY_FOR_HMAC_SIGNATURE", // Used to cryptographically sign the cookie (Use a UUID encoded in SHA256 format recommended)
    revokeDuration: DateTime.UtcNow.AddHours(8), //// Session duration (Default: 12 hours in UTC))
    enableOnDevelopment: false // Set to true to enable authentication in development environment (Default: true))
);

// Standard ASP.NET Core pipeline...
app.Run();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 36 6/5/2026
1.0.2 32 6/5/2026
1.0.1 36 6/5/2026

Initial release