aboutsummaryrefslogtreecommitdiff
path: root/azalea-auth/examples
diff options
context:
space:
mode:
authorAdam Reisenauer <58893124+Mythbusters123@users.noreply.github.com>2023-06-24 18:09:43 -0400
committerGitHub <noreply@github.com>2023-06-24 17:09:43 -0500
commit5e4699688207b8ac722ae7f96c49428242f49a9d (patch)
tree52b0f9b8507fa380376dab81411cb74eed413c95 /azalea-auth/examples
parentfe687f9bdbdf3e0214ac4ac6da47a181e4dc23dd (diff)
downloadazalea-drasl-5e4699688207b8ac722ae7f96c49428242f49a9d.tar.xz
Add functions `auth_with_link_code`, `get_ms_link_code`, and `get_ms_auth_token`. (#88)
* Add option for grabbing authentication code for Microsoft seperately. Created two new functions, one that outputs the DeviceCodeResponse and one that uses this response to authenticate an actual account. * Added documentation and cleaned up function names. Still wondering about code repeition * reduce code duplication, more docs, cleanup * clippy --------- Co-authored-by: mat <git@matdoes.dev>
Diffstat (limited to 'azalea-auth/examples')
-rwxr-xr-xazalea-auth/examples/auth_manual.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/azalea-auth/examples/auth_manual.rs b/azalea-auth/examples/auth_manual.rs
new file mode 100755
index 00000000..6a9510a8
--- /dev/null
+++ b/azalea-auth/examples/auth_manual.rs
@@ -0,0 +1,32 @@
+//! 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(())
+}
+
+async fn auth() -> Result<ProfileResponse, Box<dyn Error>> {
+ let client = reqwest::Client::new();
+
+ let res = azalea_auth::get_ms_link_code(&client).await?;
+ println!(
+ "Go to {} and enter the code {}",
+ res.verification_uri, res.user_code
+ );
+ let msa = azalea_auth::get_ms_auth_token(&client, res).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?)
+}