Skip to content

Commit

Permalink
2.1.7
Browse files Browse the repository at this point in the history
* 加入设备流验证(未翻译)
  • Loading branch information
natsurainko committed Apr 8, 2023
1 parent cc0ccbd commit 39d8939
Show file tree
Hide file tree
Showing 19 changed files with 1,004 additions and 313 deletions.
2 changes: 1 addition & 1 deletion Natsurainko.FluentLauncher (Package)/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Identity
Name="26553XcubeStudio.Natsurianko.FluentLauncher"
Publisher="CN=053EFB0E-6705-4A11-94B9-980C4C9E0047"
Version="2.1.6.0" />
Version="2.1.7.0" />

<Properties>
<DisplayName>Natsurianko.FluentLauncher</DisplayName>
Expand Down
72 changes: 0 additions & 72 deletions Natsurainko.FluentLauncher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "Natsurainko.FluentLauncher
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Natsurainko.FluentLauncher", "Natsurainko.FluentLauncher\Natsurainko.FluentLauncher.csproj", "{25A06654-F92D-43C8-BA6C-4B84BED2A505}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Natsurainko.FluentCore", "..\Natsurainko.FluentCore\Natsurainko.FluentCore\Natsurainko.FluentCore.csproj", "{A16112E3-DC85-445A-9E59-A64203F449FE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Natsurainko.FluentCore.Extension.Windows", "..\Natsurainko.FluentCore\Natsurainko.FluentCore.Extension.Windows\Natsurainko.FluentCore.Extension.Windows.csproj", "{855D9C39-2E50-4C21-99F3-D2DB153B427A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Natsurainko.Toolkits", "..\Natsurainko.Toolkits\Natsurainko.Toolkits\Natsurainko.Toolkits.csproj", "{2958D370-BA2A-448D-A318-E3092B213F81}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Natsurainko.FluentLauncher (SelfContained)", "Natsurainko.FluentLauncher\Natsurainko.FluentLauncher (SelfContained).csproj", "{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -67,70 +59,6 @@ Global
{25A06654-F92D-43C8-BA6C-4B84BED2A505}.Release|x64.Build.0 = Release|x64
{25A06654-F92D-43C8-BA6C-4B84BED2A505}.Release|x86.ActiveCfg = Release|x86
{25A06654-F92D-43C8-BA6C-4B84BED2A505}.Release|x86.Build.0 = Release|x86
{A16112E3-DC85-445A-9E59-A64203F449FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Debug|ARM64.Build.0 = Debug|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Debug|x64.ActiveCfg = Debug|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Debug|x64.Build.0 = Debug|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Debug|x86.ActiveCfg = Debug|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Debug|x86.Build.0 = Debug|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Release|Any CPU.Build.0 = Release|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Release|ARM64.ActiveCfg = Release|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Release|ARM64.Build.0 = Release|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Release|x64.ActiveCfg = Release|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Release|x64.Build.0 = Release|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Release|x86.ActiveCfg = Release|Any CPU
{A16112E3-DC85-445A-9E59-A64203F449FE}.Release|x86.Build.0 = Release|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Debug|ARM64.Build.0 = Debug|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Debug|x64.ActiveCfg = Debug|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Debug|x64.Build.0 = Debug|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Debug|x86.ActiveCfg = Debug|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Debug|x86.Build.0 = Debug|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Release|Any CPU.Build.0 = Release|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Release|ARM64.ActiveCfg = Release|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Release|ARM64.Build.0 = Release|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Release|x64.ActiveCfg = Release|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Release|x64.Build.0 = Release|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Release|x86.ActiveCfg = Release|Any CPU
{855D9C39-2E50-4C21-99F3-D2DB153B427A}.Release|x86.Build.0 = Release|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Debug|ARM64.Build.0 = Debug|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Debug|x64.ActiveCfg = Debug|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Debug|x64.Build.0 = Debug|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Debug|x86.ActiveCfg = Debug|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Debug|x86.Build.0 = Debug|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Release|Any CPU.Build.0 = Release|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Release|ARM64.ActiveCfg = Release|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Release|ARM64.Build.0 = Release|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Release|x64.ActiveCfg = Release|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Release|x64.Build.0 = Release|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Release|x86.ActiveCfg = Release|Any CPU
{2958D370-BA2A-448D-A318-E3092B213F81}.Release|x86.Build.0 = Release|Any CPU
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Debug|Any CPU.ActiveCfg = Debug|x64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Debug|Any CPU.Build.0 = Debug|x64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Debug|ARM64.ActiveCfg = Debug|ARM64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Debug|ARM64.Build.0 = Debug|ARM64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Debug|x64.ActiveCfg = Debug|x64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Debug|x64.Build.0 = Debug|x64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Debug|x86.ActiveCfg = Debug|x86
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Debug|x86.Build.0 = Debug|x86
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Release|Any CPU.ActiveCfg = Release|x64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Release|Any CPU.Build.0 = Release|x64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Release|ARM64.ActiveCfg = Release|ARM64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Release|ARM64.Build.0 = Release|ARM64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Release|x64.ActiveCfg = Release|x64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Release|x64.Build.0 = Release|x64
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Release|x86.ActiveCfg = Release|x86
{7C1AD2DA-6E71-4142-99B6-B15A80D3A1C5}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 5 additions & 0 deletions Natsurainko.FluentLauncher/Components/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public static Configuration Default()
Accounts = new(),
EnableDemoUser = false,
AutoRefresh = true,
UseDeviceFlowAuth = false,
CurrentDownloadSource = "Mcbbs",
EnableFragmentDownload = true,
MaxDownloadThreads = 128,
Expand Down Expand Up @@ -183,6 +184,10 @@ public partial class Configuration
[ObservableProperty]
[JsonIgnore]
private bool autoRefresh;

[ObservableProperty]
[JsonIgnore]
private bool useDeviceFlowAuth;
}

public partial class Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Natsurainko.FluentCore.Model.Auth;
using Natsurainko.Toolkits.Network;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Natsurainko.FluentCore.Module.Authenticator;
using System.Threading;

namespace Natsurainko.FluentLauncher.Components.FluentCore;

internal static class MicrosoftAuthenticatorExtension
{
public static Task<DeviceFlowAuthResult> DeviceFlowAuthAsync
(string client_id, Action<DeviceAuthorizationResponse> ReceiveUserCodeAction, out CancellationTokenSource cancellationTokenSource)
{
cancellationTokenSource = new CancellationTokenSource();
var token = cancellationTokenSource.Token;

return Task.Run(async () =>
{
try
{
var deviceAuthPost =
$"client_id={client_id}" +
"&scope=XboxLive.signin%20offline_access";
using var deviceAuthPostRes = await HttpWrapper.HttpPostAsync
($"https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode", deviceAuthPost, "application/x-www-form-urlencoded");
var deviceAuthResponse = JsonConvert.DeserializeObject<DeviceAuthorizationResponse>(await deviceAuthPostRes.Content.ReadAsStringAsync());
ReceiveUserCodeAction(deviceAuthResponse);
var stopwatch = Stopwatch.StartNew();
while (stopwatch.Elapsed < TimeSpan.FromSeconds(deviceAuthResponse.ExpiresIn))
{
if (token.IsCancellationRequested)
break;
await Task.Delay(deviceAuthResponse.Interval * 1000);
var pollingPost =
"grant_type=urn:ietf:params:oauth:grant-type:device_code" +
$"&client_id={client_id}" +
$"&device_code={deviceAuthResponse.DeviceCode}";
using var pollingPostRes = await HttpWrapper.HttpPostAsync
($"https://login.microsoftonline.com/consumers/oauth2/v2.0/token", pollingPost, "application/x-www-form-urlencoded");
var pollingPostJson = JObject.Parse(await pollingPostRes.Content.ReadAsStringAsync());
if (pollingPostRes.IsSuccessStatusCode)
return new()
{
Success = true,
OAuth20TokenResponse = pollingPostJson.ToObject<OAuth20TokenResponseModel>()
};
else
{
var error = (string)pollingPostJson["error"];
if (error.Equals("authorization_declined") ||
error.Equals("bad_verification_code") ||
error.Equals("expired_token"))
break;
}
}
stopwatch.Stop();
}
catch (Exception ex)
{
if (ex is OperationCanceledException)
{
}
}
return new DeviceFlowAuthResult()
{
Success = false
};
}, token);
}
}
Loading

0 comments on commit 39d8939

Please sign in to comment.