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.
19 lines
584 B
C#
19 lines
584 B
C#
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");
|
|
}
|
|
} |