diff --git a/src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationDescription.cs b/src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationDescription.cs index 81653dd1..97ca3fe1 100644 --- a/src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationDescription.cs +++ b/src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationDescription.cs @@ -20,23 +20,23 @@ public class AuthenticationDescription /// Initializes a new instance of the class /// public AuthenticationDescription() + : this(items: null) { - Dictionary = new Dictionary(StringComparer.Ordinal); } /// /// Initializes a new instance of the class /// - /// - public AuthenticationDescription([NotNull] IDictionary properties) + /// + public AuthenticationDescription(IDictionary items) { - Dictionary = properties; + Items = items ?? new Dictionary(StringComparer.Ordinal); ; } /// /// Contains metadata about the authentication provider. /// - public IDictionary Dictionary { get; private set; } + public IDictionary Items { get; private set; } /// /// Gets or sets the name used to reference the authentication middleware instance. @@ -44,7 +44,7 @@ public AuthenticationDescription([NotNull] IDictionary propertie public string AuthenticationScheme { get { return GetString(AuthenticationSchemePropertyKey); } - set { Dictionary[AuthenticationSchemePropertyKey] = value; } + set { Items[AuthenticationSchemePropertyKey] = value; } } /// @@ -53,13 +53,13 @@ public string AuthenticationScheme public string Caption { get { return GetString(CaptionPropertyKey); } - set { Dictionary[CaptionPropertyKey] = value; } + set { Items[CaptionPropertyKey] = value; } } private string GetString(string name) { object value; - if (Dictionary.TryGetValue(name, out value)) + if (Items.TryGetValue(name, out value)) { return Convert.ToString(value, CultureInfo.InvariantCulture); } diff --git a/src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationManager.cs b/src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationManager.cs new file mode 100644 index 00000000..f7b4342b --- /dev/null +++ b/src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationManager.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Security.Claims; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Http.Authentication +{ + public abstract class AuthenticationManager + { + public abstract IEnumerable GetAuthenticationSchemes(); + + public abstract AuthenticationResult Authenticate(string authenticationScheme); + + public abstract Task AuthenticateAsync(string authenticationScheme); + + public virtual void Challenge() + { + Challenge(authenticationScheme: null, properties: null); + } + + public virtual void Challenge(AuthenticationProperties properties) + { + Challenge(authenticationScheme: null, properties: properties); + } + + public virtual void Challenge(string authenticationScheme) + { + Challenge(authenticationScheme: authenticationScheme, properties: null); + } + + public abstract void Challenge(string authenticationScheme, AuthenticationProperties properties); + + public void SignIn(string authenticationScheme, ClaimsPrincipal principal) + { + SignIn(authenticationScheme, principal, properties: null); + } + + public abstract void SignIn(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties); + + public virtual void SignOut() + { + SignOut(authenticationScheme: null, properties: null); + } + + public abstract void SignOut(string authenticationScheme); + + public abstract void SignOut(string authenticationScheme, AuthenticationProperties properties); + } +} diff --git a/src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationProperties.cs b/src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationProperties.cs index 475dd027..f6574163 100644 --- a/src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationProperties.cs +++ b/src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationProperties.cs @@ -24,51 +24,51 @@ public class AuthenticationProperties /// Initializes a new instance of the class /// public AuthenticationProperties() - : this(dictionary: null) + : this(items: null) { } /// /// Initializes a new instance of the class /// - /// - public AuthenticationProperties(IDictionary dictionary) + /// + public AuthenticationProperties(IDictionary items) { - Dictionary = dictionary ?? new Dictionary(StringComparer.Ordinal); + Items = items ?? new Dictionary(StringComparer.Ordinal); } /// /// State values about the authentication session. /// - public IDictionary Dictionary { get; private set; } + public IDictionary Items { get; private set; } /// /// Gets or sets whether the authentication session is persisted across multiple requests. /// public bool IsPersistent { - get { return Dictionary.ContainsKey(IsPersistentKey); } + get { return Items.ContainsKey(IsPersistentKey); } set { - if (Dictionary.ContainsKey(IsPersistentKey)) + if (Items.ContainsKey(IsPersistentKey)) { if (!value) { - Dictionary.Remove(IsPersistentKey); + Items.Remove(IsPersistentKey); } } else { if (value) { - Dictionary.Add(IsPersistentKey, string.Empty); + Items.Add(IsPersistentKey, string.Empty); } } } } /// - /// Gets or sets the full path or absolute URI to be used as an http redirect response value. + /// Gets or sets the full path or absolute URI to be used as an http redirect response value. /// [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "By design")] public string RedirectUri @@ -76,19 +76,19 @@ public string RedirectUri get { string value; - return Dictionary.TryGetValue(RedirectUriKey, out value) ? value : null; + return Items.TryGetValue(RedirectUriKey, out value) ? value : null; } set { if (value != null) { - Dictionary[RedirectUriKey] = value; + Items[RedirectUriKey] = value; } else { - if (Dictionary.ContainsKey(RedirectUriKey)) + if (Items.ContainsKey(RedirectUriKey)) { - Dictionary.Remove(RedirectUriKey); + Items.Remove(RedirectUriKey); } } } @@ -102,7 +102,7 @@ public DateTimeOffset? IssuedUtc get { string value; - if (Dictionary.TryGetValue(IssuedUtcKey, out value)) + if (Items.TryGetValue(IssuedUtcKey, out value)) { DateTimeOffset dateTimeOffset; if (DateTimeOffset.TryParseExact(value, UtcDateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dateTimeOffset)) @@ -116,13 +116,13 @@ public DateTimeOffset? IssuedUtc { if (value.HasValue) { - Dictionary[IssuedUtcKey] = value.Value.ToString(UtcDateTimeFormat, CultureInfo.InvariantCulture); + Items[IssuedUtcKey] = value.Value.ToString(UtcDateTimeFormat, CultureInfo.InvariantCulture); } else { - if (Dictionary.ContainsKey(IssuedUtcKey)) + if (Items.ContainsKey(IssuedUtcKey)) { - Dictionary.Remove(IssuedUtcKey); + Items.Remove(IssuedUtcKey); } } } @@ -136,7 +136,7 @@ public DateTimeOffset? ExpiresUtc get { string value; - if (Dictionary.TryGetValue(ExpiresUtcKey, out value)) + if (Items.TryGetValue(ExpiresUtcKey, out value)) { DateTimeOffset dateTimeOffset; if (DateTimeOffset.TryParseExact(value, UtcDateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dateTimeOffset)) @@ -150,13 +150,13 @@ public DateTimeOffset? ExpiresUtc { if (value.HasValue) { - Dictionary[ExpiresUtcKey] = value.Value.ToString(UtcDateTimeFormat, CultureInfo.InvariantCulture); + Items[ExpiresUtcKey] = value.Value.ToString(UtcDateTimeFormat, CultureInfo.InvariantCulture); } else { - if (Dictionary.ContainsKey(ExpiresUtcKey)) + if (Items.ContainsKey(ExpiresUtcKey)) { - Dictionary.Remove(ExpiresUtcKey); + Items.Remove(ExpiresUtcKey); } } } @@ -170,7 +170,7 @@ public bool? AllowRefresh get { string value; - if (Dictionary.TryGetValue(RefreshKey, out value)) + if (Items.TryGetValue(RefreshKey, out value)) { bool refresh; if (bool.TryParse(value, out refresh)) @@ -184,13 +184,13 @@ public bool? AllowRefresh { if (value.HasValue) { - Dictionary[RefreshKey] = value.Value.ToString(); + Items[RefreshKey] = value.Value.ToString(); } else { - if (Dictionary.ContainsKey(RefreshKey)) + if (Items.ContainsKey(RefreshKey)) { - Dictionary.Remove(RefreshKey); + Items.Remove(RefreshKey); } } } diff --git a/src/Microsoft.AspNet.Http.Core/HttpContext.cs b/src/Microsoft.AspNet.Http.Core/HttpContext.cs index 47f595df..14646bf0 100644 --- a/src/Microsoft.AspNet.Http.Core/HttpContext.cs +++ b/src/Microsoft.AspNet.Http.Core/HttpContext.cs @@ -3,11 +3,8 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Net.WebSockets; using System.Security.Claims; using System.Threading; -using System.Threading.Tasks; using Microsoft.AspNet.Http.Authentication; namespace Microsoft.AspNet.Http @@ -20,6 +17,8 @@ public abstract class HttpContext : IDisposable public abstract ConnectionInfo Connection { get; } + public abstract AuthenticationManager Authentication { get; } + public abstract ClaimsPrincipal User { get; set; } public abstract IDictionary Items { get; } @@ -32,9 +31,7 @@ public abstract class HttpContext : IDisposable public abstract ISessionCollection Session { get; } - public abstract bool IsWebSocketRequest { get; } - - public abstract IList WebSocketRequestedProtocols { get; } + public abstract WebSocketManager WebSockets { get; } public abstract void Abort(); @@ -53,18 +50,5 @@ public virtual void SetFeature(T instance) { SetFeature(typeof(T), instance); } - - public abstract IEnumerable GetAuthenticationSchemes(); - - public abstract AuthenticationResult Authenticate(string authenticationScheme); - - public abstract Task AuthenticateAsync(string authenticationScheme); - - public virtual Task AcceptWebSocketAsync() - { - return AcceptWebSocketAsync(subProtocol: null); - } - - public abstract Task AcceptWebSocketAsync(string subProtocol); } } diff --git a/src/Microsoft.AspNet.Http.Core/HttpRequest.cs b/src/Microsoft.AspNet.Http.Core/HttpRequest.cs index 7465c306..5252c864 100644 --- a/src/Microsoft.AspNet.Http.Core/HttpRequest.cs +++ b/src/Microsoft.AspNet.Http.Core/HttpRequest.cs @@ -1,9 +1,6 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Collections; -using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -12,8 +9,6 @@ namespace Microsoft.AspNet.Http { public abstract class HttpRequest { - // TODO - review IOwinRequest for properties - public abstract HttpContext HttpContext { get; } /// diff --git a/src/Microsoft.AspNet.Http.Core/HttpResponse.cs b/src/Microsoft.AspNet.Http.Core/HttpResponse.cs index 97c0a63e..4721f9a4 100644 --- a/src/Microsoft.AspNet.Http.Core/HttpResponse.cs +++ b/src/Microsoft.AspNet.Http.Core/HttpResponse.cs @@ -2,23 +2,22 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.IO; -using System.Security.Claims; -using Microsoft.AspNet.Http.Authentication; namespace Microsoft.AspNet.Http { public abstract class HttpResponse { - // TODO - review IOwinResponse for completeness - public abstract HttpContext HttpContext { get; } + public abstract int StatusCode { get; set; } + public abstract IHeaderDictionary Headers { get; } + public abstract Stream Body { get; set; } public abstract long? ContentLength { get; set; } + public abstract string ContentType { get; set; } public abstract IResponseCookies Cookies { get; } @@ -35,33 +34,5 @@ public virtual void Redirect(string location) } public abstract void Redirect(string location, bool permanent); - - public virtual void Challenge() - { - Challenge(properties: null, authenticationScheme: null); - } - - public virtual void Challenge(AuthenticationProperties properties) - { - Challenge(properties, ""); - } - - public virtual void Challenge(string authenticationScheme) - { - Challenge(properties: null, authenticationScheme: authenticationScheme); - } - - public abstract void Challenge(AuthenticationProperties properties, string authenticationScheme); - - public abstract void SignIn(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties = null); - - public virtual void SignOut() - { - SignOut(authenticationScheme: null, properties: null); - } - - public abstract void SignOut(string authenticationScheme); - - public abstract void SignOut(string authenticationScheme, AuthenticationProperties properties); } } diff --git a/src/Microsoft.AspNet.Http.Core/WebSocketManager.cs b/src/Microsoft.AspNet.Http.Core/WebSocketManager.cs new file mode 100644 index 00000000..cf7fd11f --- /dev/null +++ b/src/Microsoft.AspNet.Http.Core/WebSocketManager.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Net.WebSockets; +using System.Threading.Tasks; + +namespace Microsoft.AspNet.Http +{ + public abstract class WebSocketManager + { + public abstract bool IsWebSocketRequest { get; } + + public abstract IList WebSocketRequestedProtocols { get; } + + public virtual Task AcceptWebSocketAsync() + { + return AcceptWebSocketAsync(subProtocol: null); + } + + public abstract Task AcceptWebSocketAsync(string subProtocol); + } +} diff --git a/src/Microsoft.AspNet.Http.Interfaces/Authentication/AuthenticateContext.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/AuthenticateContext.cs new file mode 100644 index 00000000..e76a501d --- /dev/null +++ b/src/Microsoft.AspNet.Http.Interfaces/Authentication/AuthenticateContext.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Security.Claims; +using Microsoft.Framework.Internal; + +namespace Microsoft.AspNet.Http.Authentication +{ + public class AuthenticateContext + { + public AuthenticateContext([NotNull] string authenticationScheme) + { + AuthenticationScheme = authenticationScheme; + } + + public string AuthenticationScheme { get; } + + public bool Accepted { get; private set; } + + public ClaimsPrincipal Principal { get; private set; } + + public IDictionary Properties { get; private set; } + + public IDictionary Description { get; private set; } + + public virtual void Authenticated(ClaimsPrincipal principal, IDictionary properties, IDictionary description) + { + Accepted = true; + Principal = principal; + Properties = properties; + Description = description; + } + + public virtual void NotAuthenticated() + { + Accepted = true; + } + } +} diff --git a/src/Microsoft.AspNet.Http/Authentication/ChallengeContext.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/ChallengeContext.cs similarity index 54% rename from src/Microsoft.AspNet.Http/Authentication/ChallengeContext.cs rename to src/Microsoft.AspNet.Http.Interfaces/Authentication/ChallengeContext.cs index 0a137bb6..e1b6bf8c 100644 --- a/src/Microsoft.AspNet.Http/Authentication/ChallengeContext.cs +++ b/src/Microsoft.AspNet.Http.Interfaces/Authentication/ChallengeContext.cs @@ -3,35 +3,26 @@ using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Authentication { - public class ChallengeContext : IChallengeContext + public class ChallengeContext { - private bool _accepted; - public ChallengeContext(string authenticationScheme, IDictionary properties) { AuthenticationScheme = authenticationScheme; Properties = properties ?? new Dictionary(StringComparer.Ordinal); - - // The default Challenge with no scheme is always accepted - _accepted = string.IsNullOrEmpty(authenticationScheme); } - public string AuthenticationScheme { get; private set; } + public string AuthenticationScheme { get; } - public IDictionary Properties { get; private set; } + public IDictionary Properties { get; } - public bool Accepted - { - get { return _accepted; } - } + public bool Accepted { get; private set; } public void Accept() { - _accepted = true; + Accepted = true; } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http/Authentication/DescribeSchemesContext.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/DescribeSchemesContext.cs similarity index 60% rename from src/Microsoft.AspNet.Http/Authentication/DescribeSchemesContext.cs rename to src/Microsoft.AspNet.Http.Interfaces/Authentication/DescribeSchemesContext.cs index 6e490794..38daa0a8 100644 --- a/src/Microsoft.AspNet.Http/Authentication/DescribeSchemesContext.cs +++ b/src/Microsoft.AspNet.Http.Interfaces/Authentication/DescribeSchemesContext.cs @@ -5,23 +5,23 @@ namespace Microsoft.AspNet.Http.Authentication { - public class DescribeSchemesContext : IDescribeSchemesContext + public class DescribeSchemesContext { - private List _results; + private List> _results; public DescribeSchemesContext() { - _results = new List(); + _results = new List>(); } - public IEnumerable Results + public IEnumerable> Results { get { return _results; } } public void Accept(IDictionary description) { - _results.Add(new AuthenticationDescription(description)); + _results.Add(description); } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http.Interfaces/Authentication/IAuthenticateContext.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/IAuthenticateContext.cs deleted file mode 100644 index ecf8b567..00000000 --- a/src/Microsoft.AspNet.Http.Interfaces/Authentication/IAuthenticateContext.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Security.Claims; - -namespace Microsoft.AspNet.Http.Authentication -{ - public interface IAuthenticateContext - { - string AuthenticationScheme { get; } - - void Authenticated(ClaimsPrincipal principal, IDictionary properties, IDictionary description); - - void NotAuthenticated(); - } -} diff --git a/src/Microsoft.AspNet.Http.Interfaces/Authentication/IAuthenticationHandler.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/IAuthenticationHandler.cs index 76b3e8cb..04a7039a 100644 --- a/src/Microsoft.AspNet.Http.Interfaces/Authentication/IAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Http.Interfaces/Authentication/IAuthenticationHandler.cs @@ -7,13 +7,16 @@ namespace Microsoft.AspNet.Http.Authentication { public interface IAuthenticationHandler { - void GetDescriptions(IDescribeSchemesContext context); + void GetDescriptions(DescribeSchemesContext context); - void Authenticate(IAuthenticateContext context); - Task AuthenticateAsync(IAuthenticateContext context); + void Authenticate(AuthenticateContext context); - void Challenge(IChallengeContext context); - void SignIn(ISignInContext context); - void SignOut(ISignOutContext context); + Task AuthenticateAsync(AuthenticateContext context); + + void Challenge(ChallengeContext context); + + void SignIn(SignInContext context); + + void SignOut(SignOutContext context); } } diff --git a/src/Microsoft.AspNet.Http.Interfaces/Authentication/IChallengeContext.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/IChallengeContext.cs deleted file mode 100644 index 26a90fef..00000000 --- a/src/Microsoft.AspNet.Http.Interfaces/Authentication/IChallengeContext.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; - -namespace Microsoft.AspNet.Http.Authentication -{ - public interface IChallengeContext - { - string AuthenticationScheme { get; } - IDictionary Properties { get; } - - void Accept(); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http.Interfaces/Authentication/IDescribeSchemesContext.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/IDescribeSchemesContext.cs deleted file mode 100644 index 96f395cb..00000000 --- a/src/Microsoft.AspNet.Http.Interfaces/Authentication/IDescribeSchemesContext.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; - -namespace Microsoft.AspNet.Http.Authentication -{ - public interface IDescribeSchemesContext - { - void Accept(IDictionary description); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http.Interfaces/Authentication/ISignInContext.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/ISignInContext.cs deleted file mode 100644 index c7986027..00000000 --- a/src/Microsoft.AspNet.Http.Interfaces/Authentication/ISignInContext.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Security.Claims; - -namespace Microsoft.AspNet.Http.Authentication -{ - public interface ISignInContext - { - //IEnumerable Principals { get; } - ClaimsPrincipal Principal { get; } - IDictionary Properties { get; } - string AuthenticationScheme { get; } - - void Accept(IDictionary description); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http.Interfaces/Authentication/ISignOutContext.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/ISignOutContext.cs deleted file mode 100644 index 2bb70360..00000000 --- a/src/Microsoft.AspNet.Http.Interfaces/Authentication/ISignOutContext.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; - -namespace Microsoft.AspNet.Http.Authentication -{ - public interface ISignOutContext - { - string AuthenticationScheme { get; } - - IDictionary Properties { get; } - - void Accept(); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http/Authentication/SignInContext.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/SignInContext.cs similarity index 70% rename from src/Microsoft.AspNet.Http/Authentication/SignInContext.cs rename to src/Microsoft.AspNet.Http.Interfaces/Authentication/SignInContext.cs index 1a77db41..d5d74c31 100644 --- a/src/Microsoft.AspNet.Http/Authentication/SignInContext.cs +++ b/src/Microsoft.AspNet.Http.Interfaces/Authentication/SignInContext.cs @@ -8,31 +8,26 @@ namespace Microsoft.AspNet.Http.Authentication { - public class SignInContext : ISignInContext + public class SignInContext { - private bool _accepted; - - public SignInContext([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal, IDictionary dictionary) + public SignInContext([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal, IDictionary properties) { AuthenticationScheme = authenticationScheme; Principal = principal; - Properties = dictionary ?? new Dictionary(StringComparer.Ordinal); + Properties = properties ?? new Dictionary(StringComparer.Ordinal); } + public string AuthenticationScheme { get; } + public ClaimsPrincipal Principal { get; } public IDictionary Properties { get; } - public string AuthenticationScheme { get; } - - public bool Accepted - { - get { return _accepted; } - } + public bool Accepted { get; private set; } - public void Accept(IDictionary description) + public void Accept() { - _accepted = true; + Accepted = true; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http/Authentication/SignOutContext.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/SignOutContext.cs similarity index 79% rename from src/Microsoft.AspNet.Http/Authentication/SignOutContext.cs rename to src/Microsoft.AspNet.Http.Interfaces/Authentication/SignOutContext.cs index d7882098..27a7d294 100644 --- a/src/Microsoft.AspNet.Http/Authentication/SignOutContext.cs +++ b/src/Microsoft.AspNet.Http.Interfaces/Authentication/SignOutContext.cs @@ -7,10 +7,8 @@ namespace Microsoft.AspNet.Http.Authentication { - public class SignOutContext : ISignOutContext + public class SignOutContext { - private bool _accepted; - public SignOutContext([NotNull] string authenticationScheme, IDictionary properties) { AuthenticationScheme = authenticationScheme; @@ -21,14 +19,11 @@ public SignOutContext([NotNull] string authenticationScheme, IDictionary Properties { get; } - public bool Accepted - { - get { return _accepted; } - } + public bool Accepted { get; private set; } public void Accept() { - _accepted = true; + Accepted = true; } } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http.Interfaces/IHttpWebSocketFeature.cs b/src/Microsoft.AspNet.Http.Interfaces/IHttpWebSocketFeature.cs index 3e860581..eb64b4be 100644 --- a/src/Microsoft.AspNet.Http.Interfaces/IHttpWebSocketFeature.cs +++ b/src/Microsoft.AspNet.Http.Interfaces/IHttpWebSocketFeature.cs @@ -10,6 +10,6 @@ public interface IHttpWebSocketFeature { bool IsWebSocketRequest { get; } - Task AcceptAsync(IWebSocketAcceptContext context); + Task AcceptAsync(WebSocketAcceptContext context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http.Interfaces/IWebSocketAcceptContext.cs b/src/Microsoft.AspNet.Http.Interfaces/IWebSocketAcceptContext.cs deleted file mode 100644 index 81f041bb..00000000 --- a/src/Microsoft.AspNet.Http.Interfaces/IWebSocketAcceptContext.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNet.Http -{ - public interface IWebSocketAcceptContext - { - string SubProtocol { get; set; } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http/WebSocketAcceptContext.cs b/src/Microsoft.AspNet.Http.Interfaces/WebSocketAcceptContext.cs similarity index 81% rename from src/Microsoft.AspNet.Http/WebSocketAcceptContext.cs rename to src/Microsoft.AspNet.Http.Interfaces/WebSocketAcceptContext.cs index 34747f90..210ec0c2 100644 --- a/src/Microsoft.AspNet.Http/WebSocketAcceptContext.cs +++ b/src/Microsoft.AspNet.Http.Interfaces/WebSocketAcceptContext.cs @@ -3,7 +3,7 @@ namespace Microsoft.AspNet.Http { - public class WebSocketAcceptContext : IWebSocketAcceptContext + public class WebSocketAcceptContext { public virtual string SubProtocol { get; set; } } diff --git a/src/Microsoft.AspNet.Http.Interfaces/project.json b/src/Microsoft.AspNet.Http.Interfaces/project.json index 3af7b3bd..d4d11392 100644 --- a/src/Microsoft.AspNet.Http.Interfaces/project.json +++ b/src/Microsoft.AspNet.Http.Interfaces/project.json @@ -1,16 +1,21 @@ { - "version": "1.0.0-*", - "description": "ASP.NET 5 HTTP feature interface definitions.", - "frameworks": { - "dnx451": {}, - "dnxcore50": { - "dependencies": { - "System.Net.Primitives": "4.0.10-beta-*", - "System.Net.WebSockets" : "4.0.0-beta-*", - "System.Security.Claims": "4.0.0-beta-*", - "System.Security.Cryptography.X509Certificates": "4.0.0-beta-*", - "System.Security.Principal": "4.0.0-beta-*" - } + "version": "1.0.0-*", + "description": "ASP.NET 5 HTTP feature interface definitions.", + "dependencies": { + "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } + }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { + "dependencies": { + "System.Collections": "4.0.10-beta-*", + "System.Net.Primitives": "4.0.10-beta-*", + "System.Net.WebSockets": "4.0.0-beta-*", + "System.Runtime.Extensions": "4.0.10-beta-*", + "System.Security.Claims": "4.0.0-beta-*", + "System.Security.Cryptography.X509Certificates": "4.0.0-beta-*", + "System.Security.Principal": "4.0.0-beta-*" + } + } } - } } diff --git a/src/Microsoft.AspNet.Http/Authentication/AuthenticateContext.cs b/src/Microsoft.AspNet.Http/Authentication/AuthenticateContext.cs deleted file mode 100644 index 91d530df..00000000 --- a/src/Microsoft.AspNet.Http/Authentication/AuthenticateContext.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Security.Claims; -using Microsoft.Framework.Internal; - -namespace Microsoft.AspNet.Http.Authentication -{ - public class AuthenticateContext : IAuthenticateContext - { - private AuthenticationResult _result; - private bool _accepted; - - public AuthenticateContext([NotNull] string authenticationScheme) - { - AuthenticationScheme = authenticationScheme; - } - - public string AuthenticationScheme { get; private set; } - - public AuthenticationResult Result { get; set; } - - public bool Accepted - { - get { return _accepted; } - } - - public void Authenticated(ClaimsPrincipal principal, IDictionary properties, IDictionary description) - { - var descrip = new AuthenticationDescription(description); - _accepted = true; - Result = new AuthenticationResult(principal, new AuthenticationProperties(properties), descrip); - } - - public void NotAuthenticated() - { - _accepted = true; - } - } -} diff --git a/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs b/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs new file mode 100644 index 00000000..f4d086b6 --- /dev/null +++ b/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs @@ -0,0 +1,157 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.Http.Infrastructure; +using Microsoft.Framework.Internal; + +namespace Microsoft.AspNet.Http.Authentication +{ + public class DefaultAuthenticationManager : AuthenticationManager + { + private readonly IFeatureCollection _features; + private FeatureReference _authentication = FeatureReference.Default; + private FeatureReference _response = FeatureReference.Default; + + public DefaultAuthenticationManager(IFeatureCollection features) + { + _features = features; + } + + private IHttpAuthenticationFeature HttpAuthenticationFeature + { + get { return _authentication.Fetch(_features) ?? _authentication.Update(_features, new HttpAuthenticationFeature()); } + } + + private IHttpResponseFeature HttpResponseFeature + { + get { return _response.Fetch(_features); } + } + + public override IEnumerable GetAuthenticationSchemes() + { + var handler = HttpAuthenticationFeature.Handler; + if (handler == null) + { + return new AuthenticationDescription[0]; + } + + var describeContext = new DescribeSchemesContext(); + handler.GetDescriptions(describeContext); + return describeContext.Results.Select(description => new AuthenticationDescription(description)); + } + + public override AuthenticationResult Authenticate([NotNull] string authenticationScheme) + { + var handler = HttpAuthenticationFeature.Handler; + + var authenticateContext = new AuthenticateContext(authenticationScheme); + if (handler != null) + { + handler.Authenticate(authenticateContext); + } + + if (!authenticateContext.Accepted) + { + throw new InvalidOperationException($"The following authentication scheme was not accepted: {authenticationScheme}"); + } + + if (authenticateContext.Principal == null) + { + return null; + } + + return new AuthenticationResult(authenticateContext.Principal, + new AuthenticationProperties(authenticateContext.Properties), + new AuthenticationDescription(authenticateContext.Description)); + } + + public override async Task AuthenticateAsync([NotNull] string authenticationScheme) + { + var handler = HttpAuthenticationFeature.Handler; + + var authenticateContext = new AuthenticateContext(authenticationScheme); + if (handler != null) + { + await handler.AuthenticateAsync(authenticateContext); + } + + // Verify all types ack'd + if (!authenticateContext.Accepted) + { + throw new InvalidOperationException($"The following authentication scheme was not accepted: {authenticationScheme}"); + } + + if (authenticateContext.Principal == null) + { + return null; + } + + return new AuthenticationResult(authenticateContext.Principal, + new AuthenticationProperties(authenticateContext.Properties), + new AuthenticationDescription(authenticateContext.Description)); + } + + public override void Challenge(string authenticationScheme, AuthenticationProperties properties) + { + HttpResponseFeature.StatusCode = 401; + var handler = HttpAuthenticationFeature.Handler; + + var challengeContext = new ChallengeContext(authenticationScheme, properties?.Items); + if (handler != null) + { + handler.Challenge(challengeContext); + } + + // The default Challenge with no scheme is always accepted + if (!challengeContext.Accepted && !string.IsNullOrEmpty(authenticationScheme)) + { + throw new InvalidOperationException($"The following authentication scheme was not accepted: {authenticationScheme}"); + } + } + + public override void SignIn([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal, AuthenticationProperties properties) + { + var handler = HttpAuthenticationFeature.Handler; + + var signInContext = new SignInContext(authenticationScheme, principal, properties?.Items); + if (handler != null) + { + handler.SignIn(signInContext); + } + + // Verify all types ack'd + if (!signInContext.Accepted) + { + throw new InvalidOperationException($"The following authentication scheme was not accepted: {authenticationScheme}"); + } + } + + public override void SignOut(string authenticationScheme, AuthenticationProperties properties) + { + var handler = HttpAuthenticationFeature.Handler; + + var signOutContext = new SignOutContext(authenticationScheme, properties?.Items); + if (handler != null) + { + handler.SignOut(signOutContext); + } + + // Verify all types ack'd + if (!string.IsNullOrWhiteSpace(authenticationScheme) && !signOutContext.Accepted) + { + throw new InvalidOperationException($"The following authentication scheme was not accepted: {authenticationScheme}"); + } + } + + public override void SignOut(string authenticationScheme) + { + SignOut(authenticationScheme, properties: null); + } + } +} diff --git a/src/Microsoft.AspNet.Http/DefaultHttpContext.cs b/src/Microsoft.AspNet.Http/DefaultHttpContext.cs index 81aef590..65365e98 100644 --- a/src/Microsoft.AspNet.Http/DefaultHttpContext.cs +++ b/src/Microsoft.AspNet.Http/DefaultHttpContext.cs @@ -3,33 +3,28 @@ using System; using System.Collections.Generic; -using System.Net.WebSockets; using System.Security.Claims; using System.Threading; -using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Http.Collections; using Microsoft.AspNet.Http.Infrastructure; -using Microsoft.Framework.Internal; -using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Http { public class DefaultHttpContext : HttpContext { - private static IList EmptyList = new List(); - private readonly HttpRequest _request; private readonly HttpResponse _response; private readonly ConnectionInfo _connection; + private readonly AuthenticationManager _authenticationManager; private FeatureReference _items; private FeatureReference _serviceProviders; private FeatureReference _authentication; private FeatureReference _lifetime; - private FeatureReference _webSockets; private FeatureReference _session; + private WebSocketManager _websockets; private IFeatureCollection _features; public DefaultHttpContext() @@ -45,12 +40,12 @@ public DefaultHttpContext(IFeatureCollection features) _request = new DefaultHttpRequest(this, features); _response = new DefaultHttpResponse(this, features); _connection = new DefaultConnectionInfo(features); + _authenticationManager = new DefaultAuthenticationManager(features); _items = FeatureReference.Default; _serviceProviders = FeatureReference.Default; _authentication = FeatureReference.Default; _lifetime = FeatureReference.Default; - _webSockets = FeatureReference.Default; _session = FeatureReference.Default; } @@ -74,11 +69,6 @@ private IHttpRequestLifetimeFeature LifetimeFeature get { return _lifetime.Fetch(_features); } } - private IHttpWebSocketFeature WebSocketFeature - { - get { return _webSockets.Fetch(_features); } - } - private ISessionFeature SessionFeature { get { return _session.Fetch(_features); } @@ -90,6 +80,8 @@ private ISessionFeature SessionFeature public override ConnectionInfo Connection { get { return _connection; } } + public override AuthenticationManager Authentication { get { return _authenticationManager; } } + public override ClaimsPrincipal User { get @@ -158,20 +150,15 @@ public override ISessionCollection Session } } - public override bool IsWebSocketRequest - { - get - { - var webSocketFeature = WebSocketFeature; - return webSocketFeature != null && webSocketFeature.IsWebSocketRequest; - } - } - - public override IList WebSocketRequestedProtocols + public override WebSocketManager WebSockets { get { - return Request.Headers.GetValues(HeaderNames.WebSocketSubProtocols) ?? EmptyList; + if (_websockets == null) + { + _websockets = new DefaultWebSocketManager(_features); + } + return _websockets; } } @@ -200,65 +187,5 @@ public override void SetFeature(Type type, object instance) { _features[type] = instance; } - - public override IEnumerable GetAuthenticationSchemes() - { - var handler = HttpAuthenticationFeature.Handler; - if (handler == null) - { - return new AuthenticationDescription[0]; - } - - var describeContext = new DescribeSchemesContext(); - handler.GetDescriptions(describeContext); - return describeContext.Results; - } - - public override AuthenticationResult Authenticate([NotNull] string authenticationScheme) - { - var handler = HttpAuthenticationFeature.Handler; - - var authenticateContext = new AuthenticateContext(authenticationScheme); - if (handler != null) - { - handler.Authenticate(authenticateContext); - } - - if (!authenticateContext.Accepted) - { - throw new InvalidOperationException("The following authentication scheme was not accepted: " + authenticationScheme); - } - - return authenticateContext.Result; - } - - public override async Task AuthenticateAsync([NotNull] string authenticationScheme) - { - var handler = HttpAuthenticationFeature.Handler; - - var authenticateContext = new AuthenticateContext(authenticationScheme); - if (handler != null) - { - await handler.AuthenticateAsync(authenticateContext); - } - - // Verify all types ack'd - if (!authenticateContext.Accepted) - { - throw new InvalidOperationException("The following authentication scheme was not accepted: " + authenticationScheme); - } - - return authenticateContext.Result; - } - - public override Task AcceptWebSocketAsync(string subProtocol) - { - var webSocketFeature = WebSocketFeature; - if (WebSocketFeature == null) - { - throw new NotSupportedException("WebSockets are not supported"); - } - return WebSocketFeature.AcceptAsync(new WebSocketAcceptContext() { SubProtocol = subProtocol } ); - } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http/DefaultHttpResponse.cs b/src/Microsoft.AspNet.Http/DefaultHttpResponse.cs index a5a3e9a4..026ce3b2 100644 --- a/src/Microsoft.AspNet.Http/DefaultHttpResponse.cs +++ b/src/Microsoft.AspNet.Http/DefaultHttpResponse.cs @@ -2,15 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Security.Claims; using Microsoft.AspNet.FeatureModel; -using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Http.Collections; using Microsoft.AspNet.Http.Infrastructure; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Http @@ -21,7 +16,6 @@ public class DefaultHttpResponse : HttpResponse private readonly IFeatureCollection _features; private FeatureReference _response = FeatureReference.Default; private FeatureReference _cookies = FeatureReference.Default; - private FeatureReference _authentication = FeatureReference.Default; public DefaultHttpResponse(DefaultHttpContext context, IFeatureCollection features) { @@ -39,11 +33,6 @@ private IResponseCookiesFeature ResponseCookiesFeature get { return _cookies.Fetch(_features) ?? _cookies.Update(_features, new ResponseCookiesFeature(_features)); } } - private IHttpAuthenticationFeature HttpAuthenticationFeature - { - get { return _authentication.Fetch(_features) ?? _authentication.Update(_features, new HttpAuthenticationFeature()); } - } - public override HttpContext HttpContext { get { return _context; } } public override int StatusCode @@ -128,61 +117,5 @@ public override void Redirect(string location, bool permanent) Headers.Set(HeaderNames.Location, location); } - - public override void Challenge(AuthenticationProperties properties, string authenticationScheme) - { - HttpResponseFeature.StatusCode = 401; - var handler = HttpAuthenticationFeature.Handler; - - var challengeContext = new ChallengeContext(authenticationScheme, properties == null ? null : properties.Dictionary); - if (handler != null) - { - handler.Challenge(challengeContext); - } - - if (!challengeContext.Accepted) - { - throw new InvalidOperationException("The following authentication type was not accepted: " + authenticationScheme); - } - } - - public override void SignIn(string authenticationScheme, [NotNull] ClaimsPrincipal principal, AuthenticationProperties properties) - { - var handler = HttpAuthenticationFeature.Handler; - - var signInContext = new SignInContext(authenticationScheme, principal, properties == null ? null : properties.Dictionary); - if (handler != null) - { - handler.SignIn(signInContext); - } - - // Verify all types ack'd - if (!signInContext.Accepted) - { - throw new InvalidOperationException("The following authentication scheme was not accepted: " + authenticationScheme); - } - } - - public override void SignOut(string authenticationScheme, AuthenticationProperties properties) - { - var handler = HttpAuthenticationFeature.Handler; - - var signOutContext = new SignOutContext(authenticationScheme, properties?.Dictionary); - if (handler != null) - { - handler.SignOut(signOutContext); - } - - // Verify all types ack'd - if (!string.IsNullOrWhiteSpace(authenticationScheme) && !signOutContext.Accepted) - { - throw new InvalidOperationException("The following authentication scheme was not accepted: " + authenticationScheme); - } - } - - public override void SignOut(string authenticationScheme) - { - SignOut(authenticationScheme, properties: null); - } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http/DefaultWebSocketManager.cs b/src/Microsoft.AspNet.Http/DefaultWebSocketManager.cs new file mode 100644 index 00000000..c1845c66 --- /dev/null +++ b/src/Microsoft.AspNet.Http/DefaultWebSocketManager.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Net.WebSockets; +using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.Http.Infrastructure; +using Microsoft.Net.Http.Headers; + +namespace Microsoft.AspNet.Http +{ + public class DefaultWebSocketManager : WebSocketManager + { + private static IList EmptyList = new List(); + + private IFeatureCollection _features; + private FeatureReference _request = FeatureReference.Default; + private FeatureReference _webSockets = FeatureReference.Default; + + public DefaultWebSocketManager(IFeatureCollection features) + { + _features = features; + } + + private IHttpRequestFeature HttpRequestFeature + { + get { return _request.Fetch(_features); } + } + + private IHttpWebSocketFeature WebSocketFeature + { + get { return _webSockets.Fetch(_features); } + } + + public override bool IsWebSocketRequest + { + get + { + return WebSocketFeature != null && WebSocketFeature.IsWebSocketRequest; + } + } + + public override IList WebSocketRequestedProtocols + { + get + { + return ParsingHelpers.GetHeaderUnmodified(HttpRequestFeature.Headers, + HeaderNames.WebSocketSubProtocols) ?? EmptyList; + } + } + + public override Task AcceptWebSocketAsync(string subProtocol) + { + if (WebSocketFeature == null) + { + throw new NotSupportedException("WebSockets are not supported"); + } + return WebSocketFeature.AcceptAsync(new WebSocketAcceptContext() { SubProtocol = subProtocol }); + } + } +} diff --git a/src/Microsoft.AspNet.Owin/OwinEnvironment.cs b/src/Microsoft.AspNet.Owin/OwinEnvironment.cs index 75b1c880..9dfae8a8 100644 --- a/src/Microsoft.AspNet.Owin/OwinEnvironment.cs +++ b/src/Microsoft.AspNet.Owin/OwinEnvironment.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Owin using WebSocketAcceptAlt = Func < - IWebSocketAcceptContext, // WebSocket Accept parameters + WebSocketAcceptContext, // WebSocket Accept parameters Task >; @@ -105,7 +105,7 @@ public OwinEnvironment(HttpContext context) feature => new Func(() => feature.GetClientCertificateAsync(CancellationToken.None)))); } - if (context.IsWebSocketRequest) + if (context.WebSockets.IsWebSocketRequest) { _entries.Add(OwinConstants.WebSocket.AcceptAlt, new FeatureMap(feature => new WebSocketAcceptAlt(feature.AcceptAsync))); } diff --git a/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs b/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs index 50d58adb..195fb04c 100644 --- a/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs +++ b/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs @@ -277,14 +277,14 @@ bool IHttpWebSocketFeature.IsWebSocketRequest } } - Task IHttpWebSocketFeature.AcceptAsync(IWebSocketAcceptContext context) + Task IHttpWebSocketFeature.AcceptAsync(WebSocketAcceptContext context) { object obj; if (!Environment.TryGetValue(OwinConstants.WebSocket.AcceptAlt, out obj)) { throw new NotSupportedException("WebSockets are not supported"); // TODO: LOC } - var accept = (Func>)obj; + var accept = (Func>)obj; return accept(context); } diff --git a/src/Microsoft.AspNet.Owin/WebSockets/OwinWebSocketAcceptAdapter.cs b/src/Microsoft.AspNet.Owin/WebSockets/OwinWebSocketAcceptAdapter.cs index 07b58bc2..50448cd5 100644 --- a/src/Microsoft.AspNet.Owin/WebSockets/OwinWebSocketAcceptAdapter.cs +++ b/src/Microsoft.AspNet.Owin/WebSockets/OwinWebSocketAcceptAdapter.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Owin using WebSocketAcceptAlt = Func < - IWebSocketAcceptContext, // WebSocket Accept parameters + WebSocketAcceptContext, // WebSocket Accept parameters Task >; @@ -48,7 +48,7 @@ private OwinWebSocketAcceptAdapter(WebSocketAccept owinWebSocketAccept) private Task UpstreamTask { get; set; } private TaskCompletionSource UpstreamWentAsyncTcs { get { return _upstreamWentAsync; } } - private async Task AcceptWebSocketAsync(IWebSocketAcceptContext context) + private async Task AcceptWebSocketAsync(WebSocketAcceptContext context) { IDictionary options = null; if (context is OwinWebSocketAcceptContext) diff --git a/src/Microsoft.AspNet.Owin/WebSockets/OwinWebSocketAcceptContext.cs b/src/Microsoft.AspNet.Owin/WebSockets/OwinWebSocketAcceptContext.cs index 56bc445f..45cacf76 100644 --- a/src/Microsoft.AspNet.Owin/WebSockets/OwinWebSocketAcceptContext.cs +++ b/src/Microsoft.AspNet.Owin/WebSockets/OwinWebSocketAcceptContext.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNet.Owin { - public class OwinWebSocketAcceptContext : IWebSocketAcceptContext + public class OwinWebSocketAcceptContext : WebSocketAcceptContext { private IDictionary _options; @@ -19,7 +19,7 @@ public OwinWebSocketAcceptContext(IDictionary options) _options = options; } - public string SubProtocol + public override string SubProtocol { get { diff --git a/src/Microsoft.AspNet.Owin/WebSockets/WebSocketAcceptAdapter.cs b/src/Microsoft.AspNet.Owin/WebSockets/WebSocketAcceptAdapter.cs index 8a7d7aa0..71efc549 100644 --- a/src/Microsoft.AspNet.Owin/WebSockets/WebSocketAcceptAdapter.cs +++ b/src/Microsoft.AspNet.Owin/WebSockets/WebSocketAcceptAdapter.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Owin using WebSocketAcceptAlt = Func < - IWebSocketAcceptContext, // WebSocket Accept parameters + WebSocketAcceptContext, // WebSocket Accept parameters Task >; @@ -65,11 +65,11 @@ public static AppFunc AdaptWebSockets(AppFunc next) await next(environment); if ((int)environment[OwinConstants.ResponseStatusCode] == 101 && adapter._callback != null) { - IWebSocketAcceptContext acceptContext = null; + WebSocketAcceptContext acceptContext = null; object obj; - if (adapter._options != null && adapter._options.TryGetValue(typeof(IWebSocketAcceptContext).FullName, out obj)) + if (adapter._options != null && adapter._options.TryGetValue(typeof(WebSocketAcceptContext).FullName, out obj)) { - acceptContext = obj as IWebSocketAcceptContext; + acceptContext = obj as WebSocketAcceptContext; } else if (adapter._options != null) { diff --git a/test/Microsoft.AspNet.Http.Tests/DefaultHttpContextTests.cs b/test/Microsoft.AspNet.Http.Tests/DefaultHttpContextTests.cs index d46ff5d6..ea887b71 100644 --- a/test/Microsoft.AspNet.Http.Tests/DefaultHttpContextTests.cs +++ b/test/Microsoft.AspNet.Http.Tests/DefaultHttpContextTests.cs @@ -46,34 +46,34 @@ public void EmptyUserIsNeverNull() public async Task AuthenticateWithNoAuthMiddlewareThrows() { var context = CreateContext(); - Assert.Throws(() => context.Authenticate("Foo")); - await Assert.ThrowsAsync(async () => await context.AuthenticateAsync("Foo")); + Assert.Throws(() => context.Authentication.Authenticate("Foo")); + await Assert.ThrowsAsync(async () => await context.Authentication.AuthenticateAsync("Foo")); } [Fact] public void ChallengeWithNoAuthMiddlewareMayThrow() { var context = CreateContext(); - context.Response.Challenge(); + context.Authentication.Challenge(); Assert.Equal(401, context.Response.StatusCode); - Assert.Throws(() => context.Response.Challenge("Foo")); + Assert.Throws(() => context.Authentication.Challenge("Foo")); } [Fact] public void SignInWithNoAuthMiddlewareThrows() { var context = CreateContext(); - Assert.Throws(() => context.Response.SignIn("Foo", new ClaimsPrincipal())); + Assert.Throws(() => context.Authentication.SignIn("Foo", new ClaimsPrincipal())); } [Fact] public void SignOutWithNoAuthMiddlewareMayThrow() { var context = CreateContext(); - context.Response.SignOut(); + context.Authentication.SignOut(); - Assert.Throws(() => context.Response.SignOut("Foo")); + Assert.Throws(() => context.Authentication.SignOut("Foo")); } [Fact] @@ -83,13 +83,13 @@ public void SignInOutIn() var handler = new AuthHandler(); context.SetFeature(new HttpAuthenticationFeature() { Handler = handler }); var user = new ClaimsPrincipal(); - context.Response.SignIn("ignored", user); + context.Authentication.SignIn("ignored", user); Assert.True(handler.SignedIn); - context.Response.SignOut("ignored"); + context.Authentication.SignOut("ignored"); Assert.False(handler.SignedIn); - context.Response.SignIn("ignored", user); + context.Authentication.SignIn("ignored", user); Assert.True(handler.SignedIn); - context.Response.SignOut("ignored", new AuthenticationProperties() { RedirectUri = "~/logout" }); + context.Authentication.SignOut("ignored", new AuthenticationProperties() { RedirectUri = "~/logout" }); Assert.False(handler.SignedIn); } @@ -97,33 +97,33 @@ private class AuthHandler : IAuthenticationHandler { public bool SignedIn { get; set; } - public void Authenticate(IAuthenticateContext context) + public void Authenticate(AuthenticateContext context) { throw new NotImplementedException(); } - public Task AuthenticateAsync(IAuthenticateContext context) + public Task AuthenticateAsync(AuthenticateContext context) { throw new NotImplementedException(); } - public void Challenge(IChallengeContext context) + public void Challenge(ChallengeContext context) { throw new NotImplementedException(); } - public void GetDescriptions(IDescribeSchemesContext context) + public void GetDescriptions(DescribeSchemesContext context) { throw new NotImplementedException(); } - public void SignIn(ISignInContext context) + public void SignIn(SignInContext context) { SignedIn = true; - context.Accept(new Dictionary()); + context.Accept(); } - public void SignOut(ISignOutContext context) + public void SignOut(SignOutContext context) { SignedIn = false; context.Accept();