Levge.Identity
1.1.43
dotnet add package Levge.Identity --version 1.1.43
NuGet\Install-Package Levge.Identity -Version 1.1.43
<PackageReference Include="Levge.Identity" Version="1.1.43" />
<PackageVersion Include="Levge.Identity" Version="1.1.43" />
<PackageReference Include="Levge.Identity" />
paket add Levge.Identity --version 1.1.43
#r "nuget: Levge.Identity, 1.1.43"
#:package Levge.Identity@1.1.43
#addin nuget:?package=Levge.Identity&version=1.1.43
#tool nuget:?package=Levge.Identity&version=1.1.43
<img src="src/Levge.Identity/icon.png" width="100" height="100" alt="Levge.Identity logo" />
Levge.Identity
Levge.Identity
is a .NET 8 library providing identity and authentication services with JWT support, password hashing, code generation, and extensible user context for modern applications. Includes email notification capabilities.
Features
- ? JWT-based authentication and authorization
- ? Strong password hashing (PBKDF2)
- ? User context and claims access via
ICurrentUser<T>
- ? Secure code and password generation utilities
- ? Extensible identity provider model
- ? Easy integration with ASP.NET Core DI
Installation
.NET CLI
dotnet add package Levge.Identity
Package Manager
Install-Package Levge.Identity
Setup
- Add configuration in
Program.cs
: builder.Services.AddIdentity<JwtIdentityProvider, string>(builder.Configuration); Or with custom config: var identityConfig = new IdentityConfig { Jwt = new JwtConfig { Issuer = "your-issuer", Audience = "your-audience", Secret = "your-secret-key", // ...other options } }; builder.Services.AddIdentity<JwtIdentityProvider, string>(identityConfig); - Access current user via DI: public class MyController : ControllerBase { private readonly ICurrentUser<string> _currentUser; public MyController(ICurrentUser<string> currentUser) { _currentUser = currentUser; } // ... }
Usage
- Generate JWT tokens:
Use
IJwtTokenService
for access/refresh token generation. - Password hashing:
Use
IPasswordHasher
for secure password storage. - Code generation:
Use
ICodeGenerator
for numeric, alphanumeric, or scoped codes. - Access user info:
Use
ICurrentUser<TKey>
to get user id, email, role, claims, etc. var token = jwtTokenService.GenerateAccessToken(claims); var passwordHash = passwordHasher.Hash("myPassword"); var code = codeGenerator.GenerateNumericCode(); if (!_currentUser.IsAuthenticated) throw new LevgeException("Not authenticated");
Configuration Options
Option | Description |
---|---|
Issuer |
JWT token issuer |
Audience |
JWT token audience |
Authority |
Authority for validation |
Secret |
Secret key for signing JWT |
AccessTokenExpirationMinutes |
Access token expiration in minutes |
RefreshTokenExpirationMinutes |
Refresh token expiration in minutes |
EnableRefreshTokens |
Enable refresh tokens |
ValidateIssuer |
Validate issuer |
ValidateAudience |
Validate audience |
ValidateLifetime |
Validate token lifetime |
ValidateSigningKey |
Validate signing key |
AuthScheme |
Authentication scheme (default: Bearer) |
DefaultScheme |
Default authentication scheme |
License
MIT License. See LICENSE for details.
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. |
-
net8.0
- Levge.Exceptions (>= 1.1.43)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.17)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Levge.Identity:
Package | Downloads |
---|---|
Levge.AuditLog
Domain entity, interface, and enumeration base types for Levge projects. |
GitHub repositories
This package is not used by any popular GitHub repositories.