35 lines
922 B
C#
35 lines
922 B
C#
|
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;
|
||
|
}
|
||
|
}
|