improve pre-login auth handling (I think?)

pull/401/head
Yaakov 3 years ago
parent c36ddcc065
commit d73462e077

@ -59,6 +59,7 @@ namespace DepotDownloader
int connectionBackoff;
int seq; // more hack fixes
DateTime connectTime;
AuthSession authSession;
// input
readonly SteamUser.LogOnDetails logonDetails;
@ -426,6 +427,7 @@ namespace DepotDownloader
bConnected = false;
bConnecting = true;
connectionBackoff = 0;
authSession = null;
ResetConnectionFlags();
@ -500,26 +502,19 @@ namespace DepotDownloader
Console.WriteLine("Logging '{0}' into Steam3...", logonDetails.Username);
}
if (authSession is null)
{
if (logonDetails.Username != null && logonDetails.Password != null && logonDetails.AccessToken is null)
{
try
{
var session = await steamClient.Authentication.BeginAuthSessionViaCredentialsAsync(new SteamKit2.Authentication.AuthSessionDetails
authSession = await steamClient.Authentication.BeginAuthSessionViaCredentialsAsync(new SteamKit2.Authentication.AuthSessionDetails
{
Username = logonDetails.Username,
Password = logonDetails.Password,
IsPersistentSession = ContentDownloader.Config.RememberPassword,
Authenticator = new UserConsoleAuthenticator(),
});
var result = await session.PollingWaitForResultAsync();
// Assume that we get back the same username, no need to reset it.
logonDetails.Password = null;
logonDetails.AccessToken = result.RefreshToken;
AccountSettingsStore.Instance.LoginTokens[result.AccountName] = result.RefreshToken;
AccountSettingsStore.Save();
}
catch (TaskCanceledException)
{
@ -532,7 +527,7 @@ namespace DepotDownloader
return;
}
}
else if (ContentDownloader.Config.UseQrCode)
else if (logonDetails.AccessToken is null && ContentDownloader.Config.UseQrCode)
{
Console.WriteLine("Logging in with QR code...");
@ -544,6 +539,8 @@ namespace DepotDownloader
Authenticator = new UserConsoleAuthenticator(),
});
authSession = session;
// Steam will periodically refresh the challenge url, so we need a new QR code.
session.ChallengeURLChanged = () =>
{
@ -555,8 +552,25 @@ namespace DepotDownloader
// Draw initial QR code immediately
DisplayQrCode(session.ChallengeURL);
}
catch (TaskCanceledException)
{
return;
}
catch (Exception ex)
{
Console.Error.WriteLine("Failed to authenticate with Steam: " + ex.Message);
Abort(false);
return;
}
}
}
var result = await session.PollingWaitForResultAsync();
if (authSession != null)
{
try
{
var result = await authSession.PollingWaitForResultAsync();
logonDetails.Username = result.AccountName;
logonDetails.Password = null;
@ -575,6 +589,8 @@ namespace DepotDownloader
Abort(false);
return;
}
authSession = null;
}
steamUser.LogOn(logonDetails);

Loading…
Cancel
Save