Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,48 @@ public MicrosoftAuthResult loginWithCredentials(String email, String password) t
}
}

/**
* Logs in a player using its Microsoft account credentials and retrieves its access and xboxUserHash
*
* @param email Player Microsoft account e-mail
* @param password Player Microsoft account password
* @param retrieveProfile if you want to retrieve the minecraft profile
* @return The player's xbox profile with minecraft access token
* @throws MicrosoftAuthenticationException Thrown if one of the several HTTP requests failed at some point
*/
public MicrosoftAuthResult loginWithCredentials(String email, String password, boolean retrieveProfile) throws MicrosoftAuthenticationException {
CookieHandler currentHandler = CookieHandler.getDefault();
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));

Map<String, String> params = new HashMap<>();
params.put("login", email);
params.put("loginfmt", email);
params.put("passwd", password);

HttpURLConnection result;

try {
PreAuthData authData = preAuthRequest();
params.put("PPFT", authData.getPPFT());

result = http.followRedirects(http.postForm(authData.getUrlPost(), params));
} finally {
CookieHandler.setDefault(currentHandler);
}

try {
return loginWithTokens(extractTokens(result.getURL().toString()),retrieveProfile);
} catch (MicrosoftAuthenticationException e) {
if (match("(identity/confirm)", http.readResponse(result)) != null) {
throw new MicrosoftAuthenticationException(
"User has enabled double-authentication or must allow sign-in on https://account.live.com/activity"
);
}

throw e;
}
}

/**
* Logs in a player using a webview to display Microsoft login page.
* <b>This function blocks the current thread until the process is finished; this can cause your application to
Expand Down Expand Up @@ -184,6 +226,27 @@ public MicrosoftAuthResult loginWithRefreshToken(String refreshToken) throws Mic
return loginWithTokens(new AuthTokens(response.getAccessToken(), response.getRefreshToken()),true);
}

/**
* Logs in a player using a Microsoft account refresh token retrieved earlier.
*
* @param refreshToken Player Microsoft account refresh token
* @param retrieveProfile if you want to retrieve the minecraft profile
* @return The player's xbox profile with minecraft access token
* @throws MicrosoftAuthenticationException Thrown if one of the several HTTP requests failed at some point
*/
public MicrosoftAuthResult loginWithRefreshToken(String refreshToken, boolean retrieveProfile) throws MicrosoftAuthenticationException {
Map<String, String> params = getLoginParams();
params.put("refresh_token", refreshToken);
params.put("grant_type", "refresh_token");

MicrosoftRefreshResponse response = http.postFormGetJson(
MICROSOFT_TOKEN_ENDPOINT,
params, MicrosoftRefreshResponse.class
);

return loginWithTokens(new AuthTokens(response.getAccessToken(), response.getRefreshToken()),retrieveProfile);
}

/**
* Logs in a player using a Microsoft account tokens retrieved earlier.
* <b>If the token was retrieved using Azure AAD/MSAL, it should be prefixed with d=</b>
Expand Down