authenticateWithXBOX function
Perform a login with a previously acquired XSTS Token. This returns a classic Minecraft access token which can be used in the Minecraft client to authenticate itself.
This is essentially the replacement for authenticate, which got the JWT access token through Yggdrasil.
The XSTS Token can be obtained by going through the
Microsoft Authentication Scheme,
for which some endpoints have been provided in microsoft_api.dart
.
However, I have not implemented the Azure OAuth flow but I'd love if anyone wanted to do it and opened a PR with the feature at https://github.com/spnda/dart_minecraft/pulls.
Implementation
Future<String> authenticateWithXBOX(String xstsToken, String userHash) async {
final headers = {
'content-type': 'application/json',
};
final response = await requestBody(
http.post,
_minecraftServicesApi,
'authentication/login_with_xbox',
{
'identityToken': 'XBL3.0 x=$userHash;$xstsToken',
},
headers: headers);
if (response.statusCode == 401) {
throw AuthException('Unauthorized (XSTS token expired or invalid)');
}
return parseResponseMap(response)['access_token'];
}