Created
November 26, 2019 21:00
-
-
Save owlyowl/24a25ab22909c12652a00feeba8160a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Http; | |
using PregnancyStudy.Services; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Security.Claims; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Identity; | |
namespace Study.Web.Services | |
{ | |
public class GetCurrentApplicationUserName : IGetCurrentApplicationUserName | |
{ | |
readonly IHttpContextAccessor contextAccessor; | |
public GetCurrentApplicationUserName(IHttpContextAccessor contextAccessor) | |
{ | |
this.contextAccessor = contextAccessor; | |
} | |
string IGetCurrentApplicationUserName.GetCurrentApplicationUserName() | |
{ | |
var email = contextAccessor.HttpContext?.User?.Claims?.FirstOrDefault(c => c.Type == "sub")?.Value; | |
var userId = contextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier).Value; | |
return contextAccessor.HttpContext?.User?.Identity?.Name; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment