HmacAuthToolkit 1.0.3

dotnet add package HmacAuthToolkit --version 1.0.3
NuGet\Install-Package HmacAuthToolkit -Version 1.0.3
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="HmacAuthToolkit" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HmacAuthToolkit --version 1.0.3
#r "nuget: HmacAuthToolkit, 1.0.3"
#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.
// Install HmacAuthToolkit as a Cake Addin
#addin nuget:?package=HmacAuthToolkit&version=1.0.3

// Install HmacAuthToolkit as a Cake Tool
#tool nuget:?package=HmacAuthToolkit&version=1.0.3

HmacAuthToolkit

HmacAuthToolkit is a package designed to simplify the process of HMAC-based authentication, allowing for easy configuration of standard HMAC authentication as well as customization with additional claims.

Features

  • Easy to configure HMAC authentication
  • Customizable claims for enhanced security
  • Lightweight and efficient

Installation

You can install the HmacAuthToolkit package via NuGet:

dotnet add package HmacAuthToolkit 

Or you can add it directly to your project file:

<PackageReference Include="HmacAuthToolkit" Version="1.0.0" />

Usage

Basic Usage

Here's a simple example of how to use HmacAuthToolkit to generate and validate HMAC tokens.

using HmacAuthToolkit;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var secretKey = "supersecretkey";
        var hmacService = new HmacAuthenticationService(secretKey);
        var message = "testMessage";
        // Generate token
        var token = hmacService.GenerateToken(message);
        Console.WriteLine($"Generated Token: {token}");
        // Validate token
        var isValid = hmacService.ValidateToken(token, message, out var claims);
        Console.WriteLine($"Is Token Valid: {isValid}");
    }
}

Custom Claims

You can also include custom claims when generating tokens:

using HmacAuthToolkit;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var secretKey = "supersecretkey";
        var hmacService = new HmacAuthenticationService(secretKey);

        var message = "testMessage";
        var customClaims = new Dictionary<string, string>
        {
            { "claim1", "value1" },
            { "claim2", "value2" }
        };

        // Generate token with custom claims
        var token = hmacService.GenerateToken(message, customClaims);
        Console.WriteLine($"Generated Token with Claims: {token}");

        // Validate token and extract claims
        var isValid = hmacService.ValidateToken(token, message, out var claims);
        Console.WriteLine($"Is Token Valid: {isValid}");
        foreach (var claim in claims)
        {
            Console.WriteLine($"Claim: {claim.Key}, Value: {claim.Value}");
        }
    }
}

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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 70 5/28/2024