minecraft-msa-auth

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

```rust const DEVICECODEURL: &str = "https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode"; const MSAAUTHORIZEURL: &str = "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize"; const MSATOKENURL: &str = "https://login.microsoftonline.com/common/oauth2/v2.0/token";

let client = BasicClient::new( ClientId::new(clientid), None, AuthUrl::new(MSAAUTHORIZEURL.tostring())?, Some(TokenUrl::new(MSATOKENURL.tostring())?), ) .setdeviceauthorizationurl(DeviceAuthorizationUrl::new(DEVICECODEURL.to_string())?);

let details: StandardDeviceAuthorizationResponse = client .exchangedevicecode()? .addscope(Scope::new("XboxLive.signin offlineaccess".tostring())) .requestasync(asynchttpclient) .await?;

println!( "Open this URL in your browser: {} and enter the code: {}", details.verificationuri().tostring(), details.usercode().secret().tostring() );

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

let mcflow = MinecraftAuthorizationFlow::new(Client::new()); let mctoken = mcflow.exchangemicrosofttoken(token.accesstoken()).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: