/// <summary>
        /// The core logic for retrieving the authorization code. It MUST be called from the UI thread.
        /// </summary>
        /// <param name="url">The authorization code request URL.</param>
        /// <param name="taskCancellationToken">Cancellation token.</param>
        /// <returns>The authorization code response.</returns>
        private async Task<AuthorizationCodeResponseUrl> ReceivedCodeCoreAsync(AuthorizationCodeRequestUrl url,
            CancellationToken taskCancellationToken)
        {
            // Get the current window.
            PhoneApplicationFrame rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
            PhoneApplicationPage rootPage = rootFrame.Content as PhoneApplicationPage;
            UIElement currentLayout = rootPage.Content;

            // Create the web authentication user control and add it to the current window.
            var webAuthControl = new WebAuthenticationBrokerUserControl();
            var oauthLayout = new Grid
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch
            };

            rootPage.Content = oauthLayout;
            oauthLayout.Children.Add(webAuthControl);

            try
            {
                return await webAuthControl.Launch(url.Build());
            }
            finally
            {
                // Change back to the old layout.
                webAuthControl.Visibility = Visibility.Collapsed;
                oauthLayout.Children.Remove(webAuthControl);
                rootPage.Content = currentLayout;
            }
        }
예제 #2
0
        /// <summary>
        /// The core logic for retrieving the authorization code. It MUST be called from the UI thread.
        /// </summary>
        /// <param name="url">The authorization code request URL.</param>
        /// <param name="taskCancellationToken">Cancellation token.</param>
        /// <returns>The authorization code response.</returns>
        private async Task <AuthorizationCodeResponseUrl> ReceivedCodeCoreAsync(AuthorizationCodeRequestUrl url,
                                                                                CancellationToken taskCancellationToken)
        {
            // Get the current window.
            PhoneApplicationFrame rootFrame     = Application.Current.RootVisual as PhoneApplicationFrame;
            PhoneApplicationPage  rootPage      = rootFrame.Content as PhoneApplicationPage;
            UIElement             currentLayout = rootPage.Content;

            // Create the web authentication user control and add it to the current window.
            var webAuthControl = new WebAuthenticationBrokerUserControl();
            var oauthLayout    = new Grid
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            rootPage.Content = oauthLayout;
            oauthLayout.Children.Add(webAuthControl);

            try
            {
                return(await webAuthControl.Launch(url.Build()));
            }
            finally
            {
                // Change back to the old layout.
                webAuthControl.Visibility = Visibility.Collapsed;
                oauthLayout.Children.Remove(webAuthControl);
                rootPage.Content = currentLayout;
            }
        }