From 4b2ad030fa381662f4b0c2464e97b0d2c5f6a716 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 18 Apr 2025 12:25:59 +0200 Subject: Initial commit --- VPNAuth.Server/Pages/Auth.cshtml | 31 +++++++++++++++++++++ VPNAuth.Server/Pages/Auth.cshtml.cs | 52 +++++++++++++++++++++++++++++++++++ VPNAuth.Server/Pages/Dashboard.cshtml | 41 +++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 VPNAuth.Server/Pages/Auth.cshtml create mode 100644 VPNAuth.Server/Pages/Auth.cshtml.cs create mode 100644 VPNAuth.Server/Pages/Dashboard.cshtml (limited to 'VPNAuth.Server/Pages') diff --git a/VPNAuth.Server/Pages/Auth.cshtml b/VPNAuth.Server/Pages/Auth.cshtml new file mode 100644 index 0000000..5ac8efe --- /dev/null +++ b/VPNAuth.Server/Pages/Auth.cshtml @@ -0,0 +1,31 @@ +@page "/auth" +@model VPNAuth.Server.Pages.Auth + +@{ + Layout = null; +} + + + + + + VPNAuth - Auth + + +

Authorization

+

VPNAuth

+ @if (Model.ValidRequest) + { +
+

Do you want to log into @Request.Query["client_id"]?

+ +
+

You are logged in as @Model.User?.Username.

+
+ } + else + { + Invalid request. + } + + diff --git a/VPNAuth.Server/Pages/Auth.cshtml.cs b/VPNAuth.Server/Pages/Auth.cshtml.cs new file mode 100644 index 0000000..bdcbc59 --- /dev/null +++ b/VPNAuth.Server/Pages/Auth.cshtml.cs @@ -0,0 +1,52 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore.ChangeTracking; +using VPNAuth.Server.Database; + +namespace VPNAuth.Server.Pages; + +public class Auth : PageModel +{ + public Config Config; + public ConfigUser? User; + public bool ValidRequest; + public EntityEntry? RequestEntry; + + public readonly List RequiredQueryParams = + [ + "response_type", + "client_id", + "scope", + "code_challenge_method", + "code_challenge" + ]; + + public void OnGet() + { + Config = Config.Read(); + User = HttpContext.GetUser(); + + ValidRequest = RequiredQueryParams.All(key => Request.Query.ContainsKey(key)) + && Config.FindApp(Request.Query["client_id"]!) != null + && Request.Query["code_challenge_method"] == "S256" + && User != null; + + RequestEntry = null; + + if (ValidRequest) + { + using var db = new Database.Database(); + RequestEntry = db.Add(new AuthRequest + { + InitTime = DateTime.Now, + ClientId = Request.Query["client_id"]!, + Code = PkceUtils.GenerateCode(), + State = Request.Query["state"], + Scopes = Request.Query["scope"].ToString().Split(" ").ToList(), + CodeChallenge = Request.Query["code_challenge"]!, + CodeChallengeMethod = Request.Query["code_challenge_method"]!, + Accepted = false + }); + db.SaveChanges(); + } + } +} diff --git a/VPNAuth.Server/Pages/Dashboard.cshtml b/VPNAuth.Server/Pages/Dashboard.cshtml new file mode 100644 index 0000000..cb00d9f --- /dev/null +++ b/VPNAuth.Server/Pages/Dashboard.cshtml @@ -0,0 +1,41 @@ +@page "/" +@using Microsoft.EntityFrameworkCore.ChangeTracking +@using VPNAuth.Server +@using VPNAuth.Server.Database + +@{ + Layout = null; + + string remoteIp = Request.HttpContext.GetRemoteIpAddress(); + ConfigUser? user = Request.HttpContext.GetUser(); +} + + + + + + VPNAuth - Dashboard + + + @if (user == null) + { +

No user detected

+ } + else + { +
+

Dashboard

+

VPNAuth

+

Hey, @user.Username!

+ User settings coming soon... +

Your IPs

+
    + @foreach (var ip in user.Ips!) + { +
  • @ip
  • + } +
+
+ } + + -- cgit v1.2.3