summaryrefslogtreecommitdiffstats
path: root/src/server/Api/V1/BaseV1Route.cs
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-01-23 11:41:42 +0100
committerivarlovlie <git@ivarlovlie.no>2022-01-23 14:33:05 +0100
commitce86d103039b22695b04714ee85e9ef3e1e032b5 (patch)
tree557455780de06ceb95dd556ca5ffca0208a1f8ba /src/server/Api/V1/BaseV1Route.cs
parent89816382424e59ad953b433fbf82c925741b3136 (diff)
downloadbookmark-thing-ce86d103039b22695b04714ee85e9ef3e1e032b5.tar.xz
bookmark-thing-ce86d103039b22695b04714ee85e9ef3e1e032b5.zip
feat(auth): Implements first draft of basic auth gen/validation
Diffstat (limited to 'src/server/Api/V1/BaseV1Route.cs')
-rw-r--r--src/server/Api/V1/BaseV1Route.cs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/server/Api/V1/BaseV1Route.cs b/src/server/Api/V1/BaseV1Route.cs
index ba7d978..b1e2128 100644
--- a/src/server/Api/V1/BaseV1Route.cs
+++ b/src/server/Api/V1/BaseV1Route.cs
@@ -1,3 +1,5 @@
+using System.Net.Http.Headers;
+
namespace IOL.BookmarkThing.Server.Api.V1;
/// <inheritdoc />
@@ -14,4 +16,23 @@ public class BaseV1Route : ControllerBase
Username = User.Identity?.Name,
Id = User.Claims.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value.ToGuid() ?? default
};
+
+ protected bool IsApiCall() {
+ if (!Request.Headers.ContainsKey("Authorization")) return false;
+ try {
+ var authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]);
+ if (authHeader.Parameter == null) return false;
+ } catch (Exception e) {
+ return false;
+ }
+
+ return true;
+ }
+
+ protected bool HasApiPermission(string permission_key) {
+ var permission_claim = User.Claims.SingleOrDefault(c => c.Type == permission_key);
+ return permission_claim is {
+ Value: "True"
+ };
+ }
}