private void AuthorizeOnUIThread(string authorizeUri)
{
// Create a WebBrowser control to display the authorize page
var webBrowser = new WebBrowser();
// Handle the navigation event for the browser to check for a response to the redirect URL
webBrowser.Navigating += WebBrowserOnNavigating;
// Display the web browser in a new window
_window = new Window
{
Content = webBrowser,
Height = 430,
Width = 395,
WindowStartupLocation = WindowStartupLocation.CenterOwner
};
// Set the app's window as the owner of the browser window (if main window closes, so will the browser)
if (Application.Current != null && Application.Current.MainWindow != null)
{
_window.Owner = Application.Current.MainWindow;
}
// Handle the window closed event then navigate to the authorize url
_window.Closed += OnWindowClosed;
webBrowser.Navigate(authorizeUri);
// Display the Window
_window.ShowDialog();
}