RA.Utilities.Authorization
RA.Utilities.Authorization offers a streamlined approach to handling user authentication and authorization in ASP.NET Core applications.
It provides a strongly-typed, injectable service to easily access the current user's claims, such as user ID, name, and roles, directly from the HttpContext.
This utility simplifies the process of retrieving authenticated user data, reducing boilerplate code and improving the readability and maintainability of your authorization logic.
🎯 Purpose
In any ASP.NET Core application that requires authentication, you often need to access information about the currently logged-in user.
This typically involves injecting IHttpContextAccessor and manually parsing claims from HttpContext.User.
This package abstracts that logic away into a clean, reusable, and testable service, ICurrentUser.
The main benefits are:
- Simplified Access: No more
IHttpContextAccessorin your controllers and services. Just injectICurrentUser. - Strongly-Typed: Get the user's ID as a
Guidorintwithout manual parsing and type conversion. - Testable: Easily mock
ICurrentUserin your unit tests to simulate different authenticated users and scenarios. - Reduced Boilerplate: Drastically cuts down on repetitive code for accessing user claims.
🛠️ Installation
You can install the package via the .NET CLI:
dotnet add package RA.Utilities.Authorization
Or through the NuGet Package Manager console:
Install-Package RA.Utilities.Authorization
Or through the NuGet Package Manager in Visual Studio.
🔗 Dependencies
📄️ AppUser
The AppUser class is a strongly-typed service that simplifies access to the claims of the currently authenticated user.
🗃️ Extensions
2 items