Initial QMAX production app
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace QMax.Api.Infrastructure.Auth;
|
||||
|
||||
public static class UserContext
|
||||
{
|
||||
public static Guid GetUserId(this ClaimsPrincipal principal)
|
||||
{
|
||||
var value = principal.FindFirstValue(ClaimTypes.NameIdentifier)
|
||||
?? principal.FindFirstValue("sub")
|
||||
?? throw new InvalidOperationException("Authenticated user id is missing.");
|
||||
return Guid.Parse(value);
|
||||
}
|
||||
|
||||
public static Guid? GetSessionId(this ClaimsPrincipal principal)
|
||||
{
|
||||
var value = principal.FindFirstValue("sid");
|
||||
return Guid.TryParse(value, out var id) ? id : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user