Compare commits
2 Commits
CoreAuth
...
4974663128
| Author | SHA1 | Date | |
|---|---|---|---|
| 4974663128 | |||
| 3901542141 |
@@ -54,7 +54,9 @@ window.addEventListener("load", async () => {
|
|||||||
function testIndex(rawJson)
|
function testIndex(rawJson)
|
||||||
{
|
{
|
||||||
const data = typeof rawJson === "string" ? JSON.parse(rawJson) : rawJson;
|
const data = typeof rawJson === "string" ? JSON.parse(rawJson) : rawJson;
|
||||||
data.sdp = data.sdp.replaceAll("(rn)", "\r\n");
|
if (data.sdp) {
|
||||||
|
data.sdp = data.sdp.replaceAll("(rn)", "\r\n");
|
||||||
|
}
|
||||||
handleRtcSignal(JSON.stringify(data));
|
handleRtcSignal(JSON.stringify(data));
|
||||||
// if (data.type === "rtc_offer") {
|
// if (data.type === "rtc_offer") {
|
||||||
// handleOffer(data)
|
// handleOffer(data)
|
||||||
|
|||||||
@@ -140,7 +140,13 @@ async function handleIce(msg) {
|
|||||||
|
|
||||||
if (!msg.candidate) return;
|
if (!msg.candidate) return;
|
||||||
|
|
||||||
await pc.addIceCandidate(msg.candidate);
|
const candidateInit = {
|
||||||
|
candidate: msg.candidate,
|
||||||
|
sdpMid: msg.sdpMid,
|
||||||
|
sdpMLineIndex: msg.sdpMLineIndex
|
||||||
|
};
|
||||||
|
|
||||||
|
await pc.addIceCandidate(candidateInit);
|
||||||
|
|
||||||
LogMessage(`Applied ICE from ${msg.from}`);
|
LogMessage(`Applied ICE from ${msg.from}`);
|
||||||
}
|
}
|
||||||
@@ -161,7 +167,9 @@ async function ensurePeerConnectionForUser(username) {
|
|||||||
channelId: currentChannelId,
|
channelId: currentChannelId,
|
||||||
from: currentUsername,
|
from: currentUsername,
|
||||||
to: username,
|
to: username,
|
||||||
candidate: JSON.stringify(event.candidate)
|
candidate: event.candidate.candidate,
|
||||||
|
sdpMid: event.candidate.sdpMid,
|
||||||
|
sdpMLineIndex: event.candidate.sdpMLineIndex
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
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, HttpContext context) =>
|
|
||||||
{
|
|
||||||
var ip = context.Connection.RemoteIpAddress?.MapToIPv4().ToString();
|
|
||||||
context.Request.Headers.TryGetValue("User-Agent", out var userAgent);
|
|
||||||
|
|
||||||
Console.WriteLine($"IP:{ip}\nUserAgent:{userAgent}");
|
|
||||||
// var token = await service.UserSigninAsync(request, ip, userAgent);
|
|
||||||
|
|
||||||
// return token != null ? Results.Ok(token) : Results.Unauthorized();
|
|
||||||
return Results.Ok();
|
|
||||||
});
|
|
||||||
app.MapPost("/user/register", async (AuthRegister request, APIAuthService service) =>
|
|
||||||
{
|
|
||||||
var token = await service.UserRegisterAsync(request);
|
|
||||||
return token != null ? Results.Ok(token) : Results.Unauthorized();
|
|
||||||
});
|
|
||||||
app.MapPost("/server/verify/user", async (AuthUserVerify request, APIAuthService service) =>
|
|
||||||
{
|
|
||||||
bool valid = await service.ServerVerifyUser(request);
|
|
||||||
return Results.Ok(valid);
|
|
||||||
});
|
|
||||||
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; }
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,7 @@ namespace RelayCore.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of threads to use for parallel computation
|
/// Number of threads to use for parallel computation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const int DegreeOfParallelism = 2;
|
private const int DegreeOfParallelism = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of iterations for the Argon2id algorithm
|
/// Number of iterations for the Argon2id algorithm
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace RelayCore.Models;
|
|||||||
|
|
||||||
public class Sessions : Record
|
public class Sessions : Record
|
||||||
{
|
{
|
||||||
public required RecordId UserId { get; set; }
|
public required string UserId { get; set; }
|
||||||
public required string TokenHash { get; set; }
|
public required string TokenHash { get; set; }
|
||||||
public required DateTime IssuedAt { get; set; }
|
public required DateTime IssuedAt { get; set; }
|
||||||
public required DateTime ExpiresAt { get; set; }
|
public required DateTime ExpiresAt { get; set; }
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
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");
|
||||||
@@ -24,25 +25,8 @@ 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)}");
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
await server.Main(db);
|
||||||
builder.WebHost.UseUrls("http://127.0.0.1:1337/");
|
|
||||||
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)
|
||||||
@@ -67,7 +51,7 @@ static async Task<Users> CreateUserAsync(SurrealDbClient db, string username, st
|
|||||||
OnlineStatus = (int)OnlineStatuses.Online,
|
OnlineStatus = (int)OnlineStatuses.Online,
|
||||||
};
|
};
|
||||||
|
|
||||||
var created = await db.Create("auth_users", user);
|
var created = await db.Create("users", user);
|
||||||
|
|
||||||
var hasher = new PasswordHasher();
|
var hasher = new PasswordHasher();
|
||||||
var passwordHash = hasher.HashPassword(created.Id.ToString() + rawPassword);
|
var passwordHash = hasher.HashPassword(created.Id.ToString() + rawPassword);
|
||||||
@@ -81,6 +65,7 @@ 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)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
@@ -10,12 +10,11 @@
|
|||||||
|
|
||||||
<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>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\RelayShared\RelayShared.csproj" />
|
<Folder Include="Services\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
using RelayCore.Endpoints;
|
|
||||||
using RelayCore.Models;
|
|
||||||
using SurrealDb.Net;
|
|
||||||
using SurrealDb.Net.Models;
|
|
||||||
|
|
||||||
namespace RelayCore.Services;
|
|
||||||
|
|
||||||
public class APIAuthService(SurrealDbClient _db)
|
|
||||||
{
|
|
||||||
|
|
||||||
public async Task<string> UserSigninAsync(AuthSignin request)
|
|
||||||
{
|
|
||||||
var hasher = new PasswordHasher();
|
|
||||||
var users = await _db.Select<Users>("auth_users");
|
|
||||||
var user = users.FirstOrDefault(x => (x.Username == request.UserName || x.Email == request.UserName)
|
|
||||||
&& hasher.VerifyPassword(request.Password, x.Password));
|
|
||||||
var tokens = await _db.Select<Sessions>("auth_sessions");
|
|
||||||
var token = tokens.Where(x => x.UserId == user.Id && !x.Revoked).OrderByDescending(x => x.ExpiresAt).FirstOrDefault();
|
|
||||||
if (token.ExpiresAt > DateTime.UtcNow)
|
|
||||||
return token.TokenHash;
|
|
||||||
|
|
||||||
//TODO: Generate TOKEN
|
|
||||||
var newToken = hasher.HashPassword($"{user.Email}{user.Username}{user.Password}");
|
|
||||||
//TODO: Store TOKEN and Username for verification
|
|
||||||
var sessionId = await _db.Create<Sessions>(new Sessions
|
|
||||||
{
|
|
||||||
UserId = user.Id,
|
|
||||||
TokenHash = newToken,
|
|
||||||
IssuedAt = DateTime.UtcNow,
|
|
||||||
ExpiresAt = DateTime.UtcNow.AddDays(30),
|
|
||||||
DeviceName = "",
|
|
||||||
Revoked = false,
|
|
||||||
IpAddress = "",
|
|
||||||
UserAgent = ""
|
|
||||||
});
|
|
||||||
//TODO: Add invalidation to TOKENs
|
|
||||||
return newToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<string> UserRegisterAsync(AuthRegister request)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> ServerVerifyUser(AuthUserVerify request)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -21,7 +21,6 @@ var bootstrapService = new ServerBootstrapService(db, coreClient, cryptoService)
|
|||||||
await bootstrapService.InitializeAsync();
|
await bootstrapService.InitializeAsync();
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
builder.WebHost.UseUrls("http://127.0.0.1:5000/");
|
|
||||||
|
|
||||||
builder.Services.AddSingleton(db);
|
builder.Services.AddSingleton(db);
|
||||||
builder.Services.AddScoped<RtcCallService>();
|
builder.Services.AddScoped<RtcCallService>();
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ Start-Sleep -Seconds 5
|
|||||||
|
|
||||||
$testScript = New-TabScript -Name "Test" -Content @"
|
$testScript = New-TabScript -Name "Test" -Content @"
|
||||||
Set-Location '$root'
|
Set-Location '$root'
|
||||||
Start-Sleep -Seconds 25
|
Start-Sleep -Seconds 5
|
||||||
& '$clientExe' --user Test
|
& '$clientExe' --user Test
|
||||||
"@
|
"@
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user