mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 16:55:37 +02:00
## Description <!-- Briefly describe the purpose and scope of your changes --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Upgraded API and authentication services with dynamic scaling, enhanced load balancing, and real-time interaction endpoints. - Introduced new commands to streamline local development and container builds. - Added new endpoints for retrieving Steam account information and managing connections. - Implemented a QR code authentication interface for Steam, enhancing user login experiences. - **Database Updates** - Rolled out comprehensive schema migrations that improve data integrity and indexing. - Introduced new tables for managing Steam user credentials and machine information. - **UI Enhancements** - Added refreshed animated assets and an improved QR code login flow for a more engaging experience. - Introduced new styled components for displaying friends and games. - **Maintenance** - Completed extensive refactoring and configuration updates to optimize performance and development workflows. - Updated logging configurations and improved error handling mechanisms. - Streamlined resource definitions in the configuration files. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
118 lines
4.5 KiB
C#
118 lines
4.5 KiB
C#
namespace Steam
|
|
{
|
|
public class Program
|
|
{
|
|
const string UnixSocketPath = "/tmp/steam.sock";
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
// Delete the socket file if it exists
|
|
if (File.Exists(UnixSocketPath))
|
|
{
|
|
File.Delete(UnixSocketPath);
|
|
}
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Configure Kestrel to listen on Unix socket
|
|
builder.WebHost.ConfigureKestrel(options =>
|
|
{
|
|
options.ListenUnixSocket(UnixSocketPath);
|
|
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(10);
|
|
options.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(5);
|
|
});
|
|
|
|
builder.Services.AddControllers();
|
|
builder.Services.AddSingleton<SteamAuthService>();
|
|
|
|
var app = builder.Build();
|
|
|
|
// Health check endpoint
|
|
app.MapGet("/", () => "Steam Auth Service is running");
|
|
|
|
// QR Code login endpoint with Server-Sent Events
|
|
app.MapGet("/api/steam/login", async (HttpResponse response, SteamAuthService steamService) =>
|
|
{
|
|
// Generate a unique session ID for this login attempt
|
|
string sessionId = Guid.NewGuid().ToString();
|
|
|
|
Console.WriteLine($"Starting new login session: {sessionId}");
|
|
|
|
// Set up SSE response
|
|
response.Headers.Append("Content-Type", "text/event-stream");
|
|
response.Headers.Append("Cache-Control", "no-cache");
|
|
response.Headers.Append("Connection", "keep-alive");
|
|
|
|
try
|
|
{
|
|
// Start QR login session with SSE updates
|
|
await steamService.StartQrLoginSessionAsync(response, sessionId);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error in login session {sessionId}: {ex.Message}");
|
|
|
|
// Send error message as SSE
|
|
await response.WriteAsync($"event: error\n");
|
|
await response.WriteAsync($"data: {{\"message\":\"{ex.Message}\"}}\n\n");
|
|
await response.Body.FlushAsync();
|
|
}
|
|
});
|
|
|
|
// Login with credentials endpoint (returns JSON)
|
|
app.MapPost("/api/steam/login-with-credentials", async (LoginCredentials credentials, SteamAuthService steamService) =>
|
|
{
|
|
if (string.IsNullOrEmpty(credentials.Username) || string.IsNullOrEmpty(credentials.RefreshToken))
|
|
{
|
|
return Results.BadRequest("Username and refresh token are required");
|
|
}
|
|
|
|
try
|
|
{
|
|
var result = await steamService.LoginWithCredentialsAsync(
|
|
credentials.Username,
|
|
credentials.RefreshToken);
|
|
|
|
return Results.Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error logging in with credentials: {ex.Message}");
|
|
return Results.Problem(ex.Message);
|
|
}
|
|
});
|
|
|
|
// Get user info endpoint (returns JSON)
|
|
app.MapGet("/api/steam/user", async (HttpRequest request, SteamAuthService steamService) =>
|
|
{
|
|
// Get credentials from headers
|
|
var username = request.Headers["X-Steam-Username"].ToString();
|
|
var refreshToken = request.Headers["X-Steam-Token"].ToString();
|
|
|
|
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(refreshToken))
|
|
{
|
|
return Results.BadRequest("Username and refresh token headers are required");
|
|
}
|
|
|
|
try
|
|
{
|
|
var userInfo = await steamService.GetUserInfoAsync(username, refreshToken);
|
|
return Results.Ok(userInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error getting user info: {ex.Message}");
|
|
return Results.Problem(ex.Message);
|
|
}
|
|
});
|
|
|
|
app.Run();
|
|
}
|
|
}
|
|
|
|
public class LoginCredentials
|
|
{
|
|
public string Username { get; set; } = string.Empty;
|
|
public string RefreshToken { get; set; } = string.Empty;
|
|
}
|
|
} |