galaeth-draft/Galaeth.ApiServer/Providers/IdentityProvider.cs

35 lines
922 B
C#
Raw Normal View History

2024-11-17 10:31:01 +01:00
using Galaeth.Services.Constants;
using Galaeth.Services.Interfaces;
using Injectio.Attributes;
namespace Galaeth.ApiServer.Providers;
/// <inheritdoc />
[RegisterScoped]
public class IdentityProvider : IIdentityProvider
{
/// <summary>
/// Initializes a new instance of the <see cref="IdentityProvider"/> class.
/// </summary>
/// <param name="httpContextAccessor">Instance of <see cref="IHttpContextAccessor"/>.</param>
public IdentityProvider(IHttpContextAccessor httpContextAccessor)
{
var claims = httpContextAccessor.HttpContext?.User.Claims;
if (claims is not null)
{
UserId = claims.FirstOrDefault(c => c.Type == ClaimIds.UserId)?.Value;
}
}
/// <summary>
/// User's id.
/// </summary>
private string UserId { get; set; }
/// <inheritdoc />
public string GetRequestingUserId()
{
return UserId;
}
}