Skip to content

Commit

Permalink
added auth session example
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Jan 6, 2024
1 parent 0904e5e commit 7aab6c1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions azalea-auth/examples/auth_session.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Authenticate with Microsoft and get a Minecraft profile, but don't cache and
//! use our own code to display the link code.
//!
//! If you still want it to cache, look at the code in [`azalea_auth::auth`] and
//! see how that does it.
use std::error::Error;

use azalea_auth::ProfileResponse;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();

let profile = auth().await?;
println!("Logged in as {}", profile.name);

Ok(())
}

const REFRESH_TOKEN: &str = "TOKEN_HERE";

async fn auth() -> Result<ProfileResponse, Box<dyn Error>> {
let client = reqwest::Client::new();

let msa = azalea_auth::refresh_ms_auth_token(&client, REFRESH_TOKEN).await?;
let auth_result = azalea_auth::get_minecraft_token(&client, &msa.data.access_token).await?;
Ok(azalea_auth::get_profile(&client, &auth_result.minecraft_access_token).await?)
}

0 comments on commit 7aab6c1

Please sign in to comment.