forked from azalea-rs/azalea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?) | ||
} |