Skip to content

Commit

Permalink
fix incorrect comment in with_microsoft_access_token docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Aug 15, 2024
1 parent 74831ab commit e485cf5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
27 changes: 14 additions & 13 deletions azalea-auth/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
time::{Instant, SystemTime, UNIX_EPOCH},
};
use thiserror::Error;
use tracing::{error, trace};
use uuid::Uuid;

#[derive(Default)]
Expand Down Expand Up @@ -92,7 +93,7 @@ pub async fn auth<'a>(email: &str, opts: AuthOpts<'a>) -> Result<AuthResult, Aut
interactive_get_ms_auth_token(&client, email, Some(client_id), Some(scope)).await?
};
if msa.is_expired() {
tracing::trace!("refreshing Microsoft auth token");
trace!("refreshing Microsoft auth token");
match refresh_ms_auth_token(
&client,
&msa.data.refresh_token,
Expand All @@ -104,7 +105,7 @@ pub async fn auth<'a>(email: &str, opts: AuthOpts<'a>) -> Result<AuthResult, Aut
Ok(new_msa) => msa = new_msa,
Err(e) => {
// can't refresh, ask the user to auth again
tracing::error!("Error refreshing Microsoft auth token: {}", e);
error!("Error refreshing Microsoft auth token: {}", e);
msa =
interactive_get_ms_auth_token(&client, email, Some(client_id), Some(scope))
.await?;
Expand All @@ -113,7 +114,7 @@ pub async fn auth<'a>(email: &str, opts: AuthOpts<'a>) -> Result<AuthResult, Aut
}

let msa_token = &msa.data.access_token;
tracing::trace!("Got access token: {msa_token}");
trace!("Got access token: {msa_token}");

let res = get_minecraft_token(&client, msa_token).await?;

Expand All @@ -140,7 +141,7 @@ pub async fn auth<'a>(email: &str, opts: AuthOpts<'a>) -> Result<AuthResult, Aut
)
.await
{
tracing::error!("{}", e);
error!("{}", e);
}
}

Expand Down Expand Up @@ -356,7 +357,7 @@ pub async fn get_ms_auth_token(
while Instant::now() < login_expires_at {
tokio::time::sleep(std::time::Duration::from_secs(res.interval)).await;

tracing::trace!("Polling to check if user has logged in...");
trace!("Polling to check if user has logged in...");
if let Ok(access_token_response) = client
.post(format!(
"https://login.live.com/oauth20_token.srf?client_id={client_id}"
Expand All @@ -371,7 +372,7 @@ pub async fn get_ms_auth_token(
.json::<AccessTokenResponse>()
.await
{
tracing::trace!("access_token_response: {:?}", access_token_response);
trace!("access_token_response: {:?}", access_token_response);
let expires_at = SystemTime::now()
+ std::time::Duration::from_secs(access_token_response.expires_in);
return Ok(ExpiringValue {
Expand All @@ -397,7 +398,7 @@ pub async fn interactive_get_ms_auth_token(
scope: Option<&str>,
) -> Result<ExpiringValue<AccessTokenResponse>, GetMicrosoftAuthTokenError> {
let res = get_ms_link_code(client, client_id, scope).await?;
tracing::trace!("Device code response: {:?}", res);
trace!("Device code response: {:?}", res);
println!(
"Go to \x1b[1m{}\x1b[m and enter the code \x1b[1m{}\x1b[m for \x1b[1m{}\x1b[m",
res.verification_uri, res.user_code, email
Expand Down Expand Up @@ -473,7 +474,7 @@ async fn auth_with_xbox_live(
"TokenType": "JWT"
});
let payload = auth_json.to_string();
tracing::trace!("auth_json: {:#?}", auth_json);
trace!("auth_json: {:#?}", auth_json);
let res = client
.post("https://user.auth.xboxlive.com/user/authenticate")
.header("Content-Type", "application/json")
Expand All @@ -486,7 +487,7 @@ async fn auth_with_xbox_live(
.await?
.json::<XboxLiveAuthResponse>()
.await?;
tracing::trace!("Xbox Live auth response: {:?}", res);
trace!("Xbox Live auth response: {:?}", res);

// not_after looks like 2020-12-21T19:52:08.4463796Z
let expires_at = DateTime::parse_from_rfc3339(&res.not_after)
Expand Down Expand Up @@ -527,7 +528,7 @@ async fn obtain_xsts_for_minecraft(
.await?
.json::<XboxLiveAuthResponse>()
.await?;
tracing::trace!("Xbox Live auth response (for XSTS): {:?}", res);
trace!("Xbox Live auth response (for XSTS): {:?}", res);

Ok(res.token)
}
Expand All @@ -553,7 +554,7 @@ async fn auth_with_minecraft(
.await?
.json::<MinecraftAuthResponse>()
.await?;
tracing::trace!("{:?}", res);
trace!("{:?}", res);

let expires_at = SystemTime::now() + std::time::Duration::from_secs(res.expires_in);
Ok(ExpiringValue {
Expand All @@ -580,7 +581,7 @@ pub async fn check_ownership(
.await?
.json::<GameOwnershipResponse>()
.await?;
tracing::trace!("{:?}", res);
trace!("{:?}", res);

// vanilla checks here to make sure the signatures are right, but it's not
// actually required so we just don't
Expand All @@ -605,7 +606,7 @@ pub async fn get_profile(
.await?
.json::<ProfileResponse>()
.await?;
tracing::trace!("{:?}", res);
trace!("{:?}", res);

Ok(res)
}
5 changes: 3 additions & 2 deletions azalea-auth/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use thiserror::Error;
use tokio::fs::File;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tracing::{debug, trace};

#[derive(Debug, Error)]
pub enum CacheError {
Expand Down Expand Up @@ -82,13 +83,13 @@ async fn get_entire_cache(cache_file: &Path) -> Result<Vec<CachedAccount>, Cache
Ok(cache)
}
async fn set_entire_cache(cache_file: &Path, cache: Vec<CachedAccount>) -> Result<(), CacheError> {
tracing::trace!("saving cache: {:?}", cache);
trace!("saving cache: {:?}", cache);

if !cache_file.exists() {
let cache_file_parent = cache_file
.parent()
.expect("Cache file is root directory and also doesn't exist.");
tracing::debug!(
debug!(
"Making cache file parent directory at {}",
cache_file_parent.to_string_lossy()
);
Expand Down
3 changes: 2 additions & 1 deletion azalea-auth/src/certs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use chrono::{DateTime, Utc};
use rsa::{pkcs8::DecodePrivateKey, RsaPrivateKey};
use serde::Deserialize;
use thiserror::Error;
use tracing::trace;

#[derive(Debug, Error)]
pub enum FetchCertificatesError {
Expand All @@ -26,7 +27,7 @@ pub async fn fetch_certificates(
.await?
.json::<CertificatesResponse>()
.await?;
tracing::trace!("{:?}", res);
trace!("{:?}", res);

// using RsaPrivateKey::from_pkcs8_pem gives an error with decoding base64 so we
// just decode it ourselves
Expand Down
6 changes: 3 additions & 3 deletions azalea-chat/src/translatable_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ fn serialize_args_as_nbt(args: &[StringOrComponent]) -> simdnbt::owned::NbtList
// if it's all components then make it a compound list
// if it's a mix then return an error

use tracing::debug;

let mut string_list = Vec::new();
let mut compound_list = Vec::new();

Expand All @@ -68,9 +70,7 @@ fn serialize_args_as_nbt(args: &[StringOrComponent]) -> simdnbt::owned::NbtList
if !string_list.is_empty() && !compound_list.is_empty() {
// i'm actually not sure what vanilla does here, so i just made it return the
// string list
tracing::debug!(
"Tried to serialize a TranslatableComponent with a mix of strings and components."
);
debug!("Tried to serialize a TranslatableComponent with a mix of strings and components.");
return string_list.into();
}

Expand Down
5 changes: 3 additions & 2 deletions azalea-client/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use azalea_auth::AccessTokenResponse;
use bevy_ecs::component::Component;
use parking_lot::Mutex;
use thiserror::Error;
use tracing::trace;
use uuid::Uuid;

/// Something that can join Minecraft servers.
Expand Down Expand Up @@ -135,7 +136,7 @@ impl Account {
/// the authentication process (like doing your own caching or
/// displaying the Microsoft user code to the user in a different way).
///
/// Note that this will not refresh the token when it expires.
/// This will refresh the given token if it's expired.
///
/// ```
/// # use azalea_client::Account;
Expand Down Expand Up @@ -170,7 +171,7 @@ impl Account {
let client = reqwest::Client::new();

if msa.is_expired() {
tracing::trace!("refreshing Microsoft auth token");
trace!("refreshing Microsoft auth token");
msa = azalea_auth::refresh_ms_auth_token(
&client,
&msa.data.refresh_token,
Expand Down
2 changes: 1 addition & 1 deletion azalea-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ impl Client {
}

if self.logged_in() {
tracing::debug!(
debug!(
"Sending client information (already logged in): {:?}",
client_information
);
Expand Down

0 comments on commit e485cf5

Please sign in to comment.