arffornia/minecraft-oauth

由 aberdeener 分支而来,已更新为支持 php8 和 Laravel 11,提供从 Microsoft Live OAuth 会话中获取 Minecraft 配置文件(UUID、用户名、皮肤、斗篷)的简单层

dev-main 2024-05-17 09:40 UTC

This package is not auto-updated.

Last update: 2024-09-22 11:29:36 UTC


README

由 tadhgboyle 分支而来。 由 TheGostsniperfr 更新,以支持 PHP 8 和 Laravel 11。

提供从 Microsoft Live OAuth 会话中获取 Minecraft 配置文件(UUID、用户名、皮肤、斗篷)的简单层。

用法

您有多种方法可以创建请求,以下是一个有效的例子。

此外,您需要将 Azure 应用程序注册到 Mojang,以便您的应用程序获得使用 Mojang API 的授权,否则您将从 Mojang API 获得一个 403 错误代码。

为此,您需要填写此表格(几周内回复)

创建 MS 请求

$clientId = 'AZURE_OAUTH_CLIENT_ID';
$redirectUri = urlencode('REDIRECT_URI');

$authUrl = "https://login.live.com/oauth20_authorize.srf?client_id=$clientId&response_type=code&redirect_uri=$redirectUri&scope=XboxLive.signin%20offline_access&state=NOT_NEEDED";

注意:据说可以使用 service::user.auth.xboxlive.com::MBI_SSL 作为作用域以避免确认 Microsoft 权限。

遗憾的是,我还没有得到任何确定的结论,所以如果您有关于这个主题的任何信息,我将非常乐意得到它。

接收 MS 响应

require 'vendor/autoload.php';

$client_id = '<Azure OAuth Client ID>';
$client_secret = '<Azure OAuth Client Secret>';
$redirect_uri = '<URL to this file>';

try {
    $profile = (new \Arffornia\MinecraftOauth\MinecraftOauth)->fetchProfile(
        $client_id,
        $client_secret,
        $_GET['code'],
        $redirect_uri,
    );
} catch (\Arffornia\MinecraftOauth\Exceptions\MinecraftOauthException $e) {
    echo $e->getMessage();
}

echo 'Minecraft UUID: ' . $profile->uuid();
echo 'Minecraft Username: ' . $profile->username();
echo 'Minecraft Skin URL: ' . $profile->skins()[0]->url();
echo 'Minecraft Cape URL: ' . $profile->capes()[0]->url();

信息

如果您想检查所有 MS Auth 方案。