#minecraft #microsoft #service #account #access #authenticating #online

minecraft-msa-auth

A library for authenticating with Microsoft accounts to access online Minecraft services

5 releases (3 breaking)

new 0.4.0 Apr 21, 2024
0.3.0 Feb 23, 2023
0.2.0 Feb 23, 2023
0.1.1 Feb 22, 2023
0.1.0 Feb 22, 2023

#171 in Authentication

Download history 6/week @ 2024-01-04 4/week @ 2024-01-11 8/week @ 2024-02-08 15/week @ 2024-02-15 32/week @ 2024-02-22 14/week @ 2024-02-29 18/week @ 2024-03-07 19/week @ 2024-03-14 61/week @ 2024-03-21 82/week @ 2024-03-28 20/week @ 2024-04-04 20/week @ 2024-04-11 157/week @ 2024-04-18

305 downloads per month

MIT/Apache

25KB
157 lines

minecraft-msa-auth

Crates.io docs.rs MIT/Apache 2.0 Crates.io Rust

This crate allows you to authenticate into Minecraft online services using a Microsoft Oauth2 token. You can integrate it with oauth2-rs and build interactive authentication flows.

Example

const DEVICE_CODE_URL: &str = "https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode";
const MSA_AUTHORIZE_URL: &str = "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize";
const MSA_TOKEN_URL: &str = "https://login.microsoftonline.com/common/oauth2/v2.0/token";

let client = BasicClient::new(
    ClientId::new(client_id),
    None,
    AuthUrl::new(MSA_AUTHORIZE_URL.to_string())?,
    Some(TokenUrl::new(MSA_TOKEN_URL.to_string())?),
)
.set_device_authorization_url(DeviceAuthorizationUrl::new(DEVICE_CODE_URL.to_string())?);

let details: StandardDeviceAuthorizationResponse = client
    .exchange_device_code()?
    .add_scope(Scope::new("XboxLive.signin offline_access".to_string()))
    .request_async(async_http_client)
    .await?;

println!(
    "Open this URL in your browser: {} and enter the code: {}",
    details.verification_uri().to_string(),
    details.user_code().secret().to_string()
);

let token = client
    .exchange_device_access_token(&details)
    .request_async(async_http_client, tokio::time::sleep, None)
    .await?;
println!("microsoft token: {:?}", token);

let mc_flow = MinecraftAuthorizationFlow::new(Client::new());
let mc_token = mc_flow.exchange_microsoft_token(token.access_token()).await?;
println!("minecraft token: {:?}", mc_token);

See full examples in the examples folder.

License

Except where noted (below and/or in individual files), all code in this repository is dual-licensed under either:

Dependencies

~5–19MB
~246K SLoC