auth_manual/
auth_manual.rs

1//! Authenticate with Microsoft and get a Minecraft profile, but don't cache and
2//! use our own code to display the link code.
3//!
4//! If you still want it to cache, look at the code in [`azalea_auth::auth`] and
5//! see how that does it.
6
7use std::error::Error;
8
9use azalea_auth::ProfileResponse;
10
11#[tokio::main]
12async fn main() -> Result<(), Box<dyn Error>> {
13    env_logger::init();
14
15    let profile = auth().await?;
16    println!("Logged in as {}", profile.name);
17
18    Ok(())
19}
20
21// We will be using default `client_id` and `scope`
22async fn auth() -> Result<ProfileResponse, Box<dyn Error>> {
23    let client = reqwest::Client::new();
24
25    let res = azalea_auth::get_ms_link_code(&client, None, None).await?;
26    println!(
27        "Go to {} and enter the code {}",
28        res.verification_uri, res.user_code
29    );
30    let msa = azalea_auth::get_ms_auth_token(&client, res, None).await?;
31    let auth_result = azalea_auth::get_minecraft_token(&client, &msa.data.access_token).await?;
32    Ok(azalea_auth::get_profile(&client, &auth_result.minecraft_access_token).await?)
33}