hanyadikhetvan-dotnethf/HanyadikHetVan/Services/IdentityService.cs

27 lines
687 B
C#
Raw Permalink Normal View History

2021-05-19 17:56:56 +02:00
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace HanyadikHetVan.Services
{
public class IdentityService
{
private readonly IHttpContextAccessor httpContextAccessor;
public IdentityService(IHttpContextAccessor httpContextAccessor)
{
this.httpContextAccessor = httpContextAccessor;
}
public string GetUserId()
{
return
httpContextAccessor.HttpContext.User.Claims
.SingleOrDefault(x => x.Type.ToLower() == "sub")
?.Value ?? throw new Exception();
}
}
}