aboutsummaryrefslogtreecommitdiff
path: root/azalea-auth/src
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-12-11 22:47:16 -0600
committerGitHub <noreply@github.com>2025-12-11 22:47:16 -0600
commit4a66f002c276a57e028e9456f6800b0b3c248885 (patch)
treef87cbdc51c09d497548f972b9b1633ceb7606443 /azalea-auth/src
parentff1e28f88e93ba83cf76569b5613445b841efd45 (diff)
downloadazalea-drasl-4a66f002c276a57e028e9456f6800b0b3c248885.tar.xz
Add options to request Mojang sessionserver with a proxy (#293)
* add options to request mojang sessionserver with a socks5 proxy * update changelog * rename auth_proxy to sessionserver_proxy
Diffstat (limited to 'azalea-auth/src')
-rw-r--r--azalea-auth/src/sessionserver.rs42
1 files changed, 27 insertions, 15 deletions
diff --git a/azalea-auth/src/sessionserver.rs b/azalea-auth/src/sessionserver.rs
index e8ab5de7..6c304942 100644
--- a/azalea-auth/src/sessionserver.rs
+++ b/azalea-auth/src/sessionserver.rs
@@ -51,28 +51,40 @@ pub struct ForbiddenError {
pub path: String,
}
-static REQWEST_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(reqwest::Client::new);
+pub struct SessionServerJoinOpts<'a> {
+ pub access_token: &'a str,
+ /// Given to us by the
+ pub public_key: &'a [u8],
+ pub private_key: &'a [u8],
+ pub uuid: &'a Uuid,
+ /// This is given to us by the server, but it's typically an empty string.
+ pub server_id: &'a str,
+
+ pub proxy: Option<reqwest::Proxy>,
+}
/// Tell Mojang's servers that you are going to join a multiplayer server,
/// which is required to join online-mode servers.
-///
-/// The server ID should typically be an empty string.
-pub async fn join(
- access_token: &str,
- public_key: &[u8],
- private_key: &[u8],
- uuid: &Uuid,
- server_id: &str,
-) -> Result<(), ClientSessionServerError> {
- let client = REQWEST_CLIENT.clone();
+pub async fn join(opts: SessionServerJoinOpts<'_>) -> 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()?
+ } else {
+ // no_proxy so we don't check reqwest's proxy env variables (because azalea
+ // doesn't handle them when connecting to servers anyways)
+ static REQWEST_CLIENT: LazyLock<reqwest::Client> =
+ LazyLock::new(|| reqwest::ClientBuilder::new().no_proxy().build().unwrap());
+
+ REQWEST_CLIENT.clone()
+ };
let server_hash = azalea_crypto::hex_digest(&azalea_crypto::digest_data(
- server_id.as_bytes(),
- public_key,
- private_key,
+ opts.server_id.as_bytes(),
+ opts.public_key,
+ opts.private_key,
));
- join_with_server_id_hash(&client, access_token, uuid, &server_hash).await
+ join_with_server_id_hash(&client, opts.access_token, opts.uuid, &server_hash).await
}
pub async fn join_with_server_id_hash(