blob: 211d1f6fd8f7408ead8cbc03119d1bb4ba680375 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
using System.Security.Claims;
namespace I2R.Storage.Api.Endpoints;
[ApiController]
[Authorize]
public class Base : ControllerBase
{
public class LoggedInUserModel
{
public string Username { get; set; }
public Guid Id { get; set; }
public EUserRole Role { get; set; }
public class Public
{
public string Id { get; set; }
public string Username { get; set; }
public string Role { get; set; }
}
public Public ForThePeople(HttpContext httpContext) {
return new Public() {
Id = httpContext.User.FindFirstValue(AppClaims.USER_ID),
Username = httpContext.User.FindFirstValue(AppClaims.USERNAME),
Role = httpContext.User.FindFirstValue(AppClaims.USER_ROLE)
};
}
}
public LoggedInUserModel LoggedInUser => new LoggedInUserModel() {
Id = HttpContext.User.FindFirstValue(AppClaims.USER_ID).AsGuid(),
Username = HttpContext.User.FindFirstValue(AppClaims.USERNAME),
Role = UserRole.FromString(HttpContext.User.FindFirstValue(AppClaims.USER_ROLE))
};
}
|