arolariu.Backend.Core.Auth.Modules
arolariu.Backend.Core.Auth
arolariu.Backend.Core.Auth.Modules Namespace
Classes
WebApplicationBuilderExtensions Class
Provides extension methods for configuring comprehensive authentication and authorization services. This class sets up ASP.NET Core Identity with JWT Bearer token authentication and Entity Framework integration.
public static class WebApplicationBuilderExtensions
Inheritance System.Object 🡒 WebApplicationBuilderExtensions
Example
// Usage in Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.AddAuthServices();
Remarks
This module configures a complete authentication system including: - Entity Framework database context with retry policies - ASP.NET Core Identity with secure password requirements - JWT Bearer token authentication with configurable validation - Cookie-based authentication for web scenarios - Authorization policies and role-based access control
Methods
WebApplicationBuilderExtensions.AddAuthServices(this WebApplicationBuilder) Method
Configures comprehensive authentication and authorization services including Identity, JWT, and database integration. This method establishes a complete authentication infrastructure with security best practices.
public static void AddAuthServices(this Microsoft.AspNetCore.Builder.WebApplicationBuilder builder);
Parameters
builder Microsoft.AspNetCore.Builder.WebApplicationBuilder
The Microsoft.AspNetCore.Builder.WebApplicationBuilder to configure with authentication services.
Exceptions
System.ArgumentNullException
Thrown when builder is null.
Remarks
This method configures: - Entity Framework database context with SQL Server and retry policies - ASP.NET Core Identity with strict password and lockout requirements - JWT Bearer authentication with token validation parameters - Secure cookie configuration for web-based authentication - Authorization services for role and policy-based access control
WebApplicationExtensions Class
Provides extension methods for configuring authentication and authorization middleware in the request pipeline. This class sets up the authentication flow including endpoint mapping and middleware ordering.
public static class WebApplicationExtensions
Inheritance System.Object 🡒 WebApplicationExtensions
Example
// Usage in Program.cs
var app = builder.Build();
app.UseAuthServices();
Remarks
This module configures the authentication pipeline in the correct order: 1. Authentication endpoint mapping for login/logout operations 2. Authentication middleware for token validation 3. Authorization middleware for access control
Methods
WebApplicationExtensions.UseAuthN(this WebApplication) Method
Configures the application to use authentication middleware. This method enables request identity validation and token processing.
private static void UseAuthN(this Microsoft.AspNetCore.Builder.WebApplication app);
Parameters
app Microsoft.AspNetCore.Builder.WebApplication
The Microsoft.AspNetCore.Builder.WebApplication to configure with authentication middleware.
Remarks
Authentication middleware: - Validates JWT tokens in request headers - Establishes user identity from valid tokens - Sets HttpContext.User for downstream middleware - Must be called before authorization middleware
WebApplicationExtensions.UseAuthServices(this WebApplication) Method
Configures the application to use comprehensive authentication and authorization middleware. This method sets up the complete authentication pipeline including endpoints and middleware.
public static void UseAuthServices(this Microsoft.AspNetCore.Builder.WebApplication app);
Parameters
app Microsoft.AspNetCore.Builder.WebApplication
The Microsoft.AspNetCore.Builder.WebApplication to configure with authentication services.
Exceptions
System.ArgumentNullException
Thrown when app is null.
Remarks
This method configures the authentication pipeline in the proper sequence: - Maps authentication endpoints for user operations (login, logout, registration) - Enables authentication middleware for request identity validation - Enables authorization middleware for role and policy-based access control
WebApplicationExtensions.UseAuthZ(this WebApplication) Method
Configures the application to use authorization middleware. This method enables role-based and policy-based access control.
private static void UseAuthZ(this Microsoft.AspNetCore.Builder.WebApplication app);
Parameters
app Microsoft.AspNetCore.Builder.WebApplication
The Microsoft.AspNetCore.Builder.WebApplication to configure with authorization middleware.
Remarks
Authorization middleware: - Evaluates user permissions against endpoint requirements - Enforces role-based access control (RBAC) - Applies policy-based authorization rules - Must be called after authentication middleware