RamsonDevelopers.SecureJwt 1.0.0

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

RamsonDevelopers.SecureJwt

RamsonDevelopers.SecureJwt is a .NET class library that provides functionality to Securely authenticate using JWT, by ensuring the signing keys are rotated and by implementing fingerprint validation layer to it as well.

Installation

To use RamsonDevelopers.SecureJwt in your project, follow these steps:

  1. Download the RamsonDevelopers.SecureJwt source code or add it as a NuGet package to your solution.

  2. Add a reference to the AddSecureJwt() Method in RamsonDevelopers.SecureJwt project or the installed NuGet package in your target project's program.cs.


builder.Services.AddSecureJwt(options =>
{
    options.Config = new RotatingJwtOptions
   {
      TokenLifeTime = TimeSpan.FromMinutes(20),
      RefreshTokenLifeTime = TimeSpan.FromMinutes(40),
      AesKeySize = 256,
      Audience = "https://localhost:7054/",
      Issuer = "https://localhost:7054/",
   };

   // Create a random AES
    using var aes = Aes.Create();
    aes.KeySize = 256;
    aes.GenerateKey();

    // Or can use any custom AES key can be from key vault
    options.Config.SecretKey = Convert.ToBase64String(aes.Key);
    options.Config.AesKeySize = aes.KeySize;
    return options;
});

NOTE: you dont need to have the following lines in the program.cs file:

     builder.Services.AddAuthentication(authentication =>
        {
            authentication.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            authentication.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
        })
        .AddJwtBearer(bearer =>{
            // Code here
        });

Usage

To create tokens using RamsonDevelopers.SecureJwt, follow these steps:

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SecureJwt;
using Serilog;

namespace Tests_Api.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController(JwtTokenService jwtTokenService) : ControllerBase
    {
        [HttpGet]
        public string Get()
        {
            var tokenResponse = jwtTokenService.GenerateJwtToken("1");
            Log.Information("Token generated for user {Token}", tokenResponse.Token);
            Log.Information("Key Pub generated for user {PublicKey}", tokenResponse.PublicKey);
            return tokenResponse.Token;
        }


        [HttpPost]
        [Authorize]
        public IActionResult Post()
        {
            return Ok();
        }
    }
}


Credits

RamsonDevelopers.SecureJwt was developed by Ayush Aher and is maintained by Ramson Developers. We would like to acknowledge the contributions of the open-source community and express our gratitude to all the contributors who helped make this project possible.


Feedback

If you have any feedback, please reach out to us at ayushaher118@gmail.com or Raise a Issue in Github Repository

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 is compatible.  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.0 116 2/22/2025