예제 #1
0
        /*private string DiscoverPostApiUrl(string baseUrl, string blogPath)
         * {
         *
         * }*/

        /// <summary>
        /// Verifies the user credentials and determines whether SharePoint is configure to use HTTP or MetaWeblog authentication
        /// </summary>
        /// <param name="postApiUrl"></param>
        /// <param name="blogCredentials"></param>
        /// <param name="credentials"></param>
        /// <returns></returns>
        private static bool VerifyCredentialsAndDetectAuthScheme(string postApiUrl, IBlogCredentials blogCredentials, IBlogCredentialsAccessor credentials)
        {
            BlogClientAttribute blogClientAttr = (BlogClientAttribute)typeof(SharePointClient).GetCustomAttributes(typeof(BlogClientAttribute), false)[0];
            SharePointClient    client         = (SharePointClient)BlogClientManager.CreateClient(blogClientAttr.TypeName, postApiUrl, credentials);

            return(SharePointClient.VerifyCredentialsAndDetectAuthScheme(blogCredentials, client));
        }
        public static bool CredentialsAreEqual(IBlogCredentials c1, IBlogCredentials c2)
        {
            if (c1.Username != c2.Username)
            {
                return(false);
            }

            if (c1.Password != c2.Password)
            {
                return(false);
            }

            foreach (string customValue in c1.CustomValues)
            {
                string c1Value = c1.GetCustomValue(customValue);
                string c2Value = c2.GetCustomValue(customValue);

                if (c1Value != c2Value)
                {
                    return(false);
                }
            }

            // if we got this far then they are equal
            return(true);
        }
        public static void Copy(IBlogCredentials sourceCredentials, IBlogCredentials destCredentials)
        {
            destCredentials.Clear();
            destCredentials.Username = sourceCredentials.Username;
            destCredentials.Password = sourceCredentials.Password;
            foreach (string customValue in sourceCredentials.CustomValues)
            {
                destCredentials.SetCustomValue(customValue, sourceCredentials.GetCustomValue(customValue));
            }

            destCredentials.Domain = sourceCredentials.Domain;
        }
예제 #4
0
        public static bool VerifyCredentialsAndDetectAuthScheme(IBlogCredentials blogCredentials, SharePointClient client)
        {
            //Attempt to execute the GetUsersBlogs() operation using standard HTTP authentication
            //If the server challenges with an HTTP 401, but doesn't include with WWW-authentication
            //header, then the server is configured to use MetaWeblog for authentication, so we
            //re-issue the request using that authentication scheme instead.

            AuthenticationScheme authScheme         = AuthenticationScheme.Http;
            AuthenticationScheme requiredAuthScheme = AuthenticationScheme.Unknown;

            while (requiredAuthScheme == AuthenticationScheme.Unknown || authScheme != requiredAuthScheme)
            {
                if (requiredAuthScheme != AuthenticationScheme.Unknown)
                {
                    authScheme = requiredAuthScheme;
                }

                blogCredentials.SetCustomValue(AUTH_SCHEME, authScheme.ToString());
                try
                {
                    TransientCredentials tc = new TransientCredentials(blogCredentials.Username, blogCredentials.Password, null);
                    client.Credentials.TransientCredentials = tc;
                    client.InitTransientCredential(tc);
                    client.GetUsersBlogs();
                    return(true);
                }
                catch (WebException e)
                {
                    requiredAuthScheme = GetRequiredAuthScheme(e);
                }
                catch (BlogClientHttpErrorException e)
                {
                    requiredAuthScheme = GetRequiredAuthScheme(e.Exception);
                }
                catch (BlogClientAuthenticationException e)
                {
                    requiredAuthScheme = GetRequiredAuthScheme(e.WebException);
                }
                catch (Exception)
                {
                    throw;
                }
                Debug.Assert(requiredAuthScheme != AuthenticationScheme.Unknown, "Unexpected authscheme");                 //this would cause an infinite loop!
            }
            return(false);
        }
        public void ShowPanel(string defaultServiceName, string homepageUrl, string accountId, IBlogCredentials credentials)
        {
            // save reference to settings
            _homepageUrl = homepageUrl;
            _accountId   = accountId;
            _credentials = credentials;

            // find provider and select it (add it to the combo if necessary)
            IBlogProviderDescription provider = BlogProviderManager.FindProviderByName(defaultServiceName);

            if (provider != null)
            {
                BlogProviderDescriptionProxy providerProxy = new BlogProviderDescriptionProxy(provider);

                if (!comboBoxSelectProvider.Items.Contains(providerProxy))
                {
                    comboBoxSelectProvider.Items.Add(providerProxy);
                }

                comboBoxSelectProvider.SelectedItem = providerProxy;
            }
            else
            {
                // add the special 'select provider' entry and select it
                if (!comboBoxSelectProvider.Items.Contains(BlogProviderDescriptionProxy.SelectProvider))
                {
                    comboBoxSelectProvider.Items.Add(BlogProviderDescriptionProxy.SelectProvider);
                }

                comboBoxSelectProvider.SelectedItem = BlogProviderDescriptionProxy.SelectProvider;
            }

            // reset results
            _targetBlog = null;
            _usersBlogs = new BlogInfo[] { };
        }
예제 #6
0
 public static StaticSiteConfig LoadConfigFromCredentials(IBlogCredentials blogCredentials)
 => LoadConfigFromCredentials(new BlogCredentialsAccessor("", blogCredentials));
예제 #7
0
 public void SaveToCredentials(IBlogCredentials blogCredentials)
 => SaveToCredentials(new BlogCredentialsAccessor("", blogCredentials));
        public void ShowPanel(string defaultServiceName, string homepageUrl, string accountId, IBlogCredentials credentials)
        {
            // save reference to settings
            _homepageUrl = homepageUrl;
            _accountId = accountId;
            _credentials = credentials;

            // find provider and select it (add it to the combo if necessary)
            IBlogProviderDescription provider = BlogProviderManager.FindProviderByName(defaultServiceName);
            if (provider != null)
            {
                BlogProviderDescriptionProxy providerProxy = new BlogProviderDescriptionProxy(provider);

                if (!comboBoxSelectProvider.Items.Contains(providerProxy))
                    comboBoxSelectProvider.Items.Add(providerProxy);

                comboBoxSelectProvider.SelectedItem = providerProxy;
            }
            else
            {
                // add the special 'select provider' entry and select it
                if (!comboBoxSelectProvider.Items.Contains(BlogProviderDescriptionProxy.SelectProvider))
                    comboBoxSelectProvider.Items.Add(BlogProviderDescriptionProxy.SelectProvider);

                comboBoxSelectProvider.SelectedItem = BlogProviderDescriptionProxy.SelectProvider;
            }

            // reset results
            _targetBlog = null;
            _usersBlogs = new BlogInfo[] { };
        }
 public BlogCredentialsAccessor(string accountId, IBlogCredentials credentials)
 {
     _accountId   = accountId;
     _credentials = credentials;
 }
        /*private string DiscoverPostApiUrl(string baseUrl, string blogPath)
        {

        }*/

        /// <summary>
        /// Verifies the user credentials and determines whether SharePoint is configure to use HTTP or MetaWeblog authentication
        /// </summary>
        /// <param name="postApiUrl"></param>
        /// <param name="blogCredentials"></param>
        /// <param name="credentials"></param>
        /// <returns></returns>
        private static bool VerifyCredentialsAndDetectAuthScheme(string postApiUrl, IBlogCredentials blogCredentials, IBlogCredentialsAccessor credentials)
        {
            BlogClientAttribute blogClientAttr = (BlogClientAttribute)typeof(SharePointClient).GetCustomAttributes(typeof(BlogClientAttribute), false)[0];
            SharePointClient client = (SharePointClient)BlogClientManager.CreateClient(blogClientAttr.TypeName, postApiUrl, credentials);

            return SharePointClient.VerifyCredentialsAndDetectAuthScheme(blogCredentials, client);
        }
예제 #11
0
 public SharePointBlogDetector(IBlogClientUIContext uiContext, Control hiddenBrowserParentControl, string localBlogId, string homepageUrl, IBlogCredentialsAccessor credentials, IBlogCredentials blogCredentials)
     : base(uiContext, hiddenBrowserParentControl, localBlogId, homepageUrl, credentials)
 {
     _blogCredentials = blogCredentials;
 }
 public SharePointBlogDetector(IBlogClientUIContext uiContext, Control hiddenBrowserParentControl, string localBlogId, string homepageUrl, IBlogCredentialsAccessor credentials, IBlogCredentials blogCredentials)
     : base(uiContext, hiddenBrowserParentControl, localBlogId, homepageUrl, credentials)
 {
     _blogCredentials = blogCredentials;
 }
 public BlogCredentialsAccessor(string accountId, IBlogCredentials credentials)
 {
     _accountId = accountId;
     _credentials = credentials;
 }
        public static bool CredentialsAreEqual(IBlogCredentials c1, IBlogCredentials c2)
        {
            if (c1.Username != c2.Username)
                return false;

            if (c1.Password != c2.Password)
                return false;

            foreach (string customValue in c1.CustomValues)
            {
                string c1Value = c1.GetCustomValue(customValue);
                string c2Value = c2.GetCustomValue(customValue);

                if (c1Value != c2Value)
                    return false;
            }

            // if we got this far then they are equal
            return true;
        }
        public static void Copy(IBlogCredentials sourceCredentials, IBlogCredentials destCredentials)
        {
            destCredentials.Clear();
            destCredentials.Username = sourceCredentials.Username;
            destCredentials.Password = sourceCredentials.Password;
            foreach (string customValue in sourceCredentials.CustomValues)
                destCredentials.SetCustomValue(customValue, sourceCredentials.GetCustomValue(customValue));

            destCredentials.Domain = sourceCredentials.Domain;
        }
        public static bool VerifyCredentialsAndDetectAuthScheme(IBlogCredentials blogCredentials, SharePointClient client)
        {
            //Attempt to execute the GetUsersBlogs() operation using standard HTTP authentication
            //If the server challenges with an HTTP 401, but doesn't include with WWW-authentication
            //header, then the server is configured to use MetaWeblog for authentication, so we
            //re-issue the request using that authentication scheme instead.

            AuthenticationScheme authScheme = AuthenticationScheme.Http;
            AuthenticationScheme requiredAuthScheme = AuthenticationScheme.Unknown;

            while (requiredAuthScheme == AuthenticationScheme.Unknown || authScheme != requiredAuthScheme)
            {
                if (requiredAuthScheme != AuthenticationScheme.Unknown)
                    authScheme = requiredAuthScheme;

                blogCredentials.SetCustomValue(AUTH_SCHEME, authScheme.ToString());
                try
                {
                    TransientCredentials tc = new TransientCredentials(blogCredentials.Username, blogCredentials.Password, null);
                    client.Credentials.TransientCredentials = tc;
                    client.InitTransientCredential(tc);
                    client.GetUsersBlogs();
                    return true;
                }
                catch (WebException e)
                {
                    requiredAuthScheme = GetRequiredAuthScheme(e);
                }
                catch (BlogClientHttpErrorException e)
                {
                    requiredAuthScheme = GetRequiredAuthScheme(e.Exception);
                }
                catch (BlogClientAuthenticationException e)
                {
                    requiredAuthScheme = GetRequiredAuthScheme(e.WebException);
                }
                catch (Exception)
                {
                    throw;
                }
                Debug.Assert(requiredAuthScheme != AuthenticationScheme.Unknown, "Unexpected authscheme"); //this would cause an infinite loop!
            }
            return false;
        }