Skip to content

Commit

Permalink
Handle auth timeouts better
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Feb 20, 2024
1 parent 9f5bbbe commit 70286e0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ protected String getMsaToken() {
try {
return liveTokenManager.authDeviceCode().get();
} catch (InterruptedException | ExecutionException e) {
logger.error("Failed to get authentication token from device code", e);
logger.error("Failed to get authentication token from device code: " + e.getMessage());
logger.debug(Utils.getStackTrace(e));
return "";
}
}
Expand All @@ -131,15 +132,21 @@ protected XboxTokenInfo getXboxToken() {
return xboxTokenManager.getCachedXstsToken();
} else {
String msaToken = getMsaToken();
String deviceToken = xboxTokenManager.getDeviceToken();
SISUAuthenticationResponse sisuAuthenticationResponse = xboxTokenManager.getSISUToken(msaToken, deviceToken);
if (sisuAuthenticationResponse == null) {
logger.info("SISU authentication response is null, please login again");
liveTokenManager.clearTokenCache();
return getXboxToken();
if (!msaToken.isEmpty()) {
String deviceToken = xboxTokenManager.getDeviceToken();
SISUAuthenticationResponse sisuAuthenticationResponse = xboxTokenManager.getSISUToken(msaToken, deviceToken);
if (sisuAuthenticationResponse != null) {
return xboxTokenManager.getXSTSToken(sisuAuthenticationResponse);
} else {
logger.info("SISU authentication response is null, please login again");
}
} else {
logger.info("MSA authentication response is null, please login again");
}
return xboxTokenManager.getXSTSToken(sisuAuthenticationResponse);
}

liveTokenManager.clearTokenCache();
return getXboxToken();
}

/**
Expand Down
21 changes: 21 additions & 0 deletions core/src/main/java/com/rtm516/mcxboxbroadcast/core/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.rtm516.mcxboxbroadcast.core;

import java.io.PrintWriter;
import java.io.StringWriter;

public class Utils {
public static String getStackTrace(Throwable ex) {
// Create a PrintWriter to write the stack trace to
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);

// Write the stack trace to the PrintWriter
ex.printStackTrace(pw);

// Close the PrintWriter
pw.close();

// Return the stack trace as a string
return sw.toString();
}
}

0 comments on commit 70286e0

Please sign in to comment.