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

Loading…
Cancel
Save