MCCI.Chatbot.Auth 1.0.5

dotnet add package MCCI.Chatbot.Auth --version 1.0.5
                    
NuGet\Install-Package MCCI.Chatbot.Auth -Version 1.0.5
                    
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="MCCI.Chatbot.Auth" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MCCI.Chatbot.Auth" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="MCCI.Chatbot.Auth" />
                    
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 MCCI.Chatbot.Auth --version 1.0.5
                    
#r "nuget: MCCI.Chatbot.Auth, 1.0.5"
                    
#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 MCCI.Chatbot.Auth@1.0.5
                    
#: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=MCCI.Chatbot.Auth&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=MCCI.Chatbot.Auth&version=1.0.5
                    
Install as a Cake Tool

MCCI.Chatbot.Auth

A lightweight .NET SDK that allows a website to reuse its existing logged-in user and roles to authorize access to an external chatbot without a separate chatbot login.

The website remains the identity and authorization authority.
The chatbot trusts tokens issued by the website.


What this package does

This package provides:

  • A service to read the currently logged-in user
  • Role extraction from the current request
  • Role mapping (website roles → chatbot roles)
  • Secure JWT token generation

This package does NOT:

  • Authenticate users
  • Store users or passwords
  • Create controllers or endpoints
  • Read configuration automatically

Prerequisites

  • .NET 6 / 7 / 8
  • Existing authentication already configured
    (ASP.NET Identity, OrchardCore, Entra, etc.)

Installation

dotnet add package MCCI.Chatbot.Auth

Step 1: Register the service (Program.cs)

This is the only required setup step after installing the package.

builder.Services.AddChatbotAuth();

Make sure authentication middleware already exists:

app.UseAuthentication();
app.UseAuthorization();

Step 2: Client configuration (appsettings.json)

The client website owns all configuration.

{
  "Chatbot": {
    "SharedSecret": "super-long-32-byte-secret-value",
    "Issuer": "client-website",
    "Audience": "chatbot",
    "RoleMapping": {
      "Administrator": [ "Admin" ],
      "Editor": [ "Editor" ],
      "Student": [ "Student" ]
    }
  }
}

Important rules

  • SharedSecret must be at least 32 bytes
  • Issuer identifies your website
  • Audience identifies the chatbot
  • Role mapping is explicit (default deny)

Step 3: Generate a chatbot token

Inject IChatbotAuthService into your controller or service:

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MCCI.Chatbot.Auth;
using System.Security.Claims;

[ApiController]
[Route("api/chatbot")]
public class ChatbotController : ControllerBase
{
    private readonly IChatbotTokenProvider _tokenProvider;
    private readonly IConfiguration _configuration;

    public ChatbotController(
        IChatbotTokenProvider tokenProvider,
        IConfiguration configuration)
    {
        _tokenProvider = tokenProvider;
        _configuration = configuration;
    }

    [HttpGet("token")]
    [Authorize]
    public async Task<IActionResult> GetToken()
    {
        var roleMapping =
            _configuration
                .GetSection("Chatbot:RoleMapping")
                .Get<Dictionary<string, string[]>>() ?? new();

        var token = await _tokenProvider.GetTokenAsync(
            HttpContext,
            sharedSecret: _configuration["Chatbot:SharedSecret"]!,
            roleMapping: roleMapping,
            issuer: _configuration["Chatbot:Issuer"]!,
            audience: _configuration["Chatbot:Audience"]!
        );

        return Ok(new { token });
    }
}

What this endpoint does

  • Requires the user to be authenticated
  • Extracts the current user and roles
  • Maps roles according to configuration
  • Generates a JWT token for the chatbot
  • Returns the token to the caller

Security notes

  • Tokens are generated server-side only
  • Secrets never go to the browser
  • Tokens are short-lived
  • Each website should use a unique secret
  • Issuer and audience must be validated by the chatbot
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.5 2,409 3/6/2026
1.0.4 103 3/2/2026
1.0.3 103 2/27/2026
1.0.2 881 1/27/2026
1.0.1 114 1/14/2026
1.0.0 109 1/14/2026