private static Uri GetAppRedirectUrl(ISessionContext context) { if (null == context) { throw new ArgumentNullException(nameof(context)); } // Make sure we don't redirect over and over again. const string SPHasRedirectedToSharePointKey = "SPHasRedirectedToSharePoint"; if (!string.IsNullOrEmpty(context.GetParam <string>(SPHasRedirectedToSharePointKey))) { return(null); } var spHostUrl = CustomSharePointContext.GetSPHostUrl(context); if (null == spHostUrl) { return(null); } var requestUrl = context.GetRequestUrl; if (null == requestUrl) { return(null); } var queryNameValueCollection = HttpUtility.ParseQueryString(requestUrl.Query); // Removes the values that are included in {StandardTokens}, as {StandardTokens} // will be inserted at the beginning of the query string. queryNameValueCollection.Remove(Constants.SPHostUrlKey); queryNameValueCollection.Remove(Constants.SPAppWebUrlKey); queryNameValueCollection.Remove(Constants.SPLanguageKey); queryNameValueCollection.Remove(Constants.SPClientTagKey); queryNameValueCollection.Remove(Constants.SPProductNumberKey); // Adds SPHasRedirectedToSharePoint=1. queryNameValueCollection.Add(SPHasRedirectedToSharePointKey, "1"); var returnUrlBuilder = new UriBuilder(requestUrl) { Query = queryNameValueCollection.ToString() }; // Inserts StandardTokens. const string StandardTokens = "{StandardTokens}"; var returnUrlString = returnUrlBuilder.Uri.AbsoluteUri; returnUrlString = returnUrlString.Insert(returnUrlString.IndexOf("?", StringComparison.Ordinal) + 1, StandardTokens + "&"); var redirectUrlString = TokenHelper.GetAppContextTokenRequestUrl(spHostUrl.AbsoluteUri, Uri.EscapeDataString(returnUrlString)); return(new Uri(redirectUrlString, UriKind.Absolute)); }
protected override bool ValidateSharePointContext( CustomSharePointContext spContext, ISessionContext context) { if (null == context) { throw new ArgumentNullException(nameof(context)); } if (!(spContext is CustomSharePointContext.CustomSharePointAcsContext spAcsContext)) { return(false); } var spHostUrl = CustomSharePointContext.GetSPHostUrl(context); var spContextString = GetContextString(context); return(spHostUrl == spAcsContext.SPHostUrl && !string.IsNullOrEmpty(spAcsContext.ContextToken) && (string.IsNullOrEmpty(spContextString) || spContextString == spAcsContext.ContextToken)); }
protected override bool ValidateSharePointContext( CustomSharePointContext spContext, ISessionContext context) { if (null == context) { throw new ArgumentNullException(nameof(context)); } if (!(spContext is CustomSharePointContext.CustomSharePointHighTrustContext spHighTrustContext)) { return(false); } var spHostUrl = CustomSharePointContext.GetSPHostUrl(context); var logonUserIdentity = context.GetLogonUser; return(spHostUrl == spHighTrustContext.SPHostUrl && logonUserIdentity != null && logonUserIdentity.IsAuthenticated && !logonUserIdentity.IsGuest && logonUserIdentity.User == spHighTrustContext.LogonUserIdentity.User); }
public CustomSharePointContext CreateSharePointContext(ISessionContext context) { if (null == context) { throw new ArgumentNullException(nameof(context)); } var spHostUrl = CustomSharePointContext.GetSPHostUrl(context); if (null == spHostUrl) { return(null); } var spLanguage = context.GetParam <string>(Constants.SPLanguageKey); if (string.IsNullOrEmpty(spLanguage)) { return(null); } var spClientTag = context.GetParam <string>(Constants.SPClientTagKey); if (string.IsNullOrEmpty(spClientTag)) { return(null); } var spProductNumber = context.GetParam <string>(Constants.SPProductNumberKey); if (string.IsNullOrEmpty(spProductNumber)) { return(null); } var spAppWebUrlString = TokenHelper.EnsureTrailingSlash(context.GetParam <string>(Constants.SPAppWebUrlKey)); if (!Uri.TryCreate(spAppWebUrlString, UriKind.Absolute, out var spAppWebUrl) || !(spAppWebUrl.Scheme == Uri.UriSchemeHttp || spAppWebUrl.Scheme == Uri.UriSchemeHttps)) { spAppWebUrl = null; } return(CreateSharePointContext(spHostUrl, spAppWebUrl, spLanguage, spClientTag, spProductNumber, context)); }