Exemple #1
0
        /// <summary>
        ///     Finalizes the registration process of an already retrieved authenticator. If this process succeeds, this instance
        ///     of Authenticator should be considered as registered and verified and must be saved safely to an persistence storage
        ///     for later usages. Failing to do so results in losing access to the user account associated with it.
        /// </summary>
        /// <param name="requestedAuthenticator">The already retrieved authenticator to register.</param>
        /// <param name="smsCode">The SMS code received on the phone number.</param>
        /// <returns></returns>
        public async Task FinalizeAddAuthenticator(Authenticator requestedAuthenticator, string smsCode)
        {
            const int maxRetries = 30;

            for (var i = 1; i <= maxRetries; i++)
            {
                var serverResponse = await SteamWebAPI.Default
                                     .RequestObject <SteamWebAPIResponse <FinalizeAuthenticatorResponse> >(
                    "ITwoFactorService",
                    SteamWebAccessRequestMethod.Post,
                    "FinalizeAddAuthenticator",
                    "v0001", new
                {
                    steamid            = SteamWeb.Session?.SessionId,
                    access_token       = (SteamWeb.Session as MobileSession)?.OAuthToken,
                    activation_code    = smsCode,
                    authenticator_code = requestedAuthenticator.GenerateSteamGuardCode(),
                    authenticator_time = SteamTime.GetUnixTime()
                }
                    ).ConfigureAwait(false);

                if (serverResponse?.Response?.Status == AuthenticatorLinkerErrorCode.IncorrectSteamGuardCode)
                {
                    if (i >= maxRetries)
                    {
                        throw new AuthenticatorLinkerException(serverResponse.Response?.Status);
                    }
                }

                if (serverResponse?.Response?.Success == true && serverResponse.Response?.WantMore == false)
                {
                    return;
                }

                if (serverResponse?.Response?.WantMore != true)
                {
                    throw new AuthenticatorLinkerException(serverResponse?.Response?.Status);
                }

                await SteamTime.ReAlignTime().ConfigureAwait(false);
            }

            throw new AuthenticatorLinkerException();
        }
Exemple #2
0
        private async Task <QueryStringBuilder> GetConfirmationParameters(string tag)
        {
            if (string.IsNullOrEmpty(DeviceId))
            {
                throw new ArgumentException("Device Id is not present");
            }

            var time = await SteamTime.GetTime().ConfigureAwait(false);

            return(new QueryStringBuilder
            {
                { "p", DeviceId },
                { "a", Session.SteamId },
                { "k", GenerateConfirmationHashForTime(time, tag) },
                { "t", time.ToUnixTime() },
                { "m", MobileSession.ClientName },
                { "tag", tag }
            });
        }
Exemple #3
0
 /// <summary>
 ///     Generates and returns a new steam guard code.
 /// </summary>
 /// <returns>The newly generated steam guard code.</returns>
 public async Task <string> GenerateSteamGuardCode()
 {
     return(GenerateSteamGuardCodeForTime(await SteamTime.GetTime().ConfigureAwait(false)));
 }
Exemple #4
0
 /// <summary>
 ///     Generates and returns a new steam guard code using the passed shared secret.
 /// </summary>
 /// <param name="sharedSecret">The shared secret to generate steam guard code from.</param>
 /// <returns>
 ///     The newly generated steam guard code.
 /// </returns>
 public static async Task <string> GenerateSteamGuardCode(byte[] sharedSecret)
 {
     return(GenerateSteamGuardCodeForTime(sharedSecret, await SteamTime.GetTime().ConfigureAwait(false)));
 }