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(); } } }