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" />
<PackageReference Include="Andrew.CommonUse.JWT" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=Andrew.CommonUse.JWT&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
# ๐ 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);
}
}
GetResponseTokenalso accepts optionalrolesandOthersfor 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 | 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
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.17)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.6)
- Microsoft.Extensions.Options (>= 9.0.6)
- Swashbuckle.AspNetCore.SwaggerGen (>= 9.0.1)
- System.IdentityModel.Tokens.Jwt (>= 8.12.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.