Esempio n. 1
0
        /// <summary>
        /// Creates a client context based on the properties of a remote event receiver
        /// </summary>
        /// <param name="properties">Properties of a remote event receiver</param>
        /// <returns>A ClientContext ready to call the web where the event originated</returns>
        internal ClientContext CreateRemoteEventReceiverClientContext(SPRemoteEventProperties properties)
        {
            Uri sharepointUrl;

            if (properties.ListEventProperties != null)
            {
                sharepointUrl = new Uri(properties.ListEventProperties.WebUrl);
            }
            else if (properties.ItemEventProperties != null)
            {
                sharepointUrl = new Uri(properties.ItemEventProperties.WebUrl);
            }
            else if (properties.WebEventProperties != null)
            {
                sharepointUrl = new Uri(properties.WebEventProperties.FullUrl);
            }
            else
            {
                return(null);
            }
            if (WebConfigAddInDataRescue.IsHighTrustApp())
            {
                return(GetS2SClientContextWithWindowsIdentity(sharepointUrl, null));
            }
            return(this.CreateAcsClientContextForUrl(properties, sharepointUrl));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a client context based on the properties of an add-in event
        /// </summary>
        /// <param name="properties">Properties of an add-in event</param>
        /// <param name="useAppWeb">True to target the app web, false to target the host web</param>
        /// <returns>A ClientContext ready to call the app web or the parent web</returns>
        private ClientContext CreateAppEventClientContext(SPRemoteEventProperties properties, bool useAppWeb)
        {
            if (properties.AppEventProperties == null)
            {
                return(null);
            }
            Uri sharepointUrl = useAppWeb ? properties.AppEventProperties.AppWebFullUrl : properties.AppEventProperties.HostWebFullUrl;

            if (WebConfigAddInDataRescue.IsHighTrustApp())
            {
                return(GetS2SClientContextWithWindowsIdentity(sharepointUrl, null));
            }
            return(this.CreateAcsClientContextForUrl(properties, sharepointUrl));
        }
Esempio n. 3
0
        /// <summary>
        /// Define o Contexto Sharepoint baseado no tipo de autenticação realizado
        /// </summary>
        /// <param name="context">Contexto Http obtido</param>
        private ClientContext StartObjectVariables(HttpContext httpContext, string siteCollectionUrl = null, string listName = null)
        {
            SharePointContextProvider ShpProvider = null;
            SharePointContextToken    ContextToken = null;
            SharePointContext         ShpContext = null;
            Uri           SharePointUrl = null;
            ClientContext _currentContext = null;
            string        AccessToken = null, contextTokenString = null;

            if (!WebConfigAddInDataRescue.IsHighTrustApp())
            {
                ShpProvider        = new SharePointAcsContextProvider();
                ShpContext         = ShpProvider.GetSharePointContext(httpContext);
                contextTokenString = ((SharePointAcsContext)ShpContext).ContextToken;
                ContextToken       = TokenHelper.ReadAndValidateContextToken(contextTokenString, httpContext.Request.Url.Authority) ?? TokenHelper.ReadAndValidateContextToken(contextTokenString, SharePointUrl.Authority);
            }
            else
            {
                ShpProvider = new SharePointHighTrustContextProvider();
                ShpContext  = ShpProvider.GetSharePointContext(httpContext);
            }

            if (!WebConfigAddInDataRescue.IsHighTrustApp() && string.IsNullOrWhiteSpace(siteCollectionUrl))
            {
                AccessToken     = TokenHelper.GetAccessToken(ContextToken, SharePointUrl.Authority).AccessToken;
                _currentContext = ShpContext.GetClientContextWithAccessToken(SharePointUrl.ToString(), AccessToken);
            }
            else if (WebConfigAddInDataRescue.IsHighTrustApp() && string.IsNullOrWhiteSpace(siteCollectionUrl))
            {
                AccessToken     = ShpContext.UserAccessTokenForSPAppWeb ?? ShpContext.UserAccessTokenForSPHost;
                _currentContext = ShpContext.CreateAppOnlyClientContextForSPHost();
            }
            else if (!string.IsNullOrWhiteSpace(siteCollectionUrl))
            {
                AccessToken     = ShpContext.UserAccessTokenForSPHost;
                _currentContext = TokenHelper.GetClientContextWithAccessToken(siteCollectionUrl, AccessToken);
            }

            return(_currentContext);
        }