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

@ -504,20 +504,13 @@ namespace MinecraftClient.Protocol
string code = ConsoleIO.ReadLine();
var msaResponse = Microsoft.RequestAccessToken(code);
try
{
return MicrosoftLogin(msaResponse, out session);
}
catch (Exception e)
{
session = new SessionToken() { ClientID = Guid.NewGuid().ToString().Replace("-", "") };
ConsoleIO.WriteLineFormatted("§cMicrosoft authenticate failed: " + e.Message);
if (Settings.DebugMessages)
{
ConsoleIO.WriteLineFormatted("§c" + e.StackTrace);
}
return LoginResult.WrongPassword; // Might not always be wrong password
}
return MicrosoftLogin(msaResponse, out session);
}
public static LoginResult MicrosoftLoginRefresh(string refreshToken, out SessionToken session)
{
var msaResponse = Microsoft.RefreshAccessToken(refreshToken);
return MicrosoftLogin(msaResponse, out session);
}
private static LoginResult MicrosoftLogin(Microsoft.LoginResponse msaResponse, out SessionToken session)
@ -539,6 +532,7 @@ namespace MinecraftClient.Protocol
session.PlayerName = profile.UserName;
session.PlayerID = profile.UUID;
session.ID = accessToken;
session.RefreshToken = msaResponse.RefreshToken;
Settings.Login = msaResponse.Email;
return LoginResult.Success;
}