runelite-client: destroy session on logout
This commit is contained in:
@@ -28,6 +28,7 @@ import com.google.gson.JsonParseException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.UUID;
|
||||||
import net.runelite.http.api.RuneliteAPI;
|
import net.runelite.http.api.RuneliteAPI;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
@@ -36,17 +37,27 @@ import okhttp3.ResponseBody;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class LoginClient
|
public class AccountClient
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(LoginClient.class);
|
private static final Logger logger = LoggerFactory.getLogger(AccountClient.class);
|
||||||
|
|
||||||
|
private UUID uuid;
|
||||||
|
|
||||||
|
public AccountClient()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public AccountClient(UUID uuid)
|
||||||
|
{
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public OAuthResponse login() throws IOException
|
public OAuthResponse login() throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl.Builder builder = RuneliteAPI.getApiBase().newBuilder()
|
HttpUrl url = RuneliteAPI.getApiBase().newBuilder()
|
||||||
.addPathSegment("account")
|
.addPathSegment("account")
|
||||||
.addPathSegment("login");
|
.addPathSegment("login")
|
||||||
|
.build();
|
||||||
HttpUrl url = builder.build();
|
|
||||||
|
|
||||||
logger.debug("Built URI: {}", url);
|
logger.debug("Built URI: {}", url);
|
||||||
|
|
||||||
@@ -66,4 +77,26 @@ public class LoginClient
|
|||||||
throw new IOException(ex);
|
throw new IOException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void logout() throws IOException
|
||||||
|
{
|
||||||
|
HttpUrl url = RuneliteAPI.getApiBase().newBuilder()
|
||||||
|
.addPathSegment("account")
|
||||||
|
.addPathSegment("logout")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
logger.debug("Built URI: {}", url);
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.header(RuneliteAPI.RUNELITE_AUTH, uuid.toString())
|
||||||
|
.url(url)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Response response = RuneliteAPI.CLIENT.newCall(request).execute();
|
||||||
|
|
||||||
|
try (ResponseBody body = response.body())
|
||||||
|
{
|
||||||
|
logger.debug("Sent logout request");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ import net.runelite.client.ui.ClientUI;
|
|||||||
import net.runelite.client.ui.NavigationButton;
|
import net.runelite.client.ui.NavigationButton;
|
||||||
import net.runelite.client.ui.NavigationPanel;
|
import net.runelite.client.ui.NavigationPanel;
|
||||||
import net.runelite.client.util.RunnableExceptionLogger;
|
import net.runelite.client.util.RunnableExceptionLogger;
|
||||||
import net.runelite.http.api.account.LoginClient;
|
import net.runelite.http.api.account.AccountClient;
|
||||||
import net.runelite.http.api.account.OAuthResponse;
|
import net.runelite.http.api.account.OAuthResponse;
|
||||||
import net.runelite.http.api.ws.messages.LoginResponse;
|
import net.runelite.http.api.ws.messages.LoginResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -58,7 +58,7 @@ public class AccountPlugin extends Plugin
|
|||||||
private final NavigationButton loginButton = new NavigationButton("Login");
|
private final NavigationButton loginButton = new NavigationButton("Login");
|
||||||
private final NavigationButton logoutButton = new NavigationButton("Logout");
|
private final NavigationButton logoutButton = new NavigationButton("Logout");
|
||||||
|
|
||||||
private final LoginClient loginClient = new LoginClient();
|
private final AccountClient loginClient = new AccountClient();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
@@ -88,8 +88,23 @@ public class AccountPlugin extends Plugin
|
|||||||
|
|
||||||
private void logoutClick(ActionEvent ae)
|
private void logoutClick(ActionEvent ae)
|
||||||
{
|
{
|
||||||
runelite.closeSession();
|
// Destroy session
|
||||||
runelite.deleteSession();
|
AccountSession session = runelite.getAccountSession();
|
||||||
|
if (session != null)
|
||||||
|
{
|
||||||
|
AccountClient client = new AccountClient(session.getUuid());
|
||||||
|
try
|
||||||
|
{
|
||||||
|
client.logout();
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
logger.warn("Unable to logout of session", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runelite.closeSession(); // remove session from client
|
||||||
|
runelite.deleteSession(); // delete saved session file
|
||||||
|
|
||||||
// Replace logout nav button with login
|
// Replace logout nav button with login
|
||||||
NavigationPanel navigationPanel = ui.getNavigationPanel();
|
NavigationPanel navigationPanel = ui.getNavigationPanel();
|
||||||
|
|||||||
Reference in New Issue
Block a user