コード例 #1
0
ファイル: XBLMSAService.cs プロジェクト: wqd1019dqw/Alex
        public async Task <(bool success, BedrockTokenPair token)> DoDeviceCodeLogin(string deviceCode, CancellationToken cancellationToken)
        {
            try
            {
                string r = "authorization_pending";
                MsaDeviceAuthPollState token = null;
                while (r == "authorization_pending" && !cancellationToken.IsCancellationRequested)
                {
                    var poll = await DevicePollState(deviceCode);

                    r     = poll.Error;
                    token = poll;
                }

                var userToken = await DoUserAuth(token.AccessToken);

                var xsts = await DoXsts(null, null, userToken.Token);

                return(await RequestMinecraftChain(xsts, MinecraftKeyPair), new BedrockTokenPair()
                {
                    AccessToken = token.AccessToken,
                    ExpiryTime = DateTime.UtcNow.AddSeconds(token.ExpiresIn),
                    RefreshToken = token.RefreshToken
                });
            }
            catch (OperationCanceledException c)
            {
                return(false, null);
            }
        }
コード例 #2
0
ファイル: XBLMSAService.cs プロジェクト: wqd1019dqw/Alex
        public async Task DoXboxAuth()
        {
            bool linux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);

            if (!linux)
            {
                var result = await StartDeviceAuthConnect();

                OpenBrowser(result.verification_uri);

                string r = "authorization_pending";
                MsaDeviceAuthPollState token = null;
                while (r == "authorization_pending")
                {
                    var poll = await DevicePollState(result.device_code);

                    r     = poll.Error;
                    token = poll;
                }

                var userToken = await DoUserAuth(token.AccessToken);

                var xsts = await DoXsts(null, null, userToken.Token);

                await RequestMinecraftChain(xsts, MinecraftKeyPair);
            }
            else
            {
                /*	await Task.Run(() =>
                 *      {
                 *              EtoApplication.AsyncInvoke(async () =>
                 *              {
                 *                      XboxAuthForm authForm = new XboxAuthForm(this, false);
                 *                      //authForm.MainWebView.Url = new Uri(result.verification_uri);
                 *
                 *                      authForm.Closed += async (sender, args) =>
                 *                      {
                 *                              Console.WriteLine();
                 *
                 *                              //var userToken = await DoUserAuth(token.access_token);
                 *                              var userToken = await DoUserAuth(authForm.AccessToken);
                 *
                 *                              //var deviceToken = await DoDeviceAuth(authForm.AccessToken);
                 *
                 *                              //var titleToken = await DoTitleAuth(deviceToken, authForm.AccessToken);
                 *
                 *                              var xsts = await DoXsts(null, null, userToken.Token);
                 *
                 *                              await RequestMinecraftChain(xsts, MinecraftKeyPair);
                 *                      };
                 *
                 *                      authForm.Show();
                 *              });
                 *      });*/
            }
        }