Impove MS authentication error feedback (#1410)

* Impove MS authentication error feedback

* Modify old error message

* Improve 2FA error message

Co-authored-by: ORelio <ORelio@users.noreply.github.com>
This commit is contained in:
ReinforceZwei 2021-01-14 12:24:51 +08:00 committed by GitHub
parent 7cbf677e0c
commit 106acab66f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,8 @@ namespace MinecraftClient.Protocol
private Regex ppft = new Regex("sFTTag:'.*value=\"(.*)\"\\/>'"); private Regex ppft = new Regex("sFTTag:'.*value=\"(.*)\"\\/>'");
private Regex urlPost = new Regex("urlPost:'(.+?(?=\'))"); private Regex urlPost = new Regex("urlPost:'(.+?(?=\'))");
private Regex confirm = new Regex("identity\\/confirm"); private Regex confirm = new Regex("identity\\/confirm");
private Regex invalidAccount = new Regex("Sign in to", RegexOptions.IgnoreCase);
private Regex twoFA = new Regex("Help us protect your account", RegexOptions.IgnoreCase);
/// <summary> /// <summary>
/// Pre-authentication /// Pre-authentication
@ -91,11 +93,7 @@ namespace MinecraftClient.Protocol
if (string.IsNullOrEmpty(hash)) if (string.IsNullOrEmpty(hash))
{ {
if (confirm.IsMatch(response2.Body)) throw new Exception("Cannot extract access token");
{
throw new Exception("Activity confirmation required");
}
else throw new Exception("Invalid credentials or 2FA enabled");
} }
var dict = Request.ParseQueryString(hash); var dict = Request.ParseQueryString(hash);
@ -113,7 +111,16 @@ namespace MinecraftClient.Protocol
} }
else else
{ {
throw new Exception("Unexpected response. Check your credentials. Response code: " + response.StatusCode); if (twoFA.IsMatch(response.Body))
{
// TODO: Handle 2FA
throw new Exception("2FA enabled but not supported yet. Try to disable it in Microsoft account settings");
}
else if (invalidAccount.IsMatch(response.Body))
{
throw new Exception("Invalid credentials. Check your credentials");
}
else throw new Exception("Unexpected response. Check your credentials. Response code: " + response.StatusCode);
} }
} }