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 "example@example.com",
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 "example@example.com",
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 502-508)
493 async fn microsoft(cache_key: &str) -> Result<Self, azalea_auth::AuthError> {
494 let minecraft_dir = minecraft_folder_path::minecraft_dir().unwrap_or_else(|| {
495 panic!(
496 "No {} environment variable found",
497 minecraft_folder_path::home_env_var()
498 )
499 });
500 let cache_file = minecraft_dir.join("azalea-auth.json");
501
502 let auth_result = azalea_auth::auth(
503 cache_key,
504 AuthOpts {
505 cache_file: Some(cache_file),
506 ..Default::default()
507 },
508 )
509 .await?;
510
511 Ok(Self::Microsoft {
512 cache_key: cache_key.to_owned(),
513 username: auth_result.profile.name,
514 uuid: auth_result.profile.id,
515 access_token: Mutex::new(auth_result.access_token),
516 // certs: Mutex::new(None),
517 })
518 }