From 138bc6a20f638eb9993c4e9c606ac7b4e322f947 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Thu, 20 Aug 2015 00:10:40 +0200 Subject: [PATCH] Added owin.RequestUser --- src/Microsoft.AspNet.Owin/OwinConstants.cs | 5 +++-- src/Microsoft.AspNet.Owin/OwinEnvironment.cs | 2 ++ src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs | 12 ++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Owin/OwinConstants.cs b/src/Microsoft.AspNet.Owin/OwinConstants.cs index 47761c96c2..039209c098 100644 --- a/src/Microsoft.AspNet.Owin/OwinConstants.cs +++ b/src/Microsoft.AspNet.Owin/OwinConstants.cs @@ -20,11 +20,12 @@ namespace Microsoft.AspNet.Owin #endregion - #region OWIN v1.1.0 - 3.2.1 Request Data + #region OWIN v1.0.1 - 3.2.1 Request Data - // OWIN 1.1.0 http://owin.org/html/owin.html + // OWIN 1.0.1 http://owin.org/html/owin.html public const string RequestId = "owin.RequestId"; + public const string RequestUser = "owin.RequestUser"; #endregion diff --git a/src/Microsoft.AspNet.Owin/OwinEnvironment.cs b/src/Microsoft.AspNet.Owin/OwinEnvironment.cs index 5c231eb0e8..2b331b0d57 100644 --- a/src/Microsoft.AspNet.Owin/OwinEnvironment.cs +++ b/src/Microsoft.AspNet.Owin/OwinEnvironment.cs @@ -9,6 +9,7 @@ using System.IO; using System.Linq; using System.Net; using System.Net.WebSockets; +using System.Security.Claims; using System.Security.Cryptography.X509Certificates; using System.Security.Principal; using System.Threading; @@ -57,6 +58,7 @@ namespace Microsoft.AspNet.Owin (feature, value) => feature.QueryString = Utilities.AddQuestionMark(Convert.ToString(value))) }, { OwinConstants.RequestHeaders, new FeatureMap(feature => feature.Headers, (feature, value) => feature.Headers = (IDictionary)value) }, { OwinConstants.RequestBody, new FeatureMap(feature => feature.Body, () => Stream.Null, (feature, value) => feature.Body = (Stream)value) }, + { OwinConstants.RequestUser, new FeatureMap(feature => feature.User, () => null, (feature, value) => feature.User = (ClaimsPrincipal)value) }, { OwinConstants.ResponseStatusCode, new FeatureMap(feature => feature.StatusCode, () => 200, (feature, value) => feature.StatusCode = Convert.ToInt32(value)) }, { OwinConstants.ResponseReasonPhrase, new FeatureMap(feature => feature.ReasonPhrase, (feature, value) => feature.ReasonPhrase = Convert.ToString(value)) }, diff --git a/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs b/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs index 6dd44e52e6..614bccf333 100644 --- a/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs +++ b/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs @@ -263,8 +263,16 @@ namespace Microsoft.AspNet.Owin ClaimsPrincipal IHttpAuthenticationFeature.User { - get { return Utilities.MakeClaimsPrincipal(Prop(OwinConstants.Security.User)); } - set { Prop(OwinConstants.Security.User, value); } + get + { + return Prop(OwinConstants.RequestUser) + ?? Utilities.MakeClaimsPrincipal(Prop(OwinConstants.Security.User)); + } + set + { + Prop(OwinConstants.RequestUser, value); + Prop(OwinConstants.Security.User, value); + } } IAuthenticationHandler IHttpAuthenticationFeature.Handler { get; set; }