summaryrefslogtreecommitdiff
path: root/VPNAuth.Server/Pages
diff options
context:
space:
mode:
Diffstat (limited to 'VPNAuth.Server/Pages')
-rw-r--r--VPNAuth.Server/Pages/Auth.cshtml31
-rw-r--r--VPNAuth.Server/Pages/Auth.cshtml.cs52
-rw-r--r--VPNAuth.Server/Pages/Dashboard.cshtml41
3 files changed, 124 insertions, 0 deletions
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;
+}
+
+<!DOCTYPE html>
+
+<html>
+<head>
+ <title>VPNAuth - Auth</title>
+</head>
+<body style="text-align: center;">
+ <h1>Authorization</h1>
+ <h2>VPNAuth</h2>
+ @if (Model.ValidRequest)
+ {
+ <div>
+ <p>Do you want to log into <i>@Request.Query["client_id"]</i>?</p>
+ <button onclick="window.location = '/accept-auth/@Model.RequestEntry?.Entity.Id'">Yes</button>
+ <br/>
+ <p>You are logged in as <i>@Model.User?.Username</i>.</p>
+ </div>
+ }
+ else
+ {
+ <b>Invalid request.</b>
+ }
+</body>
+</html>
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<AuthRequest>? RequestEntry;
+
+ public readonly List<string> 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();
+}
+
+<!DOCTYPE html>
+
+<html>
+<head>
+ <title>VPNAuth - Dashboard</title>
+</head>
+<body style="text-align: center;">
+ @if (user == null)
+ {
+ <p>No user detected</p>
+ }
+ else
+ {
+ <div>
+ <h1>Dashboard</h1>
+ <h2>VPNAuth</h2>
+ <p>Hey, @user.Username!</p>
+ <i>User settings coming soon...</i>
+ <h3>Your IPs</h3>
+ <ul style="list-style-position: inside;">
+ @foreach (var ip in user.Ips!)
+ {
+ <li>@ip</li>
+ }
+ </ul>
+ </div>
+ }
+</body>
+</html>