mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 19:21:10 +00:00
Implements Authorization system
This commit is contained in:
1 parent
5bfb2ca212
commit
2c9c210e43
68 files changed
+2734
-336
No files matched your search
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Security.Claims;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Common.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Service for retrieving the current user's information from the HTTP context.
|
||||
/// </summary>
|
||||
public class HttpContextCurrentUserService : ICurrentUserService
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HttpContextCurrentUserService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="httpContextAccessor">The <see cref="IHttpContextAccessor"/> used to access the current HTTP context.</param>
|
||||
public HttpContextCurrentUserService(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique identifier of the currently authenticated user. Returns <see langword="null"/> if no user is authenticated or if the claim is not present.
|
||||
/// </summary>
|
||||
public Guid? UserId
|
||||
{
|
||||
get
|
||||
{
|
||||
string? userIdClaim = _httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
return Guid.TryParse(userIdClaim, out Guid userId) ? userId : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user