BotSharp/src/Infrastructure/BotSharp.Core/Users/Services/UserIdentity.cs

26 lines
796 B
C#
Raw Normal View History

2023-06-17 02:42:35 +00:00
using BotSharp.Abstraction.Users;
using Microsoft.AspNetCore.Http;
using System.Security.Claims;
namespace BotSharp.Core.Users.Services;
public class UserIdentity : IUserIdentity
{
private readonly IHttpContextAccessor _contextAccessor;
private IEnumerable<Claim> _claims => _contextAccessor.HttpContext.User.Claims;
public UserIdentity(IHttpContextAccessor contextAccessor)
{
_contextAccessor = contextAccessor;
}
2023-07-03 01:02:33 +00:00
public string Id => _claims.First(x => x.Type == ClaimTypes.NameIdentifier).Value;
2023-06-17 02:42:35 +00:00
2023-07-03 01:02:33 +00:00
public string Email => _claims.First(x => x.Type == ClaimTypes.Email).Value;
2023-06-17 02:42:35 +00:00
2023-07-03 01:02:33 +00:00
public string FirstName => _claims.First(x => x.Type == ClaimTypes.GivenName).Value;
2023-06-17 02:42:35 +00:00
2023-07-03 01:02:33 +00:00
public string LastName => _claims.First(x => x.Type == ClaimTypes.Surname).Value;
2023-06-17 02:42:35 +00:00
}