From dfc0c5d323d8a83397cded64ce00a9427846074f Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Tue, 1 Apr 2014 16:29:47 -0700 Subject: [PATCH] Change GetAuthType to use a context object instead of a delegate. --- .../Security/IAuthTypeContext.cs | 9 ++++++++ .../Security/IAuthenticationHandler.cs | 6 ++--- .../DefaultHttpContext.cs | 18 +++++---------- .../Security/AuthTypeContext.cs | 22 +++++++++++++++++++ 4 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 src/Microsoft.AspNet.HttpFeature/Security/IAuthTypeContext.cs create mode 100644 src/Microsoft.AspNet.PipelineCore/Security/AuthTypeContext.cs diff --git a/src/Microsoft.AspNet.HttpFeature/Security/IAuthTypeContext.cs b/src/Microsoft.AspNet.HttpFeature/Security/IAuthTypeContext.cs new file mode 100644 index 0000000000..634517ad6b --- /dev/null +++ b/src/Microsoft.AspNet.HttpFeature/Security/IAuthTypeContext.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Microsoft.AspNet.HttpFeature.Security +{ + public interface IAuthTypeContext + { + void Ack(IDictionary description); + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationHandler.cs b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationHandler.cs index 66c82fccfc..8a519b5de9 100644 --- a/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.HttpFeature/Security/IAuthenticationHandler.cs @@ -3,13 +3,11 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.HttpFeature.Security { - public delegate void DescriptionDelegate(IDictionary description, object state); - public interface IAuthenticationHandler { - void GetDescriptions(DescriptionDelegate callback, object state); + void GetDescriptions(IAuthTypeContext context); - void Authenticate(IAuthenticateContext context); // TODO: (maybe?) + void Authenticate(IAuthenticateContext context); Task AuthenticateAsync(IAuthenticateContext context); void Challenge(IChallengeContext context); diff --git a/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs b/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs index ba2d7688ff..1edb07771c 100644 --- a/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs +++ b/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs @@ -94,25 +94,17 @@ namespace Microsoft.AspNet.PipelineCore _features[type] = instance; } - // TODO: Use context, not a delegate, like all the other APIs - private static DescriptionDelegate GetAuthenticationTypesDelegate = GetAuthenticationTypesCallback; - public override IEnumerable GetAuthenticationTypes() { - // TODO: Use context, not a delegate, like all the other APIs - var descriptions = new List(); var handler = HttpAuthentication.Handler; - if (handler != null) + if (handler == null) { - handler.GetDescriptions(GetAuthenticationTypesDelegate, descriptions); + return new AuthenticationDescription[0]; } - return descriptions; - } - private static void GetAuthenticationTypesCallback(IDictionary description, object state) - { - var localDescriptions = (List)state; - localDescriptions.Add(new AuthenticationDescription(description)); + var authTypeContext = new AuthTypeContext(); + handler.GetDescriptions(authTypeContext); + return authTypeContext.Results; } public override IEnumerable Authenticate(IList authenticationTypes) diff --git a/src/Microsoft.AspNet.PipelineCore/Security/AuthTypeContext.cs b/src/Microsoft.AspNet.PipelineCore/Security/AuthTypeContext.cs new file mode 100644 index 0000000000..ccf8d40ed0 --- /dev/null +++ b/src/Microsoft.AspNet.PipelineCore/Security/AuthTypeContext.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNet.Abstractions.Security; +using Microsoft.AspNet.HttpFeature.Security; + +namespace Microsoft.AspNet.PipelineCore.Security +{ + public class AuthTypeContext : IAuthTypeContext + { + public AuthTypeContext() + { + Results = new List(); + } + + public IList Results { get; private set; } + + public void Ack(IDictionary description) + { + Results.Add(new AuthenticationDescription(description)); + } + } +}