public Authenticator(AddAuthenticatorResponse authenticatorData, MobileSession session, string deviceId) { AuthenticatorData = authenticatorData; Session = session; DeviceId = deviceId; SteamWeb = new SteamMobileWebAccess(session ?? new MobileSession()); }
/// <summary> /// Retrieves a list of confirmation waiting to be verified by user /// </summary> /// <returns></returns> /// <exception cref="TokenInvalidException">Provided session token is invalid.</exception> /// <exception cref="TokenExpiredException">Provided session token has expired.</exception> /// <exception cref="WebException">Failed to communicate with steam's network or a bad response received.</exception> public async Task <Confirmation[]> FetchConfirmations() { try { var parameters = await GetConfirmationParameters("conf").ConfigureAwait(false); var response = await OperationRetryHelper.Default.RetryOperationAsync( () => SteamWeb.FetchString( new SteamWebAccessRequest( MobileConfirmationsUrl, SteamWebAccessRequestMethod.Get, parameters ) ) ).ConfigureAwait(false); /* * So you're going to see this abomination and you're going to be upset. * It's understandable. But the thing is, regex for HTML -- while awful -- makes this way faster than parsing a DOM, plus we don't need another library. * And because the data is always in the same place and same format... It's not as if we're trying to naturally understand HTML here. Just extract strings. * I'm sorry. */ if (response == null || !ConfirmationRegex.IsMatch(response)) { if (string.IsNullOrWhiteSpace(response) || !response.Contains("id=\"mobileconf_empty\"")) { throw new TokenInvalidException(); } return(Array.Empty <Confirmation>()); } return(ConfirmationRegex.Matches(response).Cast <Match>() .Where(match => match.Groups.Count == 5) .Select( match => { if (ulong.TryParse(match.Groups[1].Value, out var id) && ulong.TryParse(match.Groups[2].Value, out var key) && int.TryParse(match.Groups[3].Value, out var type) && ulong.TryParse(match.Groups[4].Value, out var creator)) { return new Confirmation(id, key, (ConfirmationType)type, creator); } return null; } ).Where(confirmation => confirmation != null).ToArray()); } catch (Exception e) { if (MobileSession.IsTokenExpired(e)) { throw new TokenExpiredException(e); } throw; } }
public SteamMobileWebAccess(MobileSession session, IPAddress ipAddress, IWebProxy proxy) : base(session, ipAddress, proxy) { }
public SteamMobileWebAccess(MobileSession session, IWebProxy proxy) : base(session, proxy) { }
public SteamMobileWebAccess(MobileSession session, IPAddress ipAddress) : base(session, ipAddress) { }
public SteamMobileWebAccess(MobileSession session) : base(session) { }
/// <summary> /// Returns a new instance of Authenticator class based on the description provided by the passed serialized string in /// Json format /// </summary> /// <param name="serialized">The serialized representation of an Authenticator instance as string in Json format.</param> /// <returns>An instance of Authenticator class</returns> public static Authenticator DeSerialize(string serialized) { var authenticator = JsonConvert.DeserializeObject <Authenticator>(serialized); // Tries to fill authenticator data by searching for properties in the root of Json object if (authenticator.AuthenticatorData == null || !authenticator.AuthenticatorData.HasEnoughInfo()) { var authenticatorData = JsonConvert.DeserializeObject <AddAuthenticatorResponse>(serialized); authenticator = new Authenticator( authenticatorData, authenticator.Session, authenticator.DeviceId ); } // Tries to fill session data by searching for properties in the root of Json object if (authenticator.Session == null || !authenticator.Session.HasEnoughInfo()) { var sessionData = JsonConvert.DeserializeObject <MobileSession>(serialized); authenticator = new Authenticator( authenticator.AuthenticatorData, sessionData, authenticator.DeviceId ); } // Tries to extract steam guard machine authentication tokens if (authenticator.Session != null && !(authenticator.Session.SteamMachineAuthenticationTokens?.Count > 0)) { var steamIdProperties = JsonConvert.DeserializeAnonymousType( serialized, new { steamid = (ulong?)null, steam_id = (ulong?)null, session = new { steamid = (ulong?)null, steam_id = (ulong?)null } } ); var steamId = steamIdProperties.steam_id ?? steamIdProperties.steamid ?? steamIdProperties.session.steam_id ?? steamIdProperties.session.steamid ?? authenticator.Session.SteamId; var webCookieProperties = JsonConvert.DeserializeAnonymousType( serialized, new { webcookie = (string)null, web_cookie = (string)null, session = new { webcookie = (string)null, web_cookie = (string)null } } ); var webCookie = webCookieProperties.web_cookie ?? webCookieProperties.webcookie ?? webCookieProperties.session.web_cookie ?? webCookieProperties.session.webcookie; if (steamId != null && !string.IsNullOrWhiteSpace(webCookie)) { var newSession = new MobileSession( authenticator.Session.OAuthToken, steamId, authenticator.Session.SteamLogin, authenticator.Session.SteamLoginSecure, authenticator.Session.SessionId, authenticator.Session.RememberLoginToken, new Dictionary <ulong, string> { { steamId.Value, webCookie } } ); authenticator = new Authenticator( authenticator.AuthenticatorData, newSession, authenticator.DeviceId ); } } // Tries to fill device identification string by searching for properties in the root of Json object if (string.IsNullOrWhiteSpace(authenticator.DeviceId)) { var deviceIdProperties = JsonConvert.DeserializeAnonymousType( serialized, new { deviceId = (string)null, device_id = (string)null, device = (string)null } ); authenticator = new Authenticator( authenticator.AuthenticatorData, authenticator.Session, deviceIdProperties.device_id ?? deviceIdProperties.deviceId ?? deviceIdProperties.device ); } // Do we have a enough information to call this a valid instance? return(authenticator.HasEnoughInfo() ? authenticator : null); }