arffornia/minecraft-oauth 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arffornia/minecraft-oauth

Composer 安装命令:

composer require arffornia/minecraft-oauth

包简介

Fork from aberdeener, updated to php8 for laravel11 compatibility, provides easy layer to get a Minecraft profile from a Microsoft Live OAuth session

README 文档

README

Forked from tadhgboyle. Updated by TheGostsniperfr for PHP 8 and Laravel 11 support.

Provides easy layer to get a Minecraft profile (UUID, username, skins, capes) from a Microsoft Live OAuth session.

Usage

You have different solutions for creating the request, here's one that works.

In addition, you'll need to register your Azure app with Mojang for your app to be authorized to use the Mojang api, otherwise you'll get a 403 error code by Mojang API.

To do this, you need to fill in this form (response within a few weeks)

Create MS request

$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";

Nb: Apparently, it's possible to use service::user.auth.xboxlive.com::MBI_SSL as a scope to avoid confirming microsoft permissions.

Unfortunately, I haven't had any conclusive results on this, so if you have any information on this subject, I'd be delighted to have it.

Receive MS responce

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();

Info

If you want to check all the MS Auth Scheme.

统计信息

  • 总下载量: 79
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-20