From 063af0b4837f9d213fc0450d6794c4839693f725 Mon Sep 17 00:00:00 2001 From: Bas Lijten Date: Mon, 17 Aug 2015 14:51:40 +0200 Subject: [PATCH 1/3] Fixex authentication type and added context load and save methods Fixex authentication type and added context load and save methods --- README.md | 2 +- SharePointContextSaml.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c09ee65..72008bd 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ static SharePointContextProvider() } else { - if(HttpContext.Current.User.Identity.AuthenticationType == "Federation") { + if(HttpContext.Current.User.Identity.GetType() == typeof(ClaimsIdentity)) { SharePointContextProvider.current = new SharePointHighTrustSamlContextProvider(); } else { SharePointContextProvider.current = new SharePointHighTrustContextProvider(); diff --git a/SharePointContextSaml.cs b/SharePointContextSaml.cs index 0dd36bc..a672c36 100644 --- a/SharePointContextSaml.cs +++ b/SharePointContextSaml.cs @@ -546,6 +546,16 @@ protected override bool ValidateSharePointContext(SharePointContext spContext, H return false; } + + protected override SharePointContext LoadSharePointContext(HttpContextBase httpContext) + { + return httpContext.Session[SPContextKey] as SharePointHighTrustSamlContext; + } + + protected override SharePointContext SaveSharePointContext(HttpContextBase httpContext) + { + return httpContext.Session[SPContextKey] as SharePointHighTrustSamlContext; + } } #endregion HighTrust From f0b1b95d6341d021cae69604e07c73cd9894bc20 Mon Sep 17 00:00:00 2001 From: Bas Lijten Date: Mon, 17 Aug 2015 14:57:41 +0200 Subject: [PATCH 2/3] Revert "Fixex authentication type and added context load and save methods" This reverts commit 063af0b4837f9d213fc0450d6794c4839693f725. --- README.md | 2 +- SharePointContextSaml.cs | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/README.md b/README.md index 72008bd..c09ee65 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ static SharePointContextProvider() } else { - if(HttpContext.Current.User.Identity.GetType() == typeof(ClaimsIdentity)) { + if(HttpContext.Current.User.Identity.AuthenticationType == "Federation") { SharePointContextProvider.current = new SharePointHighTrustSamlContextProvider(); } else { SharePointContextProvider.current = new SharePointHighTrustContextProvider(); diff --git a/SharePointContextSaml.cs b/SharePointContextSaml.cs index a672c36..0dd36bc 100644 --- a/SharePointContextSaml.cs +++ b/SharePointContextSaml.cs @@ -546,16 +546,6 @@ protected override bool ValidateSharePointContext(SharePointContext spContext, H return false; } - - protected override SharePointContext LoadSharePointContext(HttpContextBase httpContext) - { - return httpContext.Session[SPContextKey] as SharePointHighTrustSamlContext; - } - - protected override SharePointContext SaveSharePointContext(HttpContextBase httpContext) - { - return httpContext.Session[SPContextKey] as SharePointHighTrustSamlContext; - } } #endregion HighTrust From a8a22a3fdc08f49157f39dec10f07e918112375b Mon Sep 17 00:00:00 2001 From: BasLijten Date: Mon, 17 Aug 2015 15:01:53 +0200 Subject: [PATCH 3/3] Accidentally commited wrong code. Load and Save function now works --- README.md | 2 +- SharePointContextSaml.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 72008bd..a6afd63 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ static SharePointContextProvider() } else { - if(HttpContext.Current.User.Identity.GetType() == typeof(ClaimsIdentity)) { + if (HttpContext.Current.User.Identity.GetType() == typeof(ClaimsIdentity)) { SharePointContextProvider.current = new SharePointHighTrustSamlContextProvider(); } else { SharePointContextProvider.current = new SharePointHighTrustContextProvider(); diff --git a/SharePointContextSaml.cs b/SharePointContextSaml.cs index a672c36..f522f16 100644 --- a/SharePointContextSaml.cs +++ b/SharePointContextSaml.cs @@ -326,7 +326,7 @@ private static TokenHelper.ClaimsUserIdClaim RetrieveIdentityForSamlClaimsUser(C return id; } - + /// /// NOT IMPLEMENTED /// @@ -518,11 +518,11 @@ private static void RenewAccessTokenIfNeeded(ref Tuple accessT /// public class SharePointHighTrustSamlContextProvider : SharePointHighTrustContextProvider { - + private const string SPContextKey = "SPContext"; protected override SharePointContext CreateSharePointContext(Uri spHostUrl, Uri spAppWebUrl, string spLanguage, string spClientTag, string spProductNumber, HttpRequestBase httpRequest) { ClaimsIdentity logonUserIdentity = HttpContext.Current.User.Identity as ClaimsIdentity; - if (logonUserIdentity == null || !logonUserIdentity.IsAuthenticated ) + if (logonUserIdentity == null || !logonUserIdentity.IsAuthenticated) { return null; } @@ -552,9 +552,9 @@ protected override SharePointContext LoadSharePointContext(HttpContextBase httpC return httpContext.Session[SPContextKey] as SharePointHighTrustSamlContext; } - protected override SharePointContext SaveSharePointContext(HttpContextBase httpContext) + protected override void SaveSharePointContext(SharePointContext spContext, HttpContextBase httpContext) { - return httpContext.Session[SPContextKey] as SharePointHighTrustSamlContext; + httpContext.Session[SPContextKey] = spContext as SharePointHighTrustSamlContext; } }