Change GetAuthType to use a context object instead of a delegate.

This commit is contained in:
Chris Ross 2014-04-01 16:29:47 -07:00
parent c638c74bc9
commit dfc0c5d323
4 changed files with 38 additions and 17 deletions

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace Microsoft.AspNet.HttpFeature.Security
{
public interface IAuthTypeContext
{
void Ack(IDictionary<string,object> description);
}
}

View File

@ -3,13 +3,11 @@ using System.Threading.Tasks;
namespace Microsoft.AspNet.HttpFeature.Security
{
public delegate void DescriptionDelegate(IDictionary<string, object> 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);

View File

@ -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<AuthenticationDescription> GetAuthenticationTypes()
{
// TODO: Use context, not a delegate, like all the other APIs
var descriptions = new List<AuthenticationDescription>();
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<string, object> description, object state)
{
var localDescriptions = (List<AuthenticationDescription>)state;
localDescriptions.Add(new AuthenticationDescription(description));
var authTypeContext = new AuthTypeContext();
handler.GetDescriptions(authTypeContext);
return authTypeContext.Results;
}
public override IEnumerable<AuthenticationResult> Authenticate(IList<string> authenticationTypes)

View File

@ -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<AuthenticationDescription>();
}
public IList<AuthenticationDescription> Results { get; private set; }
public void Ack(IDictionary<string, object> description)
{
Results.Add(new AuthenticationDescription(description));
}
}
}