Skip to content

Commit

Permalink
添加统一通行证验证器
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSpring114 committed Dec 29, 2023
1 parent 67a2e65 commit 28710a2
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 4 deletions.
13 changes: 13 additions & 0 deletions .idea/.idea.MinecraftLaunch/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.MinecraftLaunch/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.MinecraftLaunch/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion MinecraftLaunch/Classes/Enums/AccountType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public enum AccountType {
/// <summary>
/// Yggdrasil 第三方账户
/// </summary>
Yggdrasil
Yggdrasil,

/// <summary>
/// UnifiedPass 统一通行证
/// </summary>
UnifiedPass
}
}
8 changes: 8 additions & 0 deletions MinecraftLaunch/Classes/Models/Auth/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ public record YggdrasilAccount : Account {
public record OfflineAccount : Account {
public override AccountType Type => AccountType.Offline;
}

public record UnifiedPassAccount : Account {
public override AccountType Type => AccountType.UnifiedPass;

public string ServerId { get; set; }

public string ClientToken { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Flurl.Http;
using MinecraftLaunch.Classes.Interfaces;
using MinecraftLaunch.Classes.Models.Auth;
using MinecraftLaunch.Extensions;

namespace MinecraftLaunch.Components.Authenticator;

public class UnifiedPassAuthenticator(string serverId, string userName, string passWord) : IAuthenticator<UnifiedPassAccount> {
private string _serverId = serverId;
private string _userName = userName;
private string _passWord = passWord;
private string _baseUrl = "https://auth.mc-user.com:233/";

public void RefreshInformation(string serverId, string userName, string passWord) {
_serverId = serverId;
_passWord = passWord;
_userName = userName;
}

public UnifiedPassAccount Authenticate() {
return AuthenticateAsync()
.GetAwaiter()
.GetResult();
}

public async ValueTask<UnifiedPassAccount> AuthenticateAsync() {
string authUrl = $"{_baseUrl}{_serverId}/authserver/authenticate";
var content = new {
agent = new {
name = "MinecraftLaunch",
version = 1.00
},
username = _userName,
password = _passWord,
clientToken = null as string,
requestUser = true,
};

var node = (await (await authUrl.PostJsonAsync(content))
.GetStringAsync())
.AsNode();

var user = node.GetEnumerable("availableProfiles")
.FirstOrDefault();

return new UnifiedPassAccount {
ServerId = _serverId,
Name = user.GetString("name"),
Uuid = Guid.Parse(user.GetString("id")),
AccessToken = node.GetString("accessToken"),
ClientToken = node.GetString("clientToken"),
};
}
}
7 changes: 7 additions & 0 deletions MinecraftLaunch/Components/Converter/AccountJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public override Account Read(ref Utf8JsonReader reader, Type typeToConvert, Json
Uuid = root.GetProperty("Uuid").GetGuid(),
YggdrasilServerUrl = root.GetProperty("YggdrasilServerUrl").GetString()
},
AccountType.UnifiedPass => new UnifiedPassAccount {
AccessToken = root.GetProperty("AccessToken").GetString(),
ClientToken = root.GetProperty("ClientToken").GetString(),
Name = root.GetProperty("Name").GetString(),
Uuid = root.GetProperty("Uuid").GetGuid(),
ServerId = root.GetProperty("ServerId").GetString()
},
_ => default!
};
}
Expand Down
2 changes: 1 addition & 1 deletion MinecraftLaunch/MinecraftLaunch.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>3.0.0-preview5</Version>
<Version>3.0.0-preview6</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions MinecraftLaunch/MirrorDownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace MinecraftLaunch {
/// <summary>
/// 默认的下载镜像源管理类
/// </summary>
public class MirrorDownloadManager {
public static class MirrorDownloadManager {
public static bool IsUseMirrorDownloadSource { get; set; } = true;

public static readonly MirrorDownloadSource Bmcl = new() {
Expand Down Expand Up @@ -35,7 +35,7 @@ public class MirrorDownloadManager {
{ "https://piston-meta.mojang.com", "https://download.mcbbs.net" },
{ "https://launchermeta.mojang.com", "https://download.mcbbs.net" },
},
LibrariesUrls = new Dictionary<string, string>() {
LibrariesUrls = new Dictionary<string, string> {
{ "https://launcher.mojang.com" , "https://download.mcbbs.net" },
{ "https://libraries.minecraft.net", "https://download.mcbbs.net/maven" },
{ "https://piston-meta.mojang.com", "https://download.mcbbs.net" },
Expand Down

0 comments on commit 28710a2

Please sign in to comment.