pub async fn auth(
cache_key: &str,
opts: AuthOpts<'_>,
) -> Result<AuthResult, AuthError>Expand description
Authenticate with Microsoft. If the data isn’t cached, the user will be asked to go to log into Microsoft in a web page.
The cache key is an arbitrary string that’s used to identify the account in the future. The account email is often used for this.
If you want to use your own code to cache or show the auth code to the user
in a different way, use get_ms_link_code, get_ms_auth_token,
get_minecraft_token and get_profile instead.
Examples found in repository?
azalea-auth/examples/auth.rs (lines 9-15)
4async fn main() {
5 env_logger::init();
6
7 let cache_file = PathBuf::from("example_cache.json");
8
9 let auth_result = azalea_auth::auth(
10 "[email protected]",
11 azalea_auth::AuthOpts {
12 cache_file: Some(cache_file),
13 ..Default::default()
14 },
15 )
16 .await
17 .unwrap();
18 println!("{auth_result:?}");
19}More examples
azalea-auth/examples/certificates.rs (lines 9-15)
4async fn main() {
5 env_logger::init();
6
7 let cache_file = PathBuf::from("example_cache.json");
8
9 let auth_result = azalea_auth::auth(
10 "[email protected]",
11 azalea_auth::AuthOpts {
12 cache_file: Some(cache_file),
13 ..Default::default()
14 },
15 )
16 .await
17 .unwrap();
18
19 let certs = azalea_auth::certs::fetch_certificates(&auth_result.access_token)
20 .await
21 .unwrap();
22
23 println!("{certs:?}");
24}azalea-protocol/examples/packet_logger.rs (lines 473-479)
464 async fn microsoft(cache_key: &str) -> Result<Self, azalea_auth::AuthError> {
465 let minecraft_dir = minecraft_folder_path::minecraft_dir().unwrap_or_else(|| {
466 panic!(
467 "No {} environment variable found",
468 minecraft_folder_path::home_env_var()
469 )
470 });
471 let cache_file = minecraft_dir.join("azalea-auth.json");
472
473 let auth_result = azalea_auth::auth(
474 cache_key,
475 AuthOpts {
476 cache_file: Some(cache_file),
477 ..Default::default()
478 },
479 )
480 .await?;
481
482 Ok(Self::Microsoft {
483 cache_key: cache_key.to_owned(),
484 username: auth_result.profile.name,
485 uuid: auth_result.profile.id,
486 access_token: Mutex::new(auth_result.access_token),
487 // certs: Mutex::new(None),
488 })
489 }