Andrew.CommonUse.JWT 1.1.0

dotnet add package Andrew.CommonUse.JWT --version 1.1.0
                    
NuGet\Install-Package Andrew.CommonUse.JWT -Version 1.1.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="Andrew.CommonUse.JWT" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Andrew.CommonUse.JWT" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Andrew.CommonUse.JWT" />
                    
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 Andrew.CommonUse.JWT --version 1.1.0
                    
#r "nuget: Andrew.CommonUse.JWT, 1.1.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 Andrew.CommonUse.JWT@1.1.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=Andrew.CommonUse.JWT&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Andrew.CommonUse.JWT&version=1.1.0
                    
Install as a Cake Tool
# ๐Ÿ” EasyJWT โ€“ Simplify JWT Authentication in ASP.NET Core

**EasyJWT** is a lightweight library that simplifies the implementation of JWT (JSON Web Tokens) authentication in ASP.NET Core. It supports both **access** and **refresh tokens**, and includes seamless Swagger integration for testing secured APIs.

---

## โœจ Features

- โœ… Minimal configuration required
- ๐Ÿ” Supports **Access** and **Refresh** tokens
- โฑ๏ธ Customizable expiration settings
- ๐Ÿงช Out-of-the-box Swagger support with `Bearer` scheme
- ๐Ÿ“ฆ Available as a NuGet package: `Andrew.CommonUse.JWT`

---

## ๐Ÿ“ฆ Installation

Install via NuGet:

### Using .NET CLI

```bash
dotnet add package Andrew.CommonUse.JWT

Using Package Manager

NuGet\Install-Package Andrew.CommonUse.JWT

๐Ÿ› ๏ธ Setup Instructions

1. Configure appsettings.json

"JWT": {
  "SecKey": "your-secret-key-goes-here",
  "ExpiresMinutes": 60,
  "RefreshTokenExpiresHours": 189,
  "Issuer": "your-issuer",
  "Audience": "your-audience"
}

2. Register in Program.cs

builder.Services.AddJWTAuthentication(builder.Configuration);

3. Inject and Use in Your Controller

[ApiController]
[Route("api/[controller]")]
public class LoginController : ControllerBase
{
    private readonly AuthenticationTokenResponse _authTokenResponse;

    public LoginController(AuthenticationTokenResponse authTokenResponse)
    {
        _authTokenResponse = authTokenResponse;
    }

    [HttpPost("login")]
    public IActionResult Login(User user)
    {
        var token = _authTokenResponse.GetResponseToken(user.Id, user.UserName);
        return Ok(token);
    }
}

GetResponseToken also accepts optional roles and Others for custom claims:

TokenWithExpireResponse GetResponseToken(
    long userId,
    string userName,
    List<string>? roles = null,
    Dictionary<string, string>? others = null
);

๐Ÿงพ Token Response Structure

public class TokenResponse
{
    public string AccessToken { get; set; }
    public string RefreshToken { get; set; }
    public DateTimeOffset AccessTokenExpiresAt { get; set; }
    public DateTimeOffset RefreshTokenExpiresAt { get; set; }
}

๐Ÿ“„ License

This project is licensed under the MIT License.

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.1.0 288 7/5/2025
1.0.0 214 6/22/2025