RamsonDevelopers.SecureJwt
1.0.0
dotnet add package RamsonDevelopers.SecureJwt --version 1.0.0
NuGet\Install-Package RamsonDevelopers.SecureJwt -Version 1.0.0
<PackageReference Include="RamsonDevelopers.SecureJwt" Version="1.0.0" />
<PackageVersion Include="RamsonDevelopers.SecureJwt" Version="1.0.0" />
<PackageReference Include="RamsonDevelopers.SecureJwt" />
paket add RamsonDevelopers.SecureJwt --version 1.0.0
#r "nuget: RamsonDevelopers.SecureJwt, 1.0.0"
#:package RamsonDevelopers.SecureJwt@1.0.0
#addin nuget:?package=RamsonDevelopers.SecureJwt&version=1.0.0
#tool nuget:?package=RamsonDevelopers.SecureJwt&version=1.0.0
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:
Download the RamsonDevelopers.SecureJwt source code or add it as a NuGet package to your solution.
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 | Versions 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. |
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.IdentityModel.Tokens (>= 8.5.0)
- Serilog.AspNetCore (>= 9.0.0)
- System.IdentityModel.Tokens.Jwt (>= 8.5.0)
- System.Security.Cryptography.Primitives (>= 4.3.0)
-
net9.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.IdentityModel.Tokens (>= 8.5.0)
- Serilog.AspNetCore (>= 9.0.0)
- System.IdentityModel.Tokens.Jwt (>= 8.5.0)
- System.Security.Cryptography.Primitives (>= 4.3.0)
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 |