Beginnings of Core Auth

This commit is contained in:
2026-04-30 19:08:37 -04:00
parent dd1aa45f6e
commit 33eee17c43
4 changed files with 98 additions and 10 deletions

View File

@@ -0,0 +1,57 @@
using RelayCore.Services;
namespace RelayCore.Endpoints;
public static class AuthEndpoints
{
public static void MapAuthEndpoints(this WebApplication app)
{
app.MapPost("/user/signin", async (AuthSignin request, APIAuthService service) =>
{
var token = await service.UserSigninAsync(request);
return token != null ? Results.Ok(token) : Results.Unauthorized();
});
app.MapPost("/user/register", async (AuthRegister request, APIAuthService service) =>
{
throw new NotImplementedException();
return Results.Ok();
});
app.MapPost("/server/verify/user", async (AuthUserVerify request, APIAuthService service) =>
{
throw new NotImplementedException();
});
app.MapPost("/server/user/profile", async (AuthUserVerify request, APIAuthService service) =>
{
throw new NotImplementedException();
});
app.MapPost("/server/verify/license", async (AuthServerLicense request, APIAuthService service) =>
{
throw new NotImplementedException();
});
}
}
public class AuthSignin
{
public string UserName { get; set; }
public string Password { get; set; }
}
public class AuthRegister
{
public string Username { get; set; }
public string Password { get; set; }
public string Email { get; set; }
}
public class AuthUserVerify
{
public string Username { get; set; }
public string Token { get; set; }
}
public class AuthServerLicense
{
public string License { get; set; }
}

View File

@@ -1,14 +1,13 @@
using SurrealDb.Net; using SurrealDb.Net;
using SurrealDb.Net.Models.Auth; using SurrealDb.Net.Models.Auth;
using System.Text.Json; using System.Text.Json;
using System;
using System.Net; using System.Net;
using System.Threading.Tasks;
using System.Text; using System.Text;
using System.Text.Json;
using RelayCore.Enums; using RelayCore.Enums;
using RelayCore.Models; using RelayCore.Models;
using RelayCore.Endpoints;
using RelayCore.Services;
await using var db = new SurrealDbClient("ws://127.0.0.1:8000/rpc"); await using var db = new SurrealDbClient("ws://127.0.0.1:8000/rpc");
@@ -25,8 +24,24 @@ Console.WriteLine($"Keeper created: {ToJsonString(keeper)}");
Console.WriteLine($"Kira created: {ToJsonString(kira)}"); Console.WriteLine($"Kira created: {ToJsonString(kira)}");
Console.WriteLine($"Test created: {ToJsonString(test)}"); Console.WriteLine($"Test created: {ToJsonString(test)}");
await server.Main(db); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton(db);
builder.Services.AddScoped<APIAuthService>();
var app = builder.Build();
app.MapGet("/", () => "Auth Server Running!");
app.MapAuthEndpoints();
// await server.Main(db);
await app.StartAsync();
Console.WriteLine("API Started");
Console.WriteLine("\n\n\n");
Console.Write("Press any key to stop.");
Console.ReadKey(true); Console.ReadKey(true);
await app.StopAsync();
return; return;
static string ToJsonString(object? o) static string ToJsonString(object? o)
@@ -65,7 +80,6 @@ static async Task<Users> CreateUserAsync(SurrealDbClient db, string username, st
return updated; return updated;
} }
partial class Program partial class Program
{ {
public async Task Main(SurrealDbClient db) public async Task Main(SurrealDbClient db)

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
@@ -10,11 +10,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.1" /> <PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.9" />
<PackageReference Include="SurrealDb.Net" Version="0.9.0" /> <PackageReference Include="SurrealDb.Net" Version="0.9.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>
</Project> </Project>

View File

@@ -0,0 +1,20 @@
using RelayCore.Endpoints;
using SurrealDb.Net;
namespace RelayCore.Services;
public class APIAuthService(SurrealDbClient db)
{
private readonly SurrealDbClient _db = db;
public async Task<object?> GetUsersAsync()
{
throw new NotImplementedException();
}
public async Task<object?> UserSigninAsync(AuthSignin request)
{
throw new NotImplementedException();
}
}