Last active
April 9, 2020 00:03
-
-
Save mrnkr/4d0e493458a9ed8b86ec1246bbbd053c to your computer and use it in GitHub Desktop.
This is how I retrieve the user from my request without tears
This file contains hidden or 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.Mvc; | |
using System.Linq; | |
using System.Security.Claims; | |
using System.Threading.Tasks; | |
namespace TwoDrive.Api | |
{ | |
public static class ExtractUserExtension | |
{ | |
protected static string GetLoggedUserId(this ControllerBase ctrl) | |
{ | |
return ctrl.User.Claims | |
.Where(c => c.Type == ClaimTypes.NameIdentifier) | |
.Select(c => c.Value) | |
.SingleOrDefault(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment