Make middleware report when auth fails (async).
This commit is contained in:
parent
8307e9b1f3
commit
8b46d43dcb
|
|
@ -153,6 +153,27 @@ namespace Microsoft.AspNet.Security.Infrastructure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual async Task AuthenticateAsync(IAuthenticateContext context)
|
||||||
|
{
|
||||||
|
if (context.AuthenticationTypes.Contains(BaseOptions.AuthenticationType, StringComparer.Ordinal))
|
||||||
|
{
|
||||||
|
AuthenticationTicket ticket = await AuthenticateAsync();
|
||||||
|
if (ticket != null && ticket.Identity != null)
|
||||||
|
{
|
||||||
|
context.Authenticated(ticket.Identity, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.NotAuthenticated(BaseOptions.AuthenticationType, properties: null, description: BaseOptions.Description.Dictionary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PriorHandler != null)
|
||||||
|
{
|
||||||
|
await PriorHandler.AuthenticateAsync(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public AuthenticationTicket Authenticate()
|
public AuthenticationTicket Authenticate()
|
||||||
{
|
{
|
||||||
return LazyInitializer.EnsureInitialized(
|
return LazyInitializer.EnsureInitialized(
|
||||||
|
|
@ -167,23 +188,6 @@ namespace Microsoft.AspNet.Security.Infrastructure
|
||||||
|
|
||||||
protected abstract AuthenticationTicket AuthenticateCore();
|
protected abstract AuthenticationTicket AuthenticateCore();
|
||||||
|
|
||||||
public virtual async Task AuthenticateAsync(IAuthenticateContext context)
|
|
||||||
{
|
|
||||||
if (context.AuthenticationTypes.Contains(BaseOptions.AuthenticationType, StringComparer.Ordinal))
|
|
||||||
{
|
|
||||||
AuthenticationTicket ticket = await AuthenticateAsync();
|
|
||||||
if (ticket != null && ticket.Identity != null)
|
|
||||||
{
|
|
||||||
context.Authenticated(ticket.Identity, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PriorHandler != null)
|
|
||||||
{
|
|
||||||
await PriorHandler.AuthenticateAsync(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Causes the authentication logic in AuthenticateCore to be performed for the current request
|
/// Causes the authentication logic in AuthenticateCore to be performed for the current request
|
||||||
/// at most once and returns the results. Calling Authenticate more than once will always return
|
/// at most once and returns the results. Calling Authenticate more than once will always return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue