DT.JwtGenerator
1.0.6
dotnet add package DT.JwtGenerator --version 1.0.6
NuGet\Install-Package DT.JwtGenerator -Version 1.0.6
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="DT.JwtGenerator" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DT.JwtGenerator" Version="1.0.6" />
<PackageReference Include="DT.JwtGenerator" />
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 DT.JwtGenerator --version 1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DT.JwtGenerator, 1.0.6"
#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 DT.JwtGenerator@1.0.6
#: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=DT.JwtGenerator&version=1.0.6
#tool nuget:?package=DT.JwtGenerator&version=1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DigitTwin.JwtGenerator
Описание
Fluent JWT Builder для .NET с поддержкой DDD и DI.
Установка
dotnet add package DigitTwin.JwtGenerator
Настройка
Добавить в appsettings.json
{
"Jwt": {
"SecretKey": "your_32_chars_min_secret_key_here_!",
"Issuer": "https://yourapi.com",
"Audience": "https://yourclient.com",
"AccessTokenLifetime": "00:15:00",
"RefreshTokenLifetime": "7.00:00:00"
}
}
Зарегистрируйте в Program.cs
using DigitTwin.JwtGenerator;
builder.Services.AddJwtServices(builder.Configuration);
Использование
Генерация токена
var token = _jwtTokenBuilder
.AddClaim("sub", "123")
.AddClaim("email", "user@example.com")
.WithExpiration(TimeSpan.FromHours(1))
.Build();
Вадидация токена
if (_jwtTokenValidator.TryValidateToken(jwt, out var principal))
{
var userId = principal.GetUserId();
var email = principal.GetEmail();
}
Refresh-токены
var refreshToken = await _refreshTokenService.GenerateRefreshTokenAsync("123");
var isValid = await _refreshTokenService.ValidateRefreshTokenAsync(refreshToken);
await _refreshTokenService.RevokeRefreshTokenAsync(refreshToken);
Дополнительно
Реализуйте IRefreshTokenStore
в инфраструктуре:
public class EfCoreRefreshTokenStore : IRefreshTokenStore
{
// Реализуйте методы: GetByTokenAsync, AddAsync, RevokeAsync, RemoveExpiredAsync
}
И зарегистрируйте:
builder.Services.AddScoped<IRefreshTokenStore, EfCoreRefreshTokenStore>();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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.
-
net9.0
- Microsoft.Extensions.Configuration (>= 9.0.9)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.9)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.9)
- Microsoft.IdentityModel.Tokens (>= 8.14.0)
- System.IdentityModel.Tokens.Jwt (>= 8.14.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Change icon.