DecodeQueryString() static private method

static private DecodeQueryString ( string queryString ) : string>.IDictionary
queryString string
return string>.IDictionary
Exemplo n.º 1
0
 /// <summary>
 /// Checks whether the Uri passed into your application comes from the Facebook
 /// app as a result of a completed login attempt.
 ///
 /// Your code will usually look like this:
 /// <code>
 /// RootFrame.Navigating += async (sender, e) => {
 ///   if (ParseFacebookUtils.IsLoginRedirect(e.Uri)) {
 ///     ParseUser user = await ParseFacebookUtils.EndLoginAsync(
 ///         sender, e, new Uri("/LandingPage.xaml", UriKind.Relative));
 ///     // A new user is now logged in.
 ///   }
 /// };
 /// </code>
 /// </summary>
 /// <param name="uri"></param>
 /// <returns><c>true</c> iff the Uri is a Facebook login redirect, <c>false</c>
 /// otherwise</returns>
 public static bool IsLogInRedirect(Uri uri)
 {
     if (uri.ToString().StartsWith("/Protocol?"))
     {
         if (!uri.IsAbsoluteUri)
         {
             uri = new Uri(new Uri("dummy:///"), uri);
         }
         var queryString = ParseClient.DecodeQueryString(uri.Query.Substring(1));
         var launchUri   = new Uri(Uri.UnescapeDataString(queryString["encodedLaunchUri"]));
         if (launchUri.IsAbsoluteUri &&
             launchUri.AbsoluteUri.StartsWith(NativeLoginAppPrefix))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Call this method within your RootFrame.Navigating event handler to complete native Facebook
        /// sign-on. When handling a Facebook login redirect URI, this method will cancel the
        /// pending navigation, begin asynchronously logging in the user, and immediately navigate
        /// to the <paramref name="redirectUri"/>.
        ///
        /// Your code will usually look like this:
        /// <code>
        /// RootFrame.Navigating += async (sender, e) => {
        ///   if (ParseFacebookUtils.IsLoginRedirect(e.Uri)) {
        ///     ParseUser user = await ParseFacebookUtils.EndLoginAsync(
        ///         sender, e, new Uri("/LandingPage.xaml", UriKind.Relative));
        ///     // A new user is now logged in.
        ///   }
        /// };
        /// </code>
        /// </summary>
        /// <param name="sender">The sender for the Navigating event.</param>
        /// <param name="e">The Navigating event args.</param>
        /// <param name="redirectUri">The Uri within your app to redirect to.</param>
        /// <returns>The ParseUser created or logged in using Facebook credentials, or null if
        /// this was not a Facebook login redirect.</returns>
        public async static Task <ParseUser> EndLogInAsync(object sender,
                                                           NavigatingCancelEventArgs e,
                                                           Uri redirectUri)
        {
            if (!IsLogInRedirect(e.Uri))
            {
                return(null);
            }
            authProvider.ResponseUrlOverride = NativeResponseUrl;
            Action <Uri> navigate = (_) => { };

            authProvider.Navigate += navigate;
            try {
                var cts = new CancellationTokenSource();
                // Kicks off a dummy to restart authentication.
                var result = ParseUser.LogInWithAsync("facebook", cts.Token);
                // Complete the authentication.
                var uri         = new Uri(new Uri("dummy:///"), e.Uri);
                var queryString = ParseClient.DecodeQueryString(uri.Query.Substring(1));
                var launchUri   = new Uri(Uri.UnescapeDataString(queryString["encodedLaunchUri"]));
                if (!authProvider.HandleNavigation(launchUri))
                {
                    // Cancel the pending attempt to log in if for some reason this wasn't actually
                    // a facebook login navigation (unlikely at this point)
                    cts.Cancel();
                }

                // Cancel navigation and redirect to the new Uri.
                e.Cancel = true;
                var navService = sender as NavigationService;
                if (navService == null)
                {
                    throw new ArgumentException("sender must be a NavigationService", "sender");
                }
                // Welcome to Windows Phone... sometimes you just have to dispatch for no
                // particularly good reason.
                Deployment.Current.Dispatcher.BeginInvoke(() => navService.Navigate(redirectUri));
                return(await result);
            } finally {
                authProvider.Navigate           -= navigate;
                authProvider.ResponseUrlOverride = null;
            }
        }