JWT.Module
1.0.0
dotnet add package JWT.Module --version 1.0.0
NuGet\Install-Package JWT.Module -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="JWT.Module" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JWT.Module" Version="1.0.0" />
<PackageReference Include="JWT.Module" />
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 JWT.Module --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JWT.Module, 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 JWT.Module@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=JWT.Module&version=1.0.0
#tool nuget:?package=JWT.Module&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
JWT Token Management NuGet Package
Overview
This repository contains a NuGet package for managing JSON Web Tokens (JWT) within ASP.NET Core applications. The package provides various functionalities for JWT-based authentication and authorization, including token generation, refresh token handling, and database integration.
Features
- JWT Token Generation: Generate JWT tokens with customizable configurations.
- Refresh Token Handling: Implement secure refresh token mechanisms to extend token validity.
- Database Integration: Store access tokens in an in-memory database and refresh tokens in a persistent database.
- AppSettings Configuration: Configure the package behavior through the
appsettings.json
file, allowing customization of token validity, database connections, and route configurations. - API Endpoints: Predefined API endpoints for full-cycle JWT authentication, including user registration, login, logout, token refreshing, and password updates.
Example AppSettings Configuration
{
"JWT": {
"ValidAudience": "http://yoursite.com",
"ValidIssuer": "http://yoursite.com",
"Secret": "JWTRefreshTokenHIGHsecuredPasswordVVVp1OH7Xzyr",
"TokenValidityInMinutes": 5,
"RefreshTokenValidityInDays": 7,
"ConnectionString": "Server=<server_name>;Database=<db_name>;Integrated Security=True;Trusted_Connection=True;TrustServerCertificate=True;",
"UserTableName": "AuthUser_Table", ///Table, you are already using to save user data like, AuthUser_Table
"UserTablePrimaryKey": "Id", ///unique Id in AuthUser_Table
"UserTableUniqueName": "UniqueName", ///unique username/email in AuthUser_Table
"JwtTableName": "TokenStorage", ///This nuget package is going to create a table to store token, TokenStorage_Table
"RegisterRoute": "auth/Register", ///This is the route to register new user
"LoginRoute": "auth/Login", ///This is the route to login
"LogoutRoute": "auth/Logout", ///This is the route to logout
"TokenRoute": "auth/GetTokenByRefreshToken", ///This is the route you need to create for fetching Refresh token
"UpdatePasswordRoute": "auth/UpdatePassword" ///This is the route to update/edit password
}
}
Example AuthController
[HttpPost]
[Route("auth/Register")]
public async Task<IActionResult> Register([FromBody] RegisterModel model)
{
///NOTE: Your Registration logic
return Ok();
}
[HttpPost]
[Route("auth/Login")]
public async Task<IActionResult> Login([FromBody] LoginModel model)
{
if (IsValidLogin())
{
return Ok();
}
return Unauthorized();
}
[Authorize] ///NOTE: We need to use [Authorize]
[HttpPost]
[Route("auth/Logout")]
public async Task<IActionResult> Logout()
{
return Ok();
}
[Authorize] ///NOTE: We need to use [Authorize]
[HttpGet]
[Route("auth/GetTokenByRefreshToken")]
public async Task<IActionResult> GetTokenByRefreshToken()
{
///NOTE: Implement your logic if any
return Ok();
}
[Authorize] ///NOTE: We need to use [Authorize]
[HttpPost]
[Route("auth/UpdatePassword")]
public async Task<IActionResult> UpdatePassword([FromBody] LoginModel model)
{
///NOTE: Implement your logic
return Ok();
}
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 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.
-
net8.0
- Dapper (>= 2.1.28)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.1)
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- System.Data.SqlClient (>= 4.8.6)
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 | 213 | 3/5/2024 |