Skip to content

Commit a5dfab5

Browse files
committed
Simple endpoint to get access token
1 parent 41ec836 commit a5dfab5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/ServerPlatform/serverplatform/APIHandler.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ public static void HandleRequest(HttpListenerContext context)
8080

8181
RespondHTML(context, "<p>Server Platform Backend server</p><p>We recommend that you only port-forward the Frontend to prevent any intrusions.</p><br><p>Made with &#10084;&#65039;</p><p>&copy; 2025 BastionSG</p>");
8282
}
83+
else if (context.Request.HttpMethod == "POST" && context.Request.Url.AbsolutePath == "/auth")
84+
{
85+
string requestBody = new System.IO.StreamReader(context.Request.InputStream, context.Request.ContentEncoding).ReadToEnd();
86+
ConsoleLogging.LogMessage($"User {JObject.Parse(requestBody)["username"]} attempting to authenticate...", "Authentication");
87+
string token = "";
88+
try {
89+
token = UserAuth.AuthenticateUser(JObject.Parse(requestBody)["username"].ToString(), JObject.Parse(requestBody)["password"].ToString());
90+
}
91+
catch (Exception ex)
92+
{
93+
token = ex.Message;
94+
}
95+
finally
96+
{
97+
RespondText(context, token);
98+
}
99+
100+
}
83101
else
84102
{
85103
context.Response.StatusCode = 404;

0 commit comments

Comments
 (0)