aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2026-05-10 16:44:50 +0200
committerLizzy Fleckenstein <lizzy@vlhl.dev>2026-05-10 16:44:50 +0200
commit448d4c630b4b06ee2870205c1d9267413caf24df (patch)
tree5effdfe382a9b1311cdf344902c24be220b12301
parent98f9f7cd2eaf64c18cca354c2062227a4abf6df0 (diff)
downloadazalea-drasl-448d4c630b4b06ee2870205c1d9267413caf24df.tar.xz
allow custom session backend
-rw-r--r--azalea-auth/src/sessionserver.rs54
1 files changed, 51 insertions, 3 deletions
diff --git a/azalea-auth/src/sessionserver.rs b/azalea-auth/src/sessionserver.rs
index 6c304942..02ec9c60 100644
--- a/azalea-auth/src/sessionserver.rs
+++ b/azalea-auth/src/sessionserver.rs
@@ -66,6 +66,13 @@ pub struct SessionServerJoinOpts<'a> {
/// Tell Mojang's servers that you are going to join a multiplayer server,
/// which is required to join online-mode servers.
pub async fn join(opts: SessionServerJoinOpts<'_>) -> Result<(), ClientSessionServerError> {
+ join_with_backend_url(opts, "https://sessionserver.mojang.com/session").await
+}
+
+pub async fn join_with_backend_url(
+ opts: SessionServerJoinOpts<'_>,
+ backend: &str,
+) -> Result<(), ClientSessionServerError> {
let client = if let Some(proxy) = opts.proxy {
// reusing the client is too complicated if we're using proxies, so don't bother
reqwest::ClientBuilder::new().proxy(proxy).build()?
@@ -84,7 +91,14 @@ pub async fn join(opts: SessionServerJoinOpts<'_>) -> Result<(), ClientSessionSe
opts.private_key,
));
- join_with_server_id_hash(&client, opts.access_token, opts.uuid, &server_hash).await
+ join_with_server_id_hash_and_backend_url(
+ &client,
+ opts.access_token,
+ opts.uuid,
+ &server_hash,
+ backend,
+ )
+ .await
}
pub async fn join_with_server_id_hash(
@@ -93,6 +107,23 @@ pub async fn join_with_server_id_hash(
uuid: &Uuid,
server_hash: &str,
) -> Result<(), ClientSessionServerError> {
+ join_with_server_id_hash_and_backend_url(
+ client,
+ access_token,
+ uuid,
+ server_hash,
+ "https://sessionserver.mojang.com/session",
+ )
+ .await
+}
+
+pub async fn join_with_server_id_hash_and_backend_url(
+ client: &reqwest::Client,
+ access_token: &str,
+ uuid: &Uuid,
+ server_hash: &str,
+ backend: &str,
+) -> Result<(), ClientSessionServerError> {
let mut encode_buffer = Uuid::encode_buffer();
let undashed_uuid = uuid.simple().encode_lower(&mut encode_buffer);
@@ -102,7 +133,7 @@ pub async fn join_with_server_id_hash(
"serverId": server_hash
});
let res = client
- .post("https://sessionserver.mojang.com/session/minecraft/join")
+ .post(format!("{backend}/minecraft/join"))
.json(&data)
.send()
.await?;
@@ -147,6 +178,23 @@ pub async fn serverside_auth(
private_key: &[u8; 16],
ip: Option<&str>,
) -> Result<GameProfile, ServerSessionServerError> {
+ serverside_auth_with_backend_url(
+ username,
+ public_key,
+ private_key,
+ ip,
+ "https://sessionserver.mojang.com/session",
+ )
+ .await
+}
+
+pub async fn serverside_auth_with_backend_url(
+ username: &str,
+ public_key: &[u8],
+ private_key: &[u8; 16],
+ ip: Option<&str>,
+ backend: &str,
+) -> Result<GameProfile, ServerSessionServerError> {
let hash = azalea_crypto::hex_digest(&azalea_crypto::digest_data(
"".as_bytes(),
public_key,
@@ -154,7 +202,7 @@ pub async fn serverside_auth(
));
let url = reqwest::Url::parse_with_params(
- "https://sessionserver.mojang.com/session/minecraft/hasJoined",
+ &format!("{backend}/minecraft/hasJoined"),
if let Some(ip) = ip {
vec![("username", username), ("serverId", &hash), ("ip", ip)]
} else {