Skip to content

Commit cc75db7

Browse files
MSA: Disable refresh token for MCC signin method (#1925)
* MSA: Change classes to static class * MSA: Disable refresh token for MCC sign method
1 parent ed452cf commit cc75db7

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

MinecraftClient/Protocol/MicrosoftAuthentication.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,28 @@ public struct LoginResponse
108108
}
109109
}
110110

111-
class XboxLive
111+
static class XboxLive
112112
{
113-
private readonly string authorize = "https://login.live.com/oauth20_authorize.srf?client_id=000000004C12AE6F&redirect_uri=https://login.live.com/oauth20_desktop.srf&scope=service::user.auth.xboxlive.com::MBI_SSL&display=touch&response_type=token&locale=en";
114-
private readonly string xbl = "https://user.auth.xboxlive.com/user/authenticate";
115-
private readonly string xsts = "https://xsts.auth.xboxlive.com/xsts/authorize";
113+
private static string authorize = "https://login.live.com/oauth20_authorize.srf?client_id=000000004C12AE6F&redirect_uri=https://login.live.com/oauth20_desktop.srf&scope=service::user.auth.xboxlive.com::MBI_SSL&display=touch&response_type=token&locale=en";
114+
private static string xbl = "https://user.auth.xboxlive.com/user/authenticate";
115+
private static string xsts = "https://xsts.auth.xboxlive.com/xsts/authorize";
116116

117-
private readonly string userAgent = "Mozilla/5.0 (XboxReplay; XboxLiveAuth/3.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36";
117+
private static string userAgent = "Mozilla/5.0 (XboxReplay; XboxLiveAuth/3.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36";
118118

119-
private Regex ppft = new Regex("sFTTag:'.*value=\"(.*)\"\\/>'");
120-
private Regex urlPost = new Regex("urlPost:'(.+?(?=\'))");
121-
private Regex confirm = new Regex("identity\\/confirm");
122-
private Regex invalidAccount = new Regex("Sign in to", RegexOptions.IgnoreCase);
123-
private Regex twoFA = new Regex("Help us protect your account", RegexOptions.IgnoreCase);
119+
private static Regex ppft = new Regex("sFTTag:'.*value=\"(.*)\"\\/>'");
120+
private static Regex urlPost = new Regex("urlPost:'(.+?(?=\'))");
121+
private static Regex confirm = new Regex("identity\\/confirm");
122+
private static Regex invalidAccount = new Regex("Sign in to", RegexOptions.IgnoreCase);
123+
private static Regex twoFA = new Regex("Help us protect your account", RegexOptions.IgnoreCase);
124124

125-
public string SignInUrl { get { return authorize; } }
125+
public static string SignInUrl { get { return authorize; } }
126126

127127
/// <summary>
128128
/// Pre-authentication
129129
/// </summary>
130130
/// <remarks>This step is to get the login page for later use</remarks>
131131
/// <returns></returns>
132-
public PreAuthResponse PreAuth()
132+
public static PreAuthResponse PreAuth()
133133
{
134134
var request = new ProxiedWebRequest(authorize);
135135
request.UserAgent = userAgent;
@@ -138,7 +138,7 @@ public PreAuthResponse PreAuth()
138138
string html = response.Body;
139139

140140
string PPFT = ppft.Match(html).Groups[1].Value;
141-
string urlPost = this.urlPost.Match(html).Groups[1].Value;
141+
string urlPost = XboxLive.urlPost.Match(html).Groups[1].Value;
142142

143143
if (string.IsNullOrEmpty(PPFT) || string.IsNullOrEmpty(urlPost))
144144
{
@@ -164,7 +164,7 @@ public PreAuthResponse PreAuth()
164164
/// <param name="password">Account password</param>
165165
/// <param name="preAuth"></param>
166166
/// <returns></returns>
167-
public Microsoft.LoginResponse UserLogin(string email, string password, PreAuthResponse preAuth)
167+
public static Microsoft.LoginResponse UserLogin(string email, string password, PreAuthResponse preAuth)
168168
{
169169
var request = new ProxiedWebRequest(preAuth.UrlPost, preAuth.Cookie);
170170
request.UserAgent = userAgent;
@@ -233,7 +233,7 @@ public Microsoft.LoginResponse UserLogin(string email, string password, PreAuthR
233233
/// </summary>
234234
/// <param name="loginResponse"></param>
235235
/// <returns></returns>
236-
public XblAuthenticateResponse XblAuthenticate(Microsoft.LoginResponse loginResponse)
236+
public static XblAuthenticateResponse XblAuthenticate(Microsoft.LoginResponse loginResponse)
237237
{
238238
var request = new ProxiedWebRequest(xbl);
239239
request.UserAgent = userAgent;
@@ -288,7 +288,7 @@ public XblAuthenticateResponse XblAuthenticate(Microsoft.LoginResponse loginResp
288288
/// <remarks>(Don't ask me what is XSTS, I DONT KNOW)</remarks>
289289
/// <param name="xblResponse"></param>
290290
/// <returns></returns>
291-
public XSTSAuthenticateResponse XSTSAuthenticate(XblAuthenticateResponse xblResponse)
291+
public static XSTSAuthenticateResponse XSTSAuthenticate(XblAuthenticateResponse xblResponse)
292292
{
293293
var request = new ProxiedWebRequest(xsts);
294294
request.UserAgent = userAgent;
@@ -364,19 +364,19 @@ public struct XSTSAuthenticateResponse
364364
}
365365
}
366366

367-
class MinecraftWithXbox
367+
static class MinecraftWithXbox
368368
{
369-
private readonly string loginWithXbox = "https://api.minecraftservices.com/authentication/login_with_xbox";
370-
private readonly string ownership = "https://api.minecraftservices.com/entitlements/mcstore";
371-
private readonly string profile = "https://api.minecraftservices.com/minecraft/profile";
369+
private static string loginWithXbox = "https://api.minecraftservices.com/authentication/login_with_xbox";
370+
private static string ownership = "https://api.minecraftservices.com/entitlements/mcstore";
371+
private static string profile = "https://api.minecraftservices.com/minecraft/profile";
372372

373373
/// <summary>
374374
/// Login to Minecraft using the XSTS token and user hash obtained before
375375
/// </summary>
376376
/// <param name="userHash"></param>
377377
/// <param name="xstsToken"></param>
378378
/// <returns></returns>
379-
public string LoginWithXbox(string userHash, string xstsToken)
379+
public static string LoginWithXbox(string userHash, string xstsToken)
380380
{
381381
var request = new ProxiedWebRequest(loginWithXbox);
382382
request.Accept = "application/json";
@@ -399,7 +399,7 @@ public string LoginWithXbox(string userHash, string xstsToken)
399399
/// </summary>
400400
/// <param name="accessToken"></param>
401401
/// <returns>True if the user own the game</returns>
402-
public bool UserHasGame(string accessToken)
402+
public static bool UserHasGame(string accessToken)
403403
{
404404
var request = new ProxiedWebRequest(ownership);
405405
request.Headers.Add("Authorization", string.Format("Bearer {0}", accessToken));
@@ -415,7 +415,7 @@ public bool UserHasGame(string accessToken)
415415
return json.Properties["items"].DataArray.Count > 0;
416416
}
417417

418-
public UserProfile GetUserProfile(string accessToken)
418+
public static UserProfile GetUserProfile(string accessToken)
419419
{
420420
var request = new ProxiedWebRequest(profile);
421421
request.Headers.Add("Authorization", string.Format("Bearer {0}", accessToken));

MinecraftClient/Protocol/ProtocolHandler.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,11 @@ private static LoginResult MojangLogin(string user, string pass, out SessionToke
463463
/// <returns></returns>
464464
private static LoginResult MicrosoftMCCLogin(string email, string password, out SessionToken session)
465465
{
466-
var ms = new XboxLive();
467466
try
468467
{
469-
var msaResponse = ms.UserLogin(email, password, ms.PreAuth());
468+
var msaResponse = XboxLive.UserLogin(email, password, XboxLive.PreAuth());
469+
// Remove refresh token for MCC sign method
470+
msaResponse.RefreshToken = string.Empty;
470471
return MicrosoftLogin(msaResponse, out session);
471472
}
472473
catch (Exception e)
@@ -516,19 +517,17 @@ public static LoginResult MicrosoftLoginRefresh(string refreshToken, out Session
516517
private static LoginResult MicrosoftLogin(Microsoft.LoginResponse msaResponse, out SessionToken session)
517518
{
518519
session = new SessionToken() { ClientID = Guid.NewGuid().ToString().Replace("-", "") };
519-
var ms = new XboxLive();
520-
var mc = new MinecraftWithXbox();
521520

522521
try
523522
{
524-
var xblResponse = ms.XblAuthenticate(msaResponse);
525-
var xsts = ms.XSTSAuthenticate(xblResponse); // Might throw even password correct
523+
var xblResponse = XboxLive.XblAuthenticate(msaResponse);
524+
var xsts = XboxLive.XSTSAuthenticate(xblResponse); // Might throw even password correct
526525

527-
string accessToken = mc.LoginWithXbox(xsts.UserHash, xsts.Token);
528-
bool hasGame = mc.UserHasGame(accessToken);
526+
string accessToken = MinecraftWithXbox.LoginWithXbox(xsts.UserHash, xsts.Token);
527+
bool hasGame = MinecraftWithXbox.UserHasGame(accessToken);
529528
if (hasGame)
530529
{
531-
var profile = mc.GetUserProfile(accessToken);
530+
var profile = MinecraftWithXbox.GetUserProfile(accessToken);
532531
session.PlayerName = profile.UserName;
533532
session.PlayerID = profile.UUID;
534533
session.ID = accessToken;

0 commit comments

Comments
 (0)