Add Steam auth, platform validators & name gen
This commit is contained in:
48
RecNet.Infrastructure/Services/Steam/SteamAuthValidator.cs
Normal file
48
RecNet.Infrastructure/Services/Steam/SteamAuthValidator.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using RecNet.Application.Common.Interfaces;
|
||||
using RecNet.Application.Common.PlatformAuth;
|
||||
using RecNet.Domain.Common;
|
||||
|
||||
namespace RecNet.Infrastructure.Services.Steam;
|
||||
|
||||
public class SteamAuthValidator(ISteamAuthService steamAuthService) : IPlatformAuthValidator
|
||||
{
|
||||
public PlatformType PlatformType
|
||||
=> PlatformType.Steamworks;
|
||||
|
||||
public async Task<PlatformAuthResult> ValidateAsync(
|
||||
string platformAuthentication,
|
||||
string platformId,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var steamParams = JsonSerializer.Deserialize<SteamPlatformAuth>(platformAuthentication);
|
||||
if (steamParams == null)
|
||||
return PlatformAuthResult.Failure("Invalid authentication");
|
||||
|
||||
var result = await steamAuthService.AuthorizeAsync(steamParams.Ticket, steamParams.AppId.AppId, ct);
|
||||
|
||||
if (!result.Succeeded || result.SteamId is null)
|
||||
return PlatformAuthResult.Failure("Invalid authentication");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(platformId) &&
|
||||
platformId != result.SteamId)
|
||||
return PlatformAuthResult.Failure("Nice try");
|
||||
|
||||
return PlatformAuthResult.Success(result.DisplayName);
|
||||
}
|
||||
|
||||
private sealed class SteamPlatformAuth
|
||||
{
|
||||
public required string Ticket { get; set; }
|
||||
|
||||
public required SteamAppIdAuth AppId { get; set; }
|
||||
}
|
||||
|
||||
// Splooty, why did you set it up like this ;-;
|
||||
private sealed class SteamAppIdAuth
|
||||
{
|
||||
[JsonPropertyName("m_AppId")]
|
||||
public required uint AppId { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user