Commit MWS backend source tree
The ASP.NET Core solution (mws.api/mws.application/mws.domain/ mws.infrastructure) existed only as untracked working files. Adding it to version control, plus a .gitignore for build output and local tooling directories, so the CQRS/mediator refactor plan has a real git history to branch and diff against.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using System.Security.Claims;
|
||||
using Microsoft.IdentityModel.JsonWebTokens;
|
||||
|
||||
namespace Mws.Api;
|
||||
|
||||
public static class ClaimsExtensions
|
||||
{
|
||||
public static Guid GetUserId(this ClaimsPrincipal principal)
|
||||
{
|
||||
var value = principal.FindFirstValue(JwtRegisteredClaimNames.Sub)
|
||||
?? principal.FindFirstValue(ClaimTypes.NameIdentifier)
|
||||
?? principal.FindFirstValue("sub");
|
||||
if (value is not null && Guid.TryParse(value, out var id))
|
||||
{
|
||||
return id;
|
||||
}
|
||||
throw new UnauthorizedAccessException("Invalid user identity");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user