refreshAuthentication method

Future<bool> refreshAuthentication()

Implementation

Future<bool> refreshAuthentication() async {
  if (_microsoftRefreshToken == null) {
    return false;
  }

  try {
    _accessToken = await _microsoftAuthService.refreshAccessToken(
      _microsoftRefreshToken!,
    );
    if (_accessToken == null) {
      return false;
    }

    final xstsResponse = await _xboxAuthService.getXstsToken(_accessToken!);
    final xstsToken = xstsResponse['token']!;
    final uhs = xstsResponse['uhs']!;
    _xstsToken = xstsToken;
    _xstsUhs = uhs;

    final tokenResponse = await _minecraftAuthService.getMinecraftAccessToken(
      uhs,
      xstsToken,
    );
    _minecraftToken = tokenResponse.accessToken;

    try {
      _minecraftProfile = await _minecraftAuthService.getAccountprofile();
    } catch (e) {
      debugPrint('Failed to get Minecraft profile during refresh: $e');
    }

    return true;
  } catch (e) {
    debugPrint('Failed to refresh authentication: $e');
    return false;
  }
}