aboutsummaryrefslogtreecommitdiff
path: root/VPNAuth.Server/Pages
diff options
context:
space:
mode:
Diffstat (limited to 'VPNAuth.Server/Pages')
-rw-r--r--VPNAuth.Server/Pages/Auth.cshtml26
-rw-r--r--VPNAuth.Server/Pages/Auth.cshtml.cs10
-rw-r--r--VPNAuth.Server/Pages/Settings.cshtml (renamed from VPNAuth.Server/Pages/Dashboard.cshtml)42
3 files changed, 52 insertions, 26 deletions
diff --git a/VPNAuth.Server/Pages/Auth.cshtml b/VPNAuth.Server/Pages/Auth.cshtml
index 5ac8efe..3b7c7c8 100644
--- a/VPNAuth.Server/Pages/Auth.cshtml
+++ b/VPNAuth.Server/Pages/Auth.cshtml
@@ -10,22 +10,38 @@
<html>
<head>
<title>VPNAuth - Auth</title>
+ <link rel="stylesheet" href="/static/style.css">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
-<body style="text-align: center;">
+<body>
<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>
+ <p>Do you want to log into <i>@Request.Query["client_id"]</i> as user <i>@Model.User?.Username</i>?</p>
+ <p>Requested scopes:</p>
+ <ul>
+ @foreach (var scope in Model.RequestEntry!.Entity.Scopes)
+ {
+ <li>@scope</li>
+ }
+ </ul>
+ <button class="button primary"
+ onclick="window.location = '/accept-auth/@Model.RequestEntry?.Entity.Id'">Yes
+ </button>
+ <button class="button error"
+ onclick="window.location = '@(Model.Config.FindApp(Request.Query["client_id"]!)!.RedirectUri
+ + "?error=access_denied")'">No</button>
<br/>
- <p>You are logged in as <i>@Model.User?.Username</i>.</p>
</div>
}
else
{
<b>Invalid request.</b>
}
+
+ <footer>
+ <p style="margin-top: 5em;"><a target="_blank" href="https://bytim.eu/projects/VPNAuth/">VPNAuth</a> by Tim</p>
+ </footer>
</body>
</html>
diff --git a/VPNAuth.Server/Pages/Auth.cshtml.cs b/VPNAuth.Server/Pages/Auth.cshtml.cs
index bdcbc59..ea648cb 100644
--- a/VPNAuth.Server/Pages/Auth.cshtml.cs
+++ b/VPNAuth.Server/Pages/Auth.cshtml.cs
@@ -7,6 +7,7 @@ namespace VPNAuth.Server.Pages;
public class Auth : PageModel
{
public Config Config;
+ public ConfigApp? ConfApp;
public ConfigUser? User;
public bool ValidRequest;
public EntityEntry<AuthRequest>? RequestEntry;
@@ -23,12 +24,14 @@ public class Auth : PageModel
public void OnGet()
{
Config = Config.Read();
+ ConfApp = Config.FindApp(Request.Query["client_id"]);
User = HttpContext.GetUser();
ValidRequest = RequiredQueryParams.All(key => Request.Query.ContainsKey(key))
- && Config.FindApp(Request.Query["client_id"]!) != null
+ && ConfApp != null
&& Request.Query["code_challenge_method"] == "S256"
- && User != null;
+ && User != null
+ && (ConfApp.AllowedUsers == null || ConfApp.AllowedUsers!.Contains(User.Username!));
RequestEntry = null;
@@ -44,7 +47,8 @@ public class Auth : PageModel
Scopes = Request.Query["scope"].ToString().Split(" ").ToList(),
CodeChallenge = Request.Query["code_challenge"]!,
CodeChallengeMethod = Request.Query["code_challenge_method"]!,
- Accepted = false
+ Accepted = false,
+ Username = User!.Username!
});
db.SaveChanges();
}
diff --git a/VPNAuth.Server/Pages/Dashboard.cshtml b/VPNAuth.Server/Pages/Settings.cshtml
index 38f9c7e..c706e98 100644
--- a/VPNAuth.Server/Pages/Dashboard.cshtml
+++ b/VPNAuth.Server/Pages/Settings.cshtml
@@ -5,7 +5,6 @@
@{
Layout = null;
- string remoteIp = Request.HttpContext.GetRemoteIpAddress();
ConfigUser? configUser = Request.HttpContext.GetUser();
UserInformation? dbUser = null;
@@ -21,26 +20,25 @@
<html>
<head>
- <title>VPNAuth - Dashboard</title>
+ <title>VPNAuth - Settings</title>
+ <link rel="stylesheet" href="/static/style.css">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
-<body style="text-align: center;">
+<body>
@if (configUser == null)
{
- <p>No user detected</p>
+ <p>No user detected with IP <code>@Request.HttpContext.GetRemoteIpAddress()</code>.</p>
}
else
{
<div>
- <h1>Dashboard</h1>
- <h2>VPNAuth</h2>
- <p>Hey, @configUser.Username!</p>
- <h3>User settings</h3>
- <form hx-post="/user-info" hx-swap="none" hx-trigger="change">
- <table style="margin-left: auto; margin-right: auto;">
+ <h1>Settings</h1>
+ <form hx-post="/user-info-settings" hx-swap="none" hx-trigger="change">
+ <table>
<tbody>
<tr>
<th>Username</th>
- <th style="text-align: left; font-weight: normal;">@dbUser?.Sub</th>
+ <th class="normal">@dbUser?.Sub</th>
</tr>
<tr>
<th><label for="given-name">Given name</label></th>
@@ -67,18 +65,26 @@
<th><input name="picture" id="picture" type="url"
value="@dbUser?.Picture"/></th>
</tr>
+ <tr>
+ <th>IPs</th>
+ <th class="normal">
+ <ul>
+ @foreach (var ip in configUser.Ips!)
+ {
+ <li>@ip</li>
+ }
+ </ul>
+ </th>
+ </tr>
</tbody>
</table>
</form>
- <h3>Your IPs</h3>
- <ul style="list-style-position: inside;">
- @foreach (var ip in configUser.Ips!)
- {
- <li>@ip</li>
- }
- </ul>
</div>
}
+
+ <footer>
+ <p style="margin-top: 5em;"><a target="_blank" href="https://bytim.eu/projects/VPNAuth/">VPNAuth</a> by Tim</p>
+ </footer>
<script src="/static/htmx.js"></script>
</body>
</html>