使用Microsoft账户登入Minecraft的流程 和 代码实现(c#)

感谢

了解MS登入MC

你可以直接在wiki.vg看,就是不会有本文这么傻瓜
https://wiki.vg/Microsoft_Authentication_Scheme

大致流程

一步到胃

1.浏览器用户登入获取Code

这一步是首次登入必须,否则你无法获取第一个refresh_token

2.获取OAuth Access Token

https://login.live.com/oauth20_token.srf

3.获取XBL Token

https://user.auth.xboxlive.com/user/authenticate

4.获取XSTS Token以及Userhash

https://xsts.auth.xboxlive.com/xsts/authorize

5.获取MC Access Token

https://api.minecraftservices.com/authentication/login_with_xbox

获取用于启动的Access Token

6.获取MC Profile

获取用于启动的UUID

二次登入

本地保存的参数 refresh_token

来自何方

由OAuth Access Token步骤中获取

如何使用
POST https://login.live.com/oauth20_token.srf

Request

Content-Type: application/x-www-form-urlencoded
client_id 00000000402b5328
refresh_token <你的refresh_token>
grant_type refresh_token
redirect_uri https://login.live.com/oauth20_desktop.srf
scope service::user.auth.xboxlive.com::MBI_SSL

Response

{
	"token_type": "bearer",
	"expires_in": 86400,
	"scope": "service::user.auth.xboxlive.com::MBI_SSL",
	"access_token": "<xbl_token>",
	"refresh_token": "<新的refresh_token>",
	"user_id": "<一个不重要的user_id>",
	"foci": "1"
}

这个新的refresh_token需要保存起来,每次我们实现自动登入需要提交保存的refresh_token然后得到新的xbl_token 和 refresh_token

首次登入

需要步骤1

使用c#实现登入

已经做了个类库了

https://github.com/heerheer/HeerDev.MLRExtension

Nuget包(
(是.net5的,所以低版本要用可以自己copy代码(

使用c#实现自动登入并启动游戏

你还是可以使用启动模块,不过记得自己存refresh_token
如上

  • 13
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值