// // Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License. // using System.Security.Claims; using Astral.Services.Constants; using Astral.Services.Interfaces; using Injectio.Attributes; namespace Astral.ApiServer.Providers; /// [RegisterScoped] public class IdentityProvider : IIdentityProvider { /// /// Initializes a new instance of the class. /// /// Instance of . public IdentityProvider(IHttpContextAccessor httpContextAccessor) { var claims = httpContextAccessor.HttpContext?.User.Claims; if (claims is not null) { Claims = claims; } } /// /// Session claims. /// private IEnumerable Claims { get; set; } /// public Guid GetUserId() { return Guid.TryParse(Claims.FirstOrDefault(c => c.Type == ClaimIds.UserId)?.Value, out var guid) ? guid : Guid.Empty; } /// public string GetUserName() { return Claims.FirstOrDefault(c => c.Type == ClaimIds.UserName)?.Value; } }