Example #1
0
        private async void LoginWebView_OnNavigationStarting(WebView sender, WebViewNavigationStartingEventArgs eventArgs)
        {
            if (eventArgs.Uri.Host == "localhost")
            {
                // Cancel the navigation, (as localhost does not exist).
                eventArgs.Cancel = true;

                // Parse the URL for work
                // ReSharper disable once CollectionNeverUpdated.Local
                var parser = new QueryParameterCollection(eventArgs.Uri);

                // First we just check that the state equals (to make sure the url was not hijacked)
                var state = parser.FirstOrDefault(x => x.Key == "state").Value;

                // The state does not match
                if (string.IsNullOrEmpty(state) || state.TrimEnd('#') != _stateVerification)
                {
                    // Display the error to the user
                    await NavigationService.Current.CallMessageDialogAsync(
                        "State Verfication Failed. This could be caused by another process intercepting the SoundByte login procedure. Signin has been canceled to protect your privacy.",
                        "Sign in Error");

                    App.Telemetry.TrackEvent("State Verfication Failed");

                    // Close
                    Hide();
                    return;
                }

                // We have an error
                if (parser.FirstOrDefault(x => x.Key == "error").Value != null)
                {
                    var type   = parser.FirstOrDefault(x => x.Key == "error").Value;
                    var reason = parser.FirstOrDefault(x => x.Key == "error_description").Value;

                    // The user denied the request
                    if (type == "access_denied")
                    {
                        Hide();
                        return;
                    }

                    // Display the error to the user
                    await NavigationService.Current.CallMessageDialogAsync(reason, "Sign in Error");

                    Hide();
                    return;
                }

                if (parser.FirstOrDefault(x => x.Key == "code").Value == null)
                {
                    await NavigationService.Current.CallMessageDialogAsync("No Code", "Sign in Error");

                    Hide();
                    return;
                }

                var code = parser.FirstOrDefault(x => x.Key == "code").Value;

                try
                {
                    var loginToken = await AuthorizationHelpers.GetAuthTokenAsync(_loginService, code);

                    if (!_isRemoteConnect)
                    {
                        // Connect the service
                        SoundByteService.Current.ConnectService(_loginService, loginToken);

                        // Close
                        Hide();
                    }
                    else
                    {
                        LoadingSection.Visibility = Visibility.Visible;

                        loginToken.LoginCode   = _loginCode;
                        loginToken.ServiceType = _loginService;

                        var serviceResponse = await BackendService.Instance.LoginSendInfoAsync(loginToken);

                        if (string.IsNullOrEmpty(serviceResponse))
                        {
                            // Close
                            Hide();
                        }
                        else
                        {
                            await NavigationService.Current.CallMessageDialogAsync("Could not connect to your Xbox One. Please check that the codes match and try again.\n\n" + serviceResponse,
                                                                                   "Xbox Connect Error");

                            // Close
                            Hide();
                        }
                    }
                }
                catch (SoundByteException ex)
                {
                    // Display the error to the user
                    await NavigationService.Current.CallMessageDialogAsync(ex.ErrorDescription, ex.ErrorTitle);

                    // Close
                    Hide();
                }
            }
        }
Example #2
0
        private async void LoginWebView_OnNavigationStarting(WebView sender, WebViewNavigationStartingEventArgs eventArgs)
        {
            if (eventArgs.Uri.Host == "localhost")
            {
                // Cancel the navigation, (as localhost does not exist).
                eventArgs.Cancel = true;

                // Parse the URL for work
                // ReSharper disable once CollectionNeverUpdated.Local
                var parser = new QueryParameterCollection(eventArgs.Uri);

                // First we just check that the state equals (to make sure the url was not hijacked)
                var state = parser.FirstOrDefault(x => x.Key == "state").Value;

                // The state does not match
                if (string.IsNullOrEmpty(state) || state.TrimEnd('#') != _stateVerification)
                {
                    // Display the error to the user
                    await NavigationService.Current.CallMessageDialogAsync(
                        "State Verification Failed. This could be caused by another process intercepting the SoundByte login procedure. Signin has been canceled to protect your privacy.",
                        "Sign in Error");

                    SimpleIoc.Default.GetInstance <ITelemetryService>().TrackEvent("State Verification Failed");

                    // Close
                    Frame.GoBack();
                    return;
                }

                // We have an error
                if (parser.FirstOrDefault(x => x.Key == "error").Value != null)
                {
                    var type   = parser.FirstOrDefault(x => x.Key == "error").Value;
                    var reason = parser.FirstOrDefault(x => x.Key == "error_description").Value;

                    // The user denied the request
                    if (type == "access_denied")
                    {
                        Frame.GoBack();

                        return;
                    }

                    // Display the error to the user
                    await NavigationService.Current.CallMessageDialogAsync(reason, "Sign in Error");

                    Frame.GoBack();
                    return;
                }

                if (parser.FirstOrDefault(x => x.Key == "code").Value == null)
                {
                    await NavigationService.Current.CallMessageDialogAsync("No Code", "Sign in Error");

                    Frame.GoBack();
                    return;
                }

                // Get the code
                var code = parser.FirstOrDefault(x => x.Key == "code").Value;

                try
                {
                    // Get the login token
                    var loginToken = await AuthorizationHelpers.GetAuthTokenAsync(_loginService, code);

                    // Connect the service
                    SoundByteService.Current.ConnectService(_loginService, loginToken);

                    // Close
                    Frame.GoBack();
                }
                catch (SoundByteException ex)
                {
                    // Display the error to the user
                    await NavigationService.Current.CallMessageDialogAsync(ex.ErrorDescription, ex.ErrorTitle);

                    // Close
                    Frame.GoBack();
                }
            }
        }