hanyadikhetvan-dotnethf/HanyadikHetVan/Services/IdentityService.cs
Torma Kristóf 634488c2d8
All checks were successful
continuous-integration/drone/push Build is passing
addfunfacts
2021-05-19 17:56:56 +02:00

27 lines
687 B
C#

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