Implements an identity context for managing user authentication and authorization information in ASP.NET Core applications.
$ dotnet add package Pavas.Runtime.IdentityContextPavas.Runtime.IdentityContext is a library designed to manage user identity, including authentication and authorization, within ASP.NET Core applications. It centralizes user-related information such as roles, claims, and other identity data, making it easier to access and manage across the application.
IdentityContext class to encapsulate user identity information.IdentityContextMiddleware.To use this library, include it in your project through dependency injection.
Define the identity context when create a jwt token:
var identityContext = new IdentityContext
{
Identifier = "1234567890",
Username = "John Doe",
Email = "john.doe@example.com",
Country = "US",
Gender = "Male",
PostalCode = "12345",
AuthenticationType = "Custom",
IsAuthenticated = true,
IpAddress = "127.0.0.1",
Roles = ["Admin", "User"],
Claims = [new Claim("custom-claim-type", "custom-claim-value")]
};
Inject the context into the service during application setup:
builder.Services.AddIdentityContext();
Add the middleware to the request pipeline:
app.UseIdentityContextMiddleware();
This project is licensed under the MIT License.