#minecraft #flow #live #server #user #xbox

mc_auth

一个用于与Mojang认证服务器进行认证的简单库

1 个不稳定版本

0.1.0 2023年9月11日

#808认证

MIT 许可证

12KB
189

MC Auth

Rust中Minecraft的Xbox live认证流程。

为什么?

为了创建基于Rust的Minecraft工具并实现用户资料,必须首先通过Microsoft服务器进行用户认证。使用此库只需5行代码即可完成。

准备

您必须首先在Azure中拥有一个账户,然后在Azure Active Directory中注册一个应用程序。

  1. 前往 门户代码 进行注册或登录。
  2. 登录您的账户后,转到“Azure Active Directory”服务。
  3. 在服务页面,转到侧边栏中的应用程序注册部分。
  4. 创建一个新应用程序,给它起个名字,并复制客户端ID。您将需要它来使用此库。
  5. 配置您的应用程序,在API权限部分确保您有以下权限激活:“XboxLive.signin offline_access”。

用法

use mc_auth::AuthFlow;

fn main() {
    let mut auth = AuthFlow::new("9c1f1f43-58d5-4b7a-af0d-4e487f073441");
    let code_res = auth.request_code().unwrap();

    println!(
        "Open this link in your browser {} and enter the following code: {}\nWaiting authentication...",
        code_res.verification_uri, code_res.user_code
    );

    auth.wait_for_login().unwrap();
    auth.login_in_xbox_live().unwrap();

    let minecraft = auth.login_in_minecraft().unwrap();
    println!("Logged in:");
    println!("Bearer token: {}", minecraft.access_token);
    println!("UUID: {}", minecraft.username);
}

贡献

欢迎为库的开发做出贡献。

依赖

~4–19MB
~247K SLoC