Microsoft Sign-in: Add refresh token support (#1838)

This commit is contained in:
ReinforceZwei 2021-12-16 15:53:31 +08:00 committed by GitHub
parent e68a51dcff
commit 4b8ca158a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 21 deletions

View file

@ -211,7 +211,14 @@ namespace MinecraftClient
if (result != ProtocolHandler.LoginResult.Success)
{
Translations.WriteLineFormatted("mcc.session_invalid");
if (Settings.Password == "" && Settings.AccountType == ProtocolHandler.AccountType.Mojang)
// Try to refresh access token
if (!string.IsNullOrWhiteSpace(session.RefreshToken))
{
result = ProtocolHandler.MicrosoftLoginRefresh(session.RefreshToken, out session);
}
if (result != ProtocolHandler.LoginResult.Success
&& Settings.Password == ""
&& Settings.AccountType == ProtocolHandler.AccountType.Mojang)
RequestPassword();
}
else ConsoleIO.WriteLineFormatted(Translations.Get("mcc.session_valid", session.PlayerName));
@ -221,14 +228,14 @@ namespace MinecraftClient
{
Translations.WriteLine("mcc.connecting", Settings.AccountType == ProtocolHandler.AccountType.Mojang ? "Minecraft.net" : "Microsoft");
result = ProtocolHandler.GetLogin(Settings.Login, Settings.Password, Settings.AccountType, out session);
if (result == ProtocolHandler.LoginResult.Success && Settings.SessionCaching != CacheType.None)
{
SessionCache.Store(Settings.Login.ToLower(), session);
}
}
}
if (result == ProtocolHandler.LoginResult.Success && Settings.SessionCaching != CacheType.None)
{
SessionCache.Store(Settings.Login.ToLower(), session);
}
if (result == ProtocolHandler.LoginResult.Success)
{
Settings.Username = session.PlayerName;