getMinecraftAccessToken method
Implementation
@override
Future<MinecraftTokenResponse> getMinecraftAccessToken(
String uhs,
String xstsToken,
) async {
try {
final response = await _httpClient.post(
Uri.parse(
'https://api.minecraftservices.com/authentication/login_with_xbox',
),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({"identityToken": "XBL3.0 x=$uhs;$xstsToken"}),
);
if (response.statusCode == 200) {
final tokenResponse = MinecraftTokenResponse.fromJson(
jsonDecode(response.body),
);
_minecraftToken = tokenResponse.accessToken;
_tokenExpiration = DateTime.now().add(Duration(seconds: tokenResponse.expiresIn));
return tokenResponse;
} else {
throw Exception('Minecraft token retrieval failed: ${response.body}');
}
} catch (e) {
throw Exception('Failed to retrieve Minecraft access token: $e');
}
}