Skip to main content

arolariu.Backend.Core.Auth.Endpoints

arolariu.Backend.Core.Auth

arolariu.Backend.Core.Auth.Endpoints Namespace

Classes

AuthEndpoints Class

Provides endpoint mapping for authentication and authorization operations. This partial class defines the authentication API endpoints using ASP.NET Core minimal APIs.

public static class AuthEndpoints

Inheritance System.Object 🡒 AuthEndpoints

Example

// Usage in application configuration
var app = builder.Build();
app.MapAuthEndpoints(); // Maps all authentication endpoints

Remarks

This class manages authentication endpoints including: - User registration and account creation - Login and logout operations - Password management and recovery - Email confirmation and verification - Account management operations

Methods

AuthEndpoints.LogoutRoute(SignInManager<IdentityUser>, ILoggerFactory, object) Method

Handles user logout operations by terminating the current authentication session. This endpoint signs out the authenticated user and invalidates their session.

private static System.Threading.Tasks.Task<Microsoft.AspNetCore.Http.IResult> LogoutRoute(Microsoft.AspNetCore.Identity.SignInManager<Microsoft.AspNetCore.Identity.IdentityUser> signInManager, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, object empty);

Parameters

signInManager Microsoft.AspNetCore.Identity.SignInManager<Microsoft.AspNetCore.Identity.IdentityUser>

The Microsoft.AspNetCore.Identity.SignInManager<> service for managing user authentication sessions. This service handles the logout process and session cleanup.

loggerFactory Microsoft.Extensions.Logging.ILoggerFactory

The Microsoft.Extensions.Logging.ILoggerFactory service for creating loggers to track logout operations. Used to log successful logouts and failed logout attempts.

empty System.Object

A placeholder object for the request body. The presence of this parameter validates that the logout request is intentional and not accidental.

Returns

System.Threading.Tasks.Task<Microsoft.AspNetCore.Http.IResult>
An Microsoft.AspNetCore.Http.IResult indicating the outcome of the logout operation. Returns Ok (200) on successful logout or Unauthorized (401) for invalid requests.

Example

// Client usage example
POST /logout
Content-Type: application/json
Authorization: Bearer {jwt-token}

{}

// Successful response: 200 OK
// Failed response: 401 Unauthorized

Remarks

This handler performs the following operations: - Validates that the logout request includes a request body - Signs out the current user using ASP.NET Core Identity - Clears authentication cookies and session data - Logs the logout operation (success or failure) - Returns appropriate HTTP status codes based on the operation result

AuthEndpoints.MapAuthEndpoints(this IEndpointRouteBuilder) Method

Maps authentication endpoints to the application's routing system. This method configures all authentication-related API endpoints for user management operations.

public static void MapAuthEndpoints(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder router);

Parameters

router Microsoft.AspNetCore.Routing.IEndpointRouteBuilder

The Microsoft.AspNetCore.Routing.IEndpointRouteBuilder used to define API routes and endpoints. This builder provides access to the application's routing configuration.

Remarks

This method configures: - Built-in ASP.NET Core Identity endpoints for standard authentication operations - Custom authentication endpoints for extended functionality - Proper versioning and tagging for API documentation - Security policies and authorization requirements

AuthEndpoints.MapIdentityBuiltinEndpoints(IEndpointRouteBuilder) Method

Maps the built-in ASP.NET Core Identity authentication endpoints and custom authentication routes. This method configures standard authentication operations and additional custom endpoints for user management.

private static void MapIdentityBuiltinEndpoints(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder router);

Parameters

router Microsoft.AspNetCore.Routing.IEndpointRouteBuilder

The Microsoft.AspNetCore.Routing.IEndpointRouteBuilder used to register authentication endpoints. This builder provides access to the application's routing system for endpoint configuration.

Remarks

This method configures two main endpoint groups:

1. **Built-in Identity Endpoints** (/auth group): - User registration and account creation - Login with email/password authentication - Password reset and recovery operations - Email confirmation and verification - Account management operations

2. **Custom Authentication Endpoints**: - Enhanced logout functionality with proper session cleanup - Additional security features and validation

All endpoints are configured with: - Proper OpenAPI documentation for Swagger integration - Appropriate HTTP status code responses - Anonymous access where required for authentication flows - Consistent tagging for API organization

// was this page useful?