From c0f73080d2b02e1521e0515d33497d45e71aad5c Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Mon, 3 Feb 2025 13:34:50 -0700 Subject: [PATCH] Add APIAuth Role --- Controllers/ErrorController.cs | 2 +- Middleware/Authen.cs | 4 +++- Views/Home/Index.cshtml | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Controllers/ErrorController.cs b/Controllers/ErrorController.cs index bd753f2..aaeb7c6 100644 --- a/Controllers/ErrorController.cs +++ b/Controllers/ErrorController.cs @@ -6,7 +6,7 @@ namespace CarCareTracker.Controllers { public IActionResult Unauthorized() { - if (!User.IsInRole("CookieAuth")) + if (User.IsInRole("APIAuth")) { Response.StatusCode = 403; return new EmptyResult(); diff --git a/Middleware/Authen.cs b/Middleware/Authen.cs index aca0d0b..32e86ab 100644 --- a/Middleware/Authen.cs +++ b/Middleware/Authen.cs @@ -75,7 +75,9 @@ namespace CarCareTracker.Middleware var userIdentity = new List { new(ClaimTypes.Name, splitString[0]), - new(ClaimTypes.NameIdentifier, userData.Id.ToString()) + new(ClaimTypes.NameIdentifier, userData.Id.ToString()), + new(ClaimTypes.Email, userData.EmailAddress), + new(ClaimTypes.Role, "APIAuth") }; if (userData.IsAdmin) { diff --git a/Views/Home/Index.cshtml b/Views/Home/Index.cshtml index 16c843d..2738f67 100644 --- a/Views/Home/Index.cshtml +++ b/Views/Home/Index.cshtml @@ -33,7 +33,7 @@ - @if (User.IsInRole("CookieAuth")) + @if (User.IsInRole("CookieAuth") || User.IsInRole("APIAuth")) { @if (User.IsInRole(nameof(UserData.IsAdmin))) { @@ -84,7 +84,7 @@ - @if (User.IsInRole("CookieAuth")) + @if (User.IsInRole("CookieAuth") || User.IsInRole("APIAuth")) {