From 8b46d43dcba91b385a7e0393d858d114ee1e9622 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 16 Jul 2014 14:44:42 -0700 Subject: [PATCH] Make middleware report when auth fails (async). --- .../Infrastructure/AuthenticationHandler.cs | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler.cs b/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler.cs index 6c8da45c65..3526d1e5b9 100644 --- a/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler.cs @@ -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() { return LazyInitializer.EnsureInitialized( @@ -167,23 +188,6 @@ namespace Microsoft.AspNet.Security.Infrastructure 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); - } - } - /// /// 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