private void OnLoginButtonPressed() { // Log.Info("Login initiated..."); LoginButton.Enabled = false; var profileManager = GetService <ProfileManager>(); XboxAuthService.OpenBrowser(ConnectResponse.verification_uri); if (Clipboard.IsClipboardAvailable()) { try { Clipboard.SetText(ConnectResponse.user_code); } catch (Exception ex) { Log.Warn(ex, $"Could not set keyboard contents!"); } } // Log.Info($"Browser opened..."); AuthenticationService.DoDeviceCodeLogin(GetService <ResourceManager>().DeviceID, ConnectResponse.device_code, CancellationToken.Token).ContinueWith( (task) => { try { var result = task.Result; if (result.success) { var r = AuthenticationService.DecodedChain.Chain.FirstOrDefault(x => x.ExtraData != null && !string.IsNullOrWhiteSpace(x.ExtraData.Xuid)); var profile = new PlayerProfile(r.ExtraData.Xuid, r.ExtraData.DisplayName, r.ExtraData.DisplayName, new Skin() { Slim = true, Texture = null }, result.token.AccessToken, JsonConvert.SerializeObject(result.token), "xbox"); profileManager.CreateOrUpdateProfile("xbox", profile, true); Ready?.Invoke(profile); //Log.Info($"Continuewith Success!"); } else { //Log.Info($"Continuewith fail!"); } } catch (Exception ex) { Log.Warn($"Authentication issue: {ex.ToString()}"); } }); }
private static async void Test() { XboxAuthService authService = new XboxAuthService(); var authConnect = await authService.StartDeviceAuthConnect(); Console.WriteLine($"Code: {authConnect.user_code}"); XboxAuthService.OpenBrowser(authConnect.verification_uri); await authService.DoDeviceCodeLogin(Guid.NewGuid().ToString(), authConnect.device_code, CancellationToken.None); }