Change GetAuthType to use a context object instead of a delegate.
This commit is contained in:
parent
c638c74bc9
commit
dfc0c5d323
|
|
@ -0,0 +1,9 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.HttpFeature.Security
|
||||||
|
{
|
||||||
|
public interface IAuthTypeContext
|
||||||
|
{
|
||||||
|
void Ack(IDictionary<string,object> description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,13 +3,11 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.HttpFeature.Security
|
namespace Microsoft.AspNet.HttpFeature.Security
|
||||||
{
|
{
|
||||||
public delegate void DescriptionDelegate(IDictionary<string, object> description, object state);
|
|
||||||
|
|
||||||
public interface IAuthenticationHandler
|
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);
|
Task AuthenticateAsync(IAuthenticateContext context);
|
||||||
|
|
||||||
void Challenge(IChallengeContext context);
|
void Challenge(IChallengeContext context);
|
||||||
|
|
|
||||||
|
|
@ -94,25 +94,17 @@ namespace Microsoft.AspNet.PipelineCore
|
||||||
_features[type] = instance;
|
_features[type] = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use context, not a delegate, like all the other APIs
|
|
||||||
private static DescriptionDelegate GetAuthenticationTypesDelegate = GetAuthenticationTypesCallback;
|
|
||||||
|
|
||||||
public override IEnumerable<AuthenticationDescription> GetAuthenticationTypes()
|
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;
|
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 authTypeContext = new AuthTypeContext();
|
||||||
{
|
handler.GetDescriptions(authTypeContext);
|
||||||
var localDescriptions = (List<AuthenticationDescription>)state;
|
return authTypeContext.Results;
|
||||||
localDescriptions.Add(new AuthenticationDescription(description));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<AuthenticationResult> Authenticate(IList<string> authenticationTypes)
|
public override IEnumerable<AuthenticationResult> Authenticate(IList<string> authenticationTypes)
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue