mirror of
https://github.com/achiez/NebulaAuth-Steam-Desktop-Authenticator-by-Achies.git
synced 2026-07-25 06:14:31 +00:00
8ff960189e
- Update: Added "Copy Password" to Mafile context menu (if available) - Update: "Save Password" now pre-fills the current password in the "Login Again" dialog when encryption is enabled - Fix: Prevented overlapping confirmation cycles in AutoConfirmer - Fix: Added a Snackbar notification when a confirmation cycle is skipped due to a too frequent timer interval - Fix: Fixed a rare bug where the previous proxy was used instead of the current one during session refresh - Fix: Corrected "Session Permanently Expired" message showing on unrelated errors (e.g. network issues) - UI-Fix: Fixed visual glitch where proxy input appeared non-empty when switching to a mafile-specific proxy - Cleanup: Refactored and cleaned up codebase, improved styling and formatting via ReSharper
97 lines
3.1 KiB
C#
97 lines
3.1 KiB
C#
using JetBrains.Annotations;
|
|
using Microsoft.Extensions.Options;
|
|
using SteamLib.Core.Enums;
|
|
using SteamLib.Core.Interfaces;
|
|
using SteamLib.Core.Models;
|
|
using SteamLib.Exceptions;
|
|
|
|
namespace SteamLib.Authentication;
|
|
|
|
public static class SessionDataValidator
|
|
{
|
|
[PublicAPI] public static Dictionary<Type, IValidateOptions<ISessionData>> Validators { get; } = new();
|
|
|
|
public static ValidateOptionsResult Validate(string? name, ISessionData data)
|
|
{
|
|
if (Validators.TryGetValue(data.GetType(), out var validator))
|
|
return validator.Validate(name, data);
|
|
|
|
return Validate(data);
|
|
}
|
|
|
|
public static ValidateOptionsResult Validate<T>(string? name, T data) where T : ISessionData
|
|
{
|
|
if (Validators.TryGetValue(typeof(T), out var validator))
|
|
return validator.Validate(name, data);
|
|
|
|
return Validate(data);
|
|
}
|
|
|
|
|
|
private static ValidateOptionsResult Validate(ISessionData data)
|
|
{
|
|
if (data == null!)
|
|
{
|
|
return ValidateOptionsResult.Fail("SessionData cannot be null");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(data.SessionId))
|
|
{
|
|
return ValidateOptionsResult.Fail("SessionId cannot be null or empty");
|
|
}
|
|
|
|
if (data.SteamId.Steam64.Id < SteamId64.SEED)
|
|
{
|
|
return ValidateOptionsResult.Fail($"SteamId '{data.SteamId.Steam64}' is invalid.");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(data.RefreshToken.Token))
|
|
{
|
|
return ValidateOptionsResult.Fail("RefreshToken cannot be null or empty");
|
|
}
|
|
|
|
if (data.RefreshToken.SteamId.Steam64.Id < SteamId64.SEED)
|
|
{
|
|
return ValidateOptionsResult.Fail($"SteamId in RefreshToken '{data.SteamId.Steam64}' is invalid.");
|
|
}
|
|
|
|
|
|
if (data is IMobileSessionData && data.RefreshToken.Type != SteamAccessTokenType.MobileRefresh)
|
|
{
|
|
return ValidateOptionsResult.Fail($"RefreshToken '{data.RefreshToken.Token}' is not of type MobileRefresh");
|
|
}
|
|
|
|
if (data.RefreshToken.Type is not (SteamAccessTokenType.Refresh or SteamAccessTokenType.MobileRefresh))
|
|
{
|
|
return ValidateOptionsResult.Fail(
|
|
$"RefreshToken '{data.RefreshToken.Token}' is not of type Refresh or MobileRefresh");
|
|
}
|
|
|
|
if (data.RefreshToken.Expires.ToLong() == 0L)
|
|
{
|
|
return ValidateOptionsResult.Fail($"RefreshToken '{data.RefreshToken.Token}' has invalid expiration date");
|
|
}
|
|
|
|
|
|
return ValidateOptionsResult.Success;
|
|
}
|
|
|
|
public static bool IsValid(this ISessionData data)
|
|
{
|
|
return Validate(null, data).Succeeded;
|
|
}
|
|
|
|
public static void EnsureValidated(this ISessionData data)
|
|
{
|
|
if (data.IsValid == true) return;
|
|
if (data.IsValid == false)
|
|
throw new SessionInvalidException(
|
|
"SessionData was validated before and validation was not passed. Session is invalid");
|
|
var validation = Validate(null, data);
|
|
data.IsValid = validation.Succeeded;
|
|
if (validation.Failed)
|
|
{
|
|
throw new SessionInvalidException("SessionData is invalid. " + validation.FailureMessage);
|
|
}
|
|
}
|
|
} |