Skip to content

Commit e04d9c0

Browse files
Merge pull request PCL-Community#86 from whitecat346/feature/account
FEATURE 添加微软登录部分,修改UserInfo等
2 parents 1770e14 + dd38a61 commit e04d9c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1982
-364
lines changed

PCL.Neo.Core/Models/Minecraft/Game/Log.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

PCL.Neo.Core/Models/Minecraft/MetadataFile.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,47 @@ namespace PCL.Neo.Core.Models.Minecraft;
66

77
public class MetadataFile
88
{
9+
private JsonObject _rawMetadata = new();
10+
911
#region Model Classes
1012

1113
public class Rule
1214
{
15+
[JsonConverter(typeof(JsonStringEnumConverter))]
16+
public enum ActionEnum
17+
{
18+
Unknown,
19+
[JsonStringEnumMemberName("allow")] Allow,
20+
[JsonStringEnumMemberName("disallow")] Disallow
21+
}
22+
23+
[JsonPropertyName("action")] public ActionEnum Action { get; set; } = ActionEnum.Allow;
24+
[JsonPropertyName("features")] public Dictionary<string, bool>? Features { get; set; } = null;
25+
[JsonPropertyName("os")] public OsModel? Os { get; set; } = null;
26+
1327
public class OsModel
1428
{
1529
[JsonConverter(typeof(JsonStringEnumConverter))]
16-
public enum NameEnum
30+
public enum ArchEnum
1731
{
1832
Unknown,
19-
[JsonStringEnumMemberName("windows")] Windows,
20-
[JsonStringEnumMemberName("linux")] Linux,
21-
[JsonStringEnumMemberName("osx")] Osx
33+
[JsonStringEnumMemberName("x64")] X64,
34+
[JsonStringEnumMemberName("x86")] X86
2235
}
2336

2437
[JsonConverter(typeof(JsonStringEnumConverter))]
25-
public enum ArchEnum
38+
public enum NameEnum
2639
{
2740
Unknown,
28-
[JsonStringEnumMemberName("x64")] X64,
29-
[JsonStringEnumMemberName("x86")] X86
41+
[JsonStringEnumMemberName("windows")] Windows,
42+
[JsonStringEnumMemberName("linux")] Linux,
43+
[JsonStringEnumMemberName("osx")] Osx
3044
}
3145

3246
[JsonPropertyName("arch")] public ArchEnum? Arch { get; set; } = null;
3347
[JsonPropertyName("name")] public NameEnum? Name { get; set; } = null;
3448
[JsonPropertyName("version")] public string? Version { get; set; } = null; // regex
3549
}
36-
37-
[JsonConverter(typeof(JsonStringEnumConverter))]
38-
public enum ActionEnum
39-
{
40-
Unknown,
41-
[JsonStringEnumMemberName("allow")] Allow,
42-
[JsonStringEnumMemberName("disallow")] Disallow
43-
}
44-
45-
[JsonPropertyName("action")] public ActionEnum Action { get; set; } = ActionEnum.Allow;
46-
[JsonPropertyName("features")] public Dictionary<string, bool>? Features { get; set; } = null;
47-
[JsonPropertyName("os")] public OsModel? Os { get; set; } = null;
4850
}
4951

5052
public class ConditionalArg
@@ -81,6 +83,12 @@ public class AssetIndexModel : RemoteFileModel
8183

8284
public class LibraryModel
8385
{
86+
[JsonPropertyName("downloads")] public DownloadsModel Downloads { get; set; } = new();
87+
[JsonPropertyName("extract")] public ExtractModel? Extract { get; set; } = null;
88+
[JsonPropertyName("name")] public string Name { get; set; } = string.Empty;
89+
[JsonPropertyName("natives")] public Dictionary<string, string>? Natives { get; set; } = null;
90+
[JsonPropertyName("rules")] public List<Rule>? Rules { get; set; } = null;
91+
8492
public class DownloadsModel
8593
{
8694
[JsonPropertyName("artifact")] public RemoteFileModel? Artifact { get; set; } = null;
@@ -93,12 +101,6 @@ public class ExtractModel
93101
{
94102
[JsonPropertyName("exclude")] public List<string> Exclude { get; set; } = [];
95103
}
96-
97-
[JsonPropertyName("downloads")] public DownloadsModel Downloads { get; set; } = new();
98-
[JsonPropertyName("extract")] public ExtractModel? Extract { get; set; } = null;
99-
[JsonPropertyName("name")] public string Name { get; set; } = string.Empty;
100-
[JsonPropertyName("natives")] public Dictionary<string, string>? Natives { get; set; } = null;
101-
[JsonPropertyName("rules")] public List<Rule>? Rules { get; set; } = null;
102104
}
103105

104106
public class LoggingModel
@@ -110,8 +112,6 @@ public class LoggingModel
110112

111113
#endregion
112114

113-
private JsonObject _rawMetadata = new();
114-
115115
#region Metadata Fields
116116

117117
public ArgumentsModel Arguments { get; set; } = new();

PCL.Neo.Core/PCL.Neo.Core.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
11-
<PackageReference Include="LZMA-SDK" Version="22.1.1" />
10+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
11+
<PackageReference Include="SevenZip" Version="19.0.0" />
12+
<PackageReference Include="System.Reactive" Version="6.0.1" />
13+
<PackageReference Include="System.Reactive.Linq" Version="6.0.1" />
1214
</ItemGroup>
1315

1416
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using PCL.Neo.Core.Service.Accounts.MicrosoftAuth;
2+
3+
namespace PCL.Neo.Core.Service.Accounts.Exceptions
4+
{
5+
public class DeviceFlowError(
6+
DeviceFlowState state,
7+
Exception? exc) : DeviceFlowState
8+
{
9+
public DeviceFlowState State { get; init; } = state;
10+
public Exception? Exc { get; init; } = exc;
11+
}
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Net;
2+
3+
namespace PCL.Neo.Core.Service.Accounts.Exceptions;
4+
5+
public record HttpError(
6+
HttpStatusCode? StatusCode,
7+
string Message,
8+
string? Content = null,
9+
Exception? Exception = null);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace PCL.Neo.Core.Service.Accounts.IYggdrasilAuth
2+
{
3+
public interface IYggdrasilAuthService
4+
{
5+
}
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace PCL.Neo.Core.Service.Accounts.MicrosoftAuth;
2+
3+
public static class DeviceCodeMode
4+
{
5+
public record DeviceCodeInfo(string DeviceCode, string UserCode, string VerificationUri, int Interval);
6+
7+
public record DeviceCodeAccessToken(string AccessToken, string RefreshToken, DateTimeOffset ExpiresIn);
8+
9+
public record McAccountInfo(
10+
List<Storage.Skin> Skins,
11+
List<Storage.Cape> Capes,
12+
string UserName,
13+
string Uuid);
14+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using PCL.Neo.Core.Service.Accounts.Storage;
2+
3+
namespace PCL.Neo.Core.Service.Accounts.MicrosoftAuth
4+
{
5+
public class DeviceFlowState;
6+
7+
public class DeviceFlowAwaitUser(string userCode, string verificationUri) : DeviceFlowState
8+
{
9+
public string UserCode { get; } = userCode;
10+
public string VerificationUri { get; } = verificationUri;
11+
}
12+
13+
public class DeviceFlowPolling : DeviceFlowState;
14+
15+
public class DeviceFlowDeclined : DeviceFlowState;
16+
17+
public class DeviceFlowExpired : DeviceFlowState;
18+
19+
public class DeviceFlowBadVerificationCode : DeviceFlowState;
20+
21+
public class DeviceFlowGetAccountInfo : DeviceFlowState;
22+
23+
public class DeviceFlowSucceeded(MsaAccount account) : DeviceFlowState
24+
25+
{
26+
public MsaAccount Account { get; } = account;
27+
}
28+
29+
public class DeviceFlowUnkonw : DeviceFlowState;
30+
31+
public class DeviceFlowInternetError : DeviceFlowState;
32+
33+
public class DeviceFlowJsonError : DeviceFlowState;
34+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using PCL.Neo.Core.Service.Accounts.Exceptions;
2+
using PCL.Neo.Core.Service.Accounts.OAuthService;
3+
using PCL.Neo.Core.Utils;
4+
5+
namespace PCL.Neo.Core.Service.Accounts.MicrosoftAuth;
6+
7+
public interface IMicrosoftAuthService
8+
{
9+
/// <summary>
10+
/// 开始设备码登录流程
11+
/// </summary>
12+
/// <returns>设备码登录流状态</returns>
13+
IObservable<DeviceFlowState> StartDeviceCodeFlow();
14+
15+
/// <summary>
16+
/// 获取设备码
17+
/// </summary>
18+
/// <returns>获取到的设备码信息,会在失败的时候返回异常</returns>
19+
Task<Result<DeviceCodeMode.DeviceCodeInfo, HttpError>> RequestDeviceCodeAsync();
20+
21+
/// <summary>
22+
/// 开始轮询服务器
23+
/// </summary>
24+
/// <param name="deviceCode">设备码</param>
25+
/// <param name="interval">轮询间隔</param>
26+
/// <returns>轮询结果</returns>
27+
Task<Result<DeviceCodeMode.DeviceCodeAccessToken, DeviceFlowError>> PollForTokenAsync(string deviceCode,
28+
int interval);
29+
30+
/// <summary>
31+
/// 获取玩家全部信息
32+
/// </summary>
33+
/// <param name="accessToken">通行Token</param>
34+
/// <returns>玩家信息</returns>
35+
Task<Result<string, MinecraftInfo.NotHaveGameException>> GetUserMinecraftAccessTokenAsync(string accessToken);
36+
37+
/// <summary>
38+
/// 获取玩家的账户信息
39+
/// </summary>
40+
/// <param name="accessToken">需要的Token</param>
41+
/// <returns>账户信息</returns>
42+
Task<Result<DeviceCodeMode.McAccountInfo, Exception>> GetUserAccountInfo(string accessToken);
43+
44+
/// <summary>
45+
/// 刷新玩家的OAuth2 Token
46+
/// </summary>
47+
/// <param name="refreshToken">OAuth2的刷新Token</param>
48+
/// <returns>新的Token</returns>
49+
Task<Result<Storage.OAuthTokenData, Exception>> RefreshTokenAsync(string refreshToken);
50+
}

0 commit comments

Comments
 (0)