From 5a219337f59c95ff73dcda5e173dab8dcbac5a36 Mon Sep 17 00:00:00 2001 From: Iluha <92525749+Iluhadesu@users.noreply.github.com> Date: Fri, 21 Jul 2023 14:35:17 +0200 Subject: [PATCH] Adds DepotDownloaderAuthenticator.cs to handle hooks on SteamKit2 new Auth --- .../DepotDownloaderAuthenticator.cs | 60 +++++++++++++++++++ DepotDownloader/Steam3Session.cs | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 DepotDownloader/DepotDownloaderAuthenticator.cs diff --git a/DepotDownloader/DepotDownloaderAuthenticator.cs b/DepotDownloader/DepotDownloaderAuthenticator.cs new file mode 100644 index 00000000..70184d1a --- /dev/null +++ b/DepotDownloader/DepotDownloaderAuthenticator.cs @@ -0,0 +1,60 @@ +using System; +using System.Threading.Tasks; +using SteamKit2.Authentication; + +namespace DepotDownloader; + +public class DepotDownloaderAuthenticator : IAuthenticator +{ + public Task GetDeviceCodeAsync(bool previousCodeWasIncorrect) + { + if (previousCodeWasIncorrect) + { + Console.Out.WriteLine("[2FA]|[Wrong]|The previous 2-factor auth code you have provided is incorrect."); + } + + string? code; + + do + { + Console.Out.Write("[2FA]|Please enter your 2 factor auth code from your authenticator app: "); + code = Console.ReadLine()?.Trim(); + + if (code == null) + { + break; + } + } while (string.IsNullOrEmpty(code)); + + return Task.FromResult(code!); + } + + public Task GetEmailCodeAsync(string email, bool previousCodeWasIncorrect) + { + if (previousCodeWasIncorrect) + { + Console.Out.WriteLine("[Guard]|[Wrong]|The previous 2-factor auth code you have provided is incorrect."); + } + + string? code; + + do + { + Console.Out.Write($"[Guard]|Please enter the authentication code sent to your email address: "); + code = Console.ReadLine()?.Trim(); + + if (code == null) + { + break; + } + } while (string.IsNullOrEmpty(code)); + + return Task.FromResult(code!); + } + + public Task AcceptDeviceConfirmationAsync() + { + Console.Out.WriteLine("[MobileApp]|Use the Steam Mobile App to confirm your sign in..."); + return Task.FromResult(true); + } +} diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index 51260f1e..7150a55e 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -513,7 +513,7 @@ namespace DepotDownloader Username = logonDetails.Username, Password = logonDetails.Password, IsPersistentSession = ContentDownloader.Config.RememberPassword, - Authenticator = new UserConsoleAuthenticator(), + Authenticator = new DepotDownloaderAuthenticator(), }); } catch (TaskCanceledException)