Ejemplo n.º 1
0
        // Get a context from the passed authentication settings
        public static ClientContext GetContext(string strURL, AuthenticationSettings authenticationsettings)
        {
            ClientContext clientcontext = new ClientContext(strURL);

            /* Using authentication settings supplied by settings object */

            if (authenticationsettings.AuthenticationType == AuthenticationSettings.AuthenticationTypes.Current)
            {
                clientcontext.Credentials = CredentialCache.DefaultCredentials;
            }
            if (authenticationsettings.AuthenticationType == AuthenticationSettings.AuthenticationTypes.Specified)
            {
                clientcontext.Credentials = new NetworkCredential(authenticationsettings.username, authenticationsettings.password, authenticationsettings.domain);
            }
            if (authenticationsettings.AuthenticationType == AuthenticationSettings.AuthenticationTypes.Forms)
            {
                clientcontext.AuthenticationMode           = ClientAuthenticationMode.FormsAuthentication;
                clientcontext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo(authenticationsettings.username, authenticationsettings.password);
            }
            if (authenticationsettings.AuthenticationType == AuthenticationSettings.AuthenticationTypes.Office365)
            {
                // To get the authentication for Office 365 the site url needs to end with a /
                string strHelperSite;
                if (strURL.EndsWith("/"))
                {
                    strHelperSite = strURL;
                }
                else
                {
                    strHelperSite = strURL + "/";
                }

                helper = new MsOnlineClaimsHelper(
                    authenticationsettings.username,
                    authenticationsettings.password,
                    strHelperSite);

                clientcontext.ExecutingWebRequest += new EventHandler <WebRequestEventArgs>(ctx_ExecutingWebRequest);
            }

            return(clientcontext);
        }
Ejemplo n.º 2
0
        // Get a context from the passed authentication settings
        public static ClientContext GetContext(string strURL, AuthenticationSettings authenticationsettings)
        {
            ClientContext clientcontext = new ClientContext(strURL);

            /* Using authentication settings supplied by settings object */

            if (authenticationsettings.AuthenticationType == AuthenticationSettings.AuthenticationTypes.Current)
            {
                clientcontext.Credentials = CredentialCache.DefaultCredentials; 
            }
            if (authenticationsettings.AuthenticationType == AuthenticationSettings.AuthenticationTypes.Specified)
            {
                clientcontext.Credentials = new NetworkCredential(authenticationsettings.username, authenticationsettings.password, authenticationsettings.domain);
            }
            if (authenticationsettings.AuthenticationType == AuthenticationSettings.AuthenticationTypes.Forms)
            {
                clientcontext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
                clientcontext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo(authenticationsettings.username, authenticationsettings.password);
            }
            if (authenticationsettings.AuthenticationType == AuthenticationSettings.AuthenticationTypes.Office365)
            {
                // To get the authentication for Office 365 the site url needs to end with a /
                string strHelperSite;
                if (strURL.EndsWith("/"))
                {
                    strHelperSite = strURL;
                }
                else
                {
                    strHelperSite = strURL+"/";
                }

                helper = new MsOnlineClaimsHelper(
                authenticationsettings.username,
                authenticationsettings.password,
                strHelperSite);

                clientcontext.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(ctx_ExecutingWebRequest);

            }
             
            return clientcontext;


        }