Skip to content

Commit

Permalink
More old code removal
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Jun 19, 2024
1 parent bc71d81 commit 00ce8b3
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.nukkitx.protocol.bedrock.BedrockPong;
import com.rtm516.mcxboxbroadcast.core.SessionInfo;
import com.rtm516.mcxboxbroadcast.core.SessionManager;
import com.rtm516.mcxboxbroadcast.core.SubSessionManager;
import com.rtm516.mcxboxbroadcast.core.configs.StandaloneConfig;
import com.rtm516.mcxboxbroadcast.core.exceptions.SessionCreationException;
import com.rtm516.mcxboxbroadcast.core.exceptions.SessionUpdateException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.raphimc.minecraftauth.util.JsonUtil;
import net.raphimc.minecraftauth.util.MicrosoftConstants;
import net.raphimc.minecraftauth.util.OAuthEnvironment;
import net.raphimc.minecraftauth.util.logging.ILogger;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -48,19 +47,21 @@ public AuthManager(String cache, Logger logger) {
this.oldXboxAuth = Paths.get(cache, "xbox_token.json");
this.logger = logger;

// Replace the default logger with one we control
MinecraftAuth.LOGGER = logger.prefixed("Auth");

httpClient = MinecraftAuth.createHttpClient();
this.httpClient = MinecraftAuth.createHttpClient();

appDetails = new MsaCodeStep.ApplicationDetails(MicrosoftConstants.BEDROCK_ANDROID_TITLE_ID, MicrosoftConstants.SCOPE_TITLE_AUTH, null, null, OAuthEnvironment.LIVE);
initialAuth = new StepMsaToken(new StepMsaDeviceCodeMsaCode(new StepMsaDeviceCode(appDetails), 120 * 1000));
stepDeviceToken = new StepXblDeviceToken("Android");
// Setup the authentication steps
this.appDetails = new MsaCodeStep.ApplicationDetails(MicrosoftConstants.BEDROCK_ANDROID_TITLE_ID, MicrosoftConstants.SCOPE_TITLE_AUTH, null, null, OAuthEnvironment.LIVE);
this.initialAuth = new StepMsaToken(new StepMsaDeviceCodeMsaCode(new StepMsaDeviceCode(this.appDetails), 120 * 1000));
this.stepDeviceToken = new StepXblDeviceToken("Android");

StepInitialXblSession xblAuth = new StepInitialXblSession(initialAuth, new StepXblDeviceToken("Android"));
StepInitialXblSession xblAuth = new StepInitialXblSession(this.initialAuth, new StepXblDeviceToken("Android"));

xstsAuth = new StepXblSisuAuthentication(xblAuth, MicrosoftConstants.XBL_XSTS_RELYING_PARTY);
this.xstsAuth = new StepXblSisuAuthentication(xblAuth, MicrosoftConstants.XBL_XSTS_RELYING_PARTY);

xstsToken = null;
this.xstsToken = null;
}

/**
Expand Down Expand Up @@ -109,6 +110,9 @@ private void importLiveTokens() {
}
}

/**
* Follow the auth flow to get the Xbox token and store it
*/
private void initialise() {
importLiveTokens();

Expand All @@ -120,6 +124,7 @@ private void initialise() {
}

try {
// Get the XSTS token or refresh it if it's expired
if (xstsToken == null) {
xstsToken = xstsAuth.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> {
logger.info("To sign in, use a web browser to open the page " + msaDeviceCode.getVerificationUri() + " and enter the code " + msaDeviceCode.getUserCode() + " to authenticate.");
Expand All @@ -131,13 +136,19 @@ private void initialise() {
// Save to cache.json
Files.writeString(cache, JsonUtil.GSON.toJson(xstsAuth.toJson(xstsToken)));

// Construct and store the Xbox token info
xboxTokenInfo = new XboxTokenInfo(xstsToken.getDisplayClaims().get("xid"), xstsToken.getUserHash(), xstsToken.getDisplayClaims().get("gtg"), xstsToken.getToken(), String.valueOf(xstsToken.getExpireTimeMs()));

} catch (Exception e) {
throw new RuntimeException(e);
}
}

/**
* Get the Xbox token info
* If the token is expired or missing then refresh it
*
* @return The Xbox token info
*/
public XboxTokenInfo getXboxToken() {
if (xstsToken == null || xboxTokenInfo == null || xstsToken.isExpired()) {
initialise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,10 @@
public class Constants {
public static final Gson GSON = new GsonBuilder().registerTypeAdapter(Instant.class, new InstantConverter()).create();

public static final String AUTH_TITLE = "0000000048183522"; // 00000000441cc96b Nintendo Switch, 0000000048183522 Android
public static final String SCOPE = "service::user.auth.xboxlive.com::MBI_SSL";
public static final String RELAYING_PARTY = "http://xboxlive.com";

public static final String SERVICE_CONFIG_ID = "4fc10100-5f7a-4470-899b-280835760c07"; // The service config ID for Minecraft
public static final String CREATE_SESSION = "https://sessiondirectory.xboxlive.com/serviceconfigs/" + SERVICE_CONFIG_ID + "/sessionTemplates/MinecraftLobby/sessions/%s";
public static final String JOIN_SESSION = "https://sessiondirectory.xboxlive.com/handles/%s/session";

public static final URI LIVE_DEVICE_CODE_REQUEST = URI.create("https://login.live.com/oauth20_connect.srf");
public static final URI LIVE_TOKEN_REQUEST = URI.create("https://login.live.com/oauth20_token.srf");
public static final URI DEVICE_AUTHENTICATE_REQUEST = URI.create("https://device.auth.xboxlive.com/device/authenticate");
public static final URI XSTS_AUTHENTICATE_REQUEST = URI.create("https://xsts.auth.xboxlive.com/xsts/authorize");
public static final URI RTA_WEBSOCKET = URI.create("wss://rta.xboxlive.com/connect");
public static final URI CREATE_HANDLE = URI.create("https://sessiondirectory.xboxlive.com/handles");

Expand Down
50 changes: 0 additions & 50 deletions core/src/main/java/com/rtm516/mcxboxbroadcast/core/Utils.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class JoinSessionRequest {
public Map<String, SessionMember> members;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.rtm516.mcxboxbroadcast.core.models.session;

import com.rtm516.mcxboxbroadcast.core.ExpandedSessionInfo;

import java.util.Collections;
import java.util.List;

public record SessionCustomProperties(
Expand Down

0 comments on commit 00ce8b3

Please sign in to comment.