mirror of
https://github.com/achiez/NebulaAuth-Steam-Desktop-Authenticator-by-Achies.git
synced 2026-07-25 06:14:31 +00:00
a9fdb58cac
Several methods were added and modified in `Storage.cs`, `MainVM_Groups.cs`, `MainVM_Proxy.cs`, and `ProxyManagerVM.cs` to validate if the data can be saved before performing various operations. The `SnackbarController.cs` was modified to increase the minimum snackbar time and adjust the duration calculation. In `MafileSerializer_SessionData.cs`, the check for whether the refresh token is expired or not was moved to a different location within the code. New localization entries were added in `localization.loc.json`. The changes are as follows: 1. Added a new HTML file `changelog\1.4.8.html` to the project `NebulaAuth.sln`. 2. Added a new converter `ProxyDataTextConverter` to `App.xaml`. 3. Imported `AchiesUtilities.Web.Proxy` in `ProxyTextConverter.cs`. 4. Modified the return string in `ProxyTextConverter` to include the port number. 5. Added a new class `ProxyDataTextConverter` in `ProxyTextConverter.cs`. 6. Increased the minimum snackbar time from 1000 to 1200 in `SnackbarController.cs`. 7. Modified the duration calculation in `GetSnackbarTime` method in `SnackbarController.cs`. 8. Added tooltips to ComboBoxes in `MainWindow.xaml`. 9. Added a new method `ValidateCanSave` in `Storage.cs` to validate if the data can be saved. 10. Added a new method `GetProxyString` in `ProxyStorage.cs` to get the proxy string. 11. Modified the `CompareProxy` method in `ProxyStorage.cs` to compare the address and port of the proxy data. 12. Removed a logger info line in `Shell.cs`. 13. Added a new property `DuplicateFound` in `Storage.cs`. 14. Modified the `CreatePathForMafile` method in `Storage.cs` to create a file name based on the account name or steam id. 15. Modified the `AddGroup` method in `MainVM_Groups.cs` to validate if the data can be saved before adding a group. 16. Modified the `AddToGroup` method in `MainVM_Groups.cs` to validate if the data can be saved before adding to a group. 17. Modified the `RemoveGroup` method in `MainVM_Groups.cs` to validate if the data can be saved before removing a group. 18. Modified the `PerformQuery` method in `MainVM_Groups.cs` to set `SelectedMafile` to the first item in `MaFiles`. 19. Modified the `RemoveProxy` method in `MainVM_Proxy.cs` to validate if the data can be saved before removing a proxy. 20. Modified the `SelectedProxyChanged` method in `MainVM_Proxy.cs` to validate if the data can be saved before changing the selected proxy. 21. Added a new method `ValidateCanSaveAndWarn` in `MainVM_Proxy.cs` to validate if the data can be saved and send a snackbar message if it can't. 22. Modified the `TimerCheckSeconds` property in `MainVM_Timer.cs` to send a snackbar message when the timer is changed. 23. Added a new method `RemoveProxy` in `LoginAgainOnImportVM.cs` to remove the selected proxy. 24. Modified the `AddProxy` method in `ProxyManagerVM.cs` to use the `DefaultScheme` to parse the proxy data. 25. Modified the `AddProxy` method in `ProxyManagerVM.cs` to use the `DefaultScheme` to parse the proxy data and get the proxy string. 26. Modified the `CopyProxy` method in `ProxyManagerVM.cs` to get the proxy string. 27. Added new localization entries in `localization.loc.json`. 28. The `update.xml` file was updated to reflect the new version of the software (1.4.8.0) and the corresponding download URL and changelog URL were updated accordingly. 29. In `AdmissionHelper.cs`, a new constant `SESSION_ID_COOKIE_NAME` was added to replace hardcoded "sessionid" strings. The same was done for `LANGUAGE_COOKIE_NAME` replacing "Steam_Language". This change was reflected in multiple methods within the `AdmissionHelper` class. 30. A new method `CloneCookie` was added to `AdmissionHelper.cs` to create a copy of a given cookie. This method was then used to replace repetitive code in the `TransferCommunityCookies` method. 31. In `MafileSerializer_SessionData.cs`, the check for whether the refresh token is expired or not was moved to a different location within the code. This change does not affect the functionality but may improve readability or maintainability of the code.
216 lines
8.3 KiB
C#
216 lines
8.3 KiB
C#
using AchiesUtilities.Extensions;
|
|
using JetBrains.Annotations;
|
|
using SteamLib.Account;
|
|
using SteamLib.Core;
|
|
using SteamLib.Core.Enums;
|
|
using SteamLib.Core.Interfaces;
|
|
using System.Net;
|
|
|
|
namespace SteamLib.Authentication;
|
|
|
|
[PublicAPI]
|
|
public static class AdmissionHelper
|
|
{
|
|
public const string ACCESS_COOKIE_NAME = "steamLoginSecure";
|
|
public const string REFRESH_COOKIE_NAME = "steamRefresh_steam";
|
|
public const string LANGUAGE_COOKIE_NAME = "Steam_Language";
|
|
public const string SESSION_ID_COOKIE_NAME = "sessionid";
|
|
|
|
#region Main
|
|
|
|
/// <summary>
|
|
/// Clear and set new session
|
|
/// </summary>
|
|
public static void SetSteamCookies(this CookieContainer container, ISessionData sessionData, string setLanguage = "english")
|
|
{
|
|
container.ClearSteamCookies(setLanguage);
|
|
|
|
|
|
AddRefreshToken(container, sessionData.RefreshToken);
|
|
|
|
var community = SteamDomains.GetDomainUri(SteamDomain.Community);
|
|
container.Add(community, new Cookie(SESSION_ID_COOKIE_NAME, sessionData.SessionId, "/"));
|
|
container.Add(community, new Cookie(LANGUAGE_COOKIE_NAME, setLanguage, "/"));
|
|
TransferCommunityCookies(container);
|
|
foreach (var domain in SteamDomains.AllDomains)
|
|
{
|
|
var token = sessionData.GetToken(domain);
|
|
if (token == null) continue;
|
|
AddTokenCookie(container, token.Value);
|
|
}
|
|
}
|
|
|
|
public static void SetDomainCookie(this CookieContainer container, SteamDomain domain, SteamAuthToken token)
|
|
{
|
|
var uri = SteamDomains.GetDomainUri(domain);
|
|
foreach (var cookie in container.GetCookies(uri).Where(c => c.Expired == false && c.Name.EqualsIgnoreCase(ACCESS_COOKIE_NAME)))
|
|
{
|
|
cookie.Expired = true;
|
|
}
|
|
|
|
AddTokenCookie(container, token);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Clear and set new session
|
|
/// </summary>
|
|
public static void SetSteamMobileCookies(this CookieContainer container, IMobileSessionData mobileSession,
|
|
string setLanguage = "english")
|
|
{
|
|
|
|
container.ClearSteamCookies(setLanguage);
|
|
container.AddMinimalMobileCookies();
|
|
|
|
AddRefreshToken(container, mobileSession.RefreshToken);
|
|
|
|
var community = SteamDomains.GetDomainUri(SteamDomain.Community);
|
|
container.Add(community, new Cookie("steamid", mobileSession.SteamId.Steam64.ToString()));
|
|
container.Add(community, new Cookie(SESSION_ID_COOKIE_NAME, mobileSession.SessionId));
|
|
container.Add(community, new Cookie(LANGUAGE_COOKIE_NAME, setLanguage));
|
|
TransferCommunityCookies(container);
|
|
|
|
foreach (var domain in SteamDomains.AllDomains)
|
|
{
|
|
var token = mobileSession.GetToken(domain);
|
|
if (token == null || token.Value.IsExpired) continue;
|
|
AddTokenCookie(container, token.Value);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clear and set new session. Not recommended. Uses <see cref="IMobileSessionData.GetMobileToken()"/> for domain <see cref="SteamDomain.Community"/> instead of its own cookie. It's okay to use it only for confirmations. But Market, Trading and other pages won't be authenticated
|
|
/// </summary>
|
|
public static void SetSteamMobileCookiesWithMobileToken(this CookieContainer container, IMobileSessionData mobileSession,
|
|
string setLanguage = "english")
|
|
{
|
|
|
|
container.ClearSteamCookies(setLanguage);
|
|
container.AddMinimalMobileCookies();
|
|
|
|
AddRefreshToken(container, mobileSession.RefreshToken);
|
|
|
|
var community = SteamDomains.GetDomainUri(SteamDomain.Community);
|
|
container.Add(community, new Cookie("steamid", mobileSession.SteamId.Steam64.ToString()));
|
|
container.Add(community, new Cookie(SESSION_ID_COOKIE_NAME, mobileSession.SessionId));
|
|
container.Add(community, new Cookie(LANGUAGE_COOKIE_NAME, setLanguage));
|
|
TransferCommunityCookies(container);
|
|
|
|
var domainCookieSet = false;
|
|
foreach (var domain in SteamDomains.AllDomains)
|
|
{
|
|
|
|
var token = mobileSession.GetToken(domain);
|
|
if (token == null || token.Value.IsExpired) continue;
|
|
if(domain == SteamDomain.Community )
|
|
domainCookieSet = true;
|
|
AddTokenCookie(container, token.Value);
|
|
}
|
|
|
|
var mobileToken = mobileSession.GetMobileToken();
|
|
if (domainCookieSet == false && mobileToken is {IsExpired: false})
|
|
AddTokenCookie(container, SteamDomain.Community, mobileToken.Value);
|
|
}
|
|
|
|
|
|
public static void AddMinimalMobileCookies(this CookieContainer container)
|
|
{
|
|
var community = SteamDomains.GetDomainUri(SteamDomain.Community);
|
|
container.Add(community, new Cookie("mobileClientVersion", "777777 3.6.1"));
|
|
container.Add(community, new Cookie("mobileClient", "android"));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Clear
|
|
public static void ClearSteamCookies(this CookieContainer container, string setLanguage = "english")
|
|
{
|
|
var cookies = container.GetAllCookies().Where(IsSteamCookie).ToList();
|
|
foreach (var cookie in cookies)
|
|
{
|
|
cookie.Expired = true;
|
|
}
|
|
container.Add(SteamDomains.GetDomainUri(SteamDomain.Community), new Cookie(LANGUAGE_COOKIE_NAME, setLanguage));
|
|
TransferCommunityCookies(container);
|
|
}
|
|
|
|
public static void ClearMobileSessionCookies(this CookieContainer container, string setLanguage = "english")
|
|
{
|
|
container.ClearSteamCookies(setLanguage);
|
|
container.AddMinimalMobileCookies();
|
|
TransferCommunityCookies(container);
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Helpers
|
|
public static void TransferCommunityCookies(CookieContainer container)
|
|
{
|
|
var cookies = container.GetAllCookies();
|
|
|
|
|
|
foreach (Cookie cookie in cookies)
|
|
{
|
|
if (cookie.Domain.Contains("steamcommunity.com") == false || cookie.Expired || cookie.Name.EqualsIgnoreCase(ACCESS_COOKIE_NAME)) continue;
|
|
|
|
|
|
container.Add(SteamDomains.GetDomainUri(SteamDomain.Store), CloneCookie(cookie));
|
|
container.Add(SteamDomains.GetDomainUri(SteamDomain.Help), CloneCookie(cookie));
|
|
container.Add(SteamDomains.GetDomainUri(SteamDomain.TV), CloneCookie(cookie));
|
|
}
|
|
|
|
return;
|
|
|
|
static Cookie CloneCookie(Cookie cookie)
|
|
=> new(cookie.Name, cookie.Value, cookie.Path) { Expires = cookie.Expires, Secure = cookie.Secure, HttpOnly = cookie.HttpOnly };
|
|
}
|
|
|
|
public static void AddRefreshToken(CookieContainer container, SteamAuthToken token)
|
|
{
|
|
if (token.Type is not (SteamAccessTokenType.Refresh or SteamAccessTokenType.MobileRefresh))
|
|
throw new ArgumentException($"Token must be of type Refresh or MobileRefresh. Provided token has type: {token.Type}", nameof(token));
|
|
var refreshToken = token.SignedToken;
|
|
container.Add(SteamDomains.LoginSteamDomain, new Cookie(REFRESH_COOKIE_NAME, refreshToken)
|
|
{
|
|
Expires = token.Expires.ToLocalDateTime()
|
|
});
|
|
}
|
|
|
|
public static void AddTokenCookie(CookieContainer container, SteamAuthToken token)
|
|
{
|
|
if (token.Type is not SteamAccessTokenType.AccessToken)
|
|
throw new ArgumentException($"Token must be of type AccessToken. Provided token has type: {token.Type}", nameof(token));
|
|
|
|
AddTokenCookie(container, token.Domain, token);
|
|
}
|
|
private static void AddTokenCookie(CookieContainer container, SteamDomain domain, SteamAuthToken token)
|
|
{
|
|
var domainUri = SteamDomains.GetDomainUri(domain);
|
|
container.Add(domainUri, new Cookie(ACCESS_COOKIE_NAME, token.SignedToken)
|
|
{
|
|
HttpOnly = true,
|
|
Secure = true,
|
|
Expires = token.Expires.ToLocalDateTime()
|
|
});
|
|
}
|
|
|
|
|
|
public static bool IsSteamCookie(Cookie cookie) =>
|
|
cookie.Domain.Contains("steamcommunity.com") || cookie.Domain.Contains("steampowered.com") || cookie.Domain.Contains("steam.tv");
|
|
|
|
|
|
public static string? GetSessionId(this CookieContainer container, string domain = "steamcommunity.com")
|
|
{
|
|
var cookies = container.GetAllCookies();
|
|
return cookies
|
|
.FirstOrDefault(c => c.Name.Equals(SESSION_ID_COOKIE_NAME, StringComparison.InvariantCultureIgnoreCase)
|
|
&& c.Expired == false
|
|
&& c.Domain.Contains(domain, StringComparison.InvariantCultureIgnoreCase))?
|
|
.Value;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
} |