public bool LogIn(Windows.UI.Xaml.Controls.WebView webView, Windows.UI.Xaml.Controls.Frame parentFrame)
        {
            var uri = driveLink.GetStartUri();

            webView.Navigate(uri);

            webView.NavigationCompleted += (s, e) =>
            {
                if (driveLink.CheckRedirectUrl(e.Uri.AbsoluteUri))
                {
                    driveLink.ContinueGetTokens(e.Uri);
                    var dialog = new Windows.UI.Popups.MessageDialog("You are authenticated!", "Success!");
                    dialog.ShowAsync();
                    parentFrame.GoBack();
                }
            };

            webView.NavigationFailed += (s, e) =>
            {
                driveLink.ContinueGetTokens(null);
                var dialog = new Windows.UI.Popups.MessageDialog("There problems authenticating you. Please try again :(", "Fail!");
                dialog.ShowAsync();
                parentFrame.GoBack();
            };
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Perform the print
        /// </summary>
        /// <returns>Task that the caller is expected to await</returns>
        public override Task PrintAsync()
        {
            Wire();

            _nativeWebView.Navigate(_uri);

            return(Task.CompletedTask);
        }
Exemple #3
0
        /// <summary>
        /// Present the Last.fm authentication UI and attempt to obtain a session key.
        /// </summary>
        /// <param name="authView">A WebView to display the Last.fm authentication page.</param>
        /// <param name="onSuccess">A callback for when the authentication is successful.</param>
        /// <param name="onFailure">A callback for when the authentication fails.</param>
        /// <returns>An async Task.</returns>
        public async Task LastFmLogin(Windows.UI.Xaml.Controls.WebView authView, Func <bool> onSuccess, Func <bool> onFailure)
        {
            Contract.Requires(authView != null);
            Contract.Requires(onSuccess != null);
            Contract.Requires(onFailure != null);

            try
            {
                HttpResponseMessage getTokenMessage = await __client.GetAsync(LastFmApiSecrets.LASTFMAPI_GET_TOKEN);

                string tokenResponse = await getTokenMessage.Content.ReadAsStringAsync();

                string token = JsonObject
                               .Parse(tokenResponse)
                               .GetNamedString("token");

                string authUri = string.Format(LastFmApiSecrets.LASTFMAPI_AUTH_URL_FORMAT, token);
                authView.LoadCompleted += async(sender, e) =>
                {
                    try
                    {
                        if (e.Uri.LocalPath.ToString().ToLowerInvariant() == LastFmApiSecrets.LASTFMAPI_AUTH_SUCCESS_URL)
                        {
                            string getSessionSignature            = string.Format(LastFmApiSecrets.LASTFMAPI_GET_SESSION_SIGN_FORMAT, token);
                            string getSessionSignatureMd5         = getSessionSignature.GetMd5Hash();
                            string getSession                     = string.Format(LastFmApiSecrets.LASTFMAPI_GET_SESSION_FORMAT, token, getSessionSignatureMd5);
                            HttpResponseMessage getSessionMessage = await __client.GetAsync(getSession);

                            string sessionResponse = await getSessionMessage.Content.ReadAsStringAsync();

                            JsonObject session = JsonObject
                                                 .Parse(sessionResponse)
                                                 .GetNamedObject("session");

                            LogIn(session.GetNamedString("name"), session.GetNamedString("key"));

                            onSuccess();
                        }
                    }
                    catch (Exception)
                    {
                        // Failure after user interaction
                        onFailure();
                    }
                };
                authView.NavigationFailed += (sender, e) =>
                {
                    // WebView navigation failure
                    onFailure();
                };
                authView.Navigate(new Uri(authUri));
            }
            catch (Exception)
            {
                // Failure before user interaction
                onFailure();
            }
        }
 public async Task <string> FetchContent(Uri url)
 {
     //webURL = url;
     //ShowWebView();
     Fetching = true;
     WebViewInstance.Navigate(url);
     while (Fetching)
     {
         await Task.Delay(50);
     }
     return(HtmlContent);
 }
Exemple #5
0
        private static void OnContentUriChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Windows.UI.Xaml.Controls.WebView wv = d as Windows.UI.Xaml.Controls.WebView;

            var uri = e.NewValue as Uri;

            if (uri == null)
            {
                return;
            }

            wv?.Navigate(uri);
        }
Exemple #6
0
 private void Control_NewWindowRequested(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNewWindowRequestedEventArgs args)
 {
     args.Handled = true;
     sender.Navigate(args.Uri);
 }