aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/Endpoints/Base.cs
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-12-21 23:37:23 +0100
committerivarlovlie <git@ivarlovlie.no>2022-12-21 23:37:23 +0100
commit82ade3c31fb17b662feec59e9e654ceb66edbb7a (patch)
tree26443c41c55d2cd2ae46fdd0d663aca84b779ffe /code/api/Endpoints/Base.cs
parente60703aadca7d423c0fbfb189d5ef439fc1df072 (diff)
downloadstorage-82ade3c31fb17b662feec59e9e654ceb66edbb7a.tar.xz
storage-82ade3c31fb17b662feec59e9e654ceb66edbb7a.zip
feat: Add initial schema and start login
Diffstat (limited to 'code/api/Endpoints/Base.cs')
-rw-r--r--code/api/Endpoints/Base.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/code/api/Endpoints/Base.cs b/code/api/Endpoints/Base.cs
new file mode 100644
index 0000000..211d1f6
--- /dev/null
+++ b/code/api/Endpoints/Base.cs
@@ -0,0 +1,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))
+ };
+} \ No newline at end of file