Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 8b46d43

Browse files
committed
Make middleware report when auth fails (async).
1 parent 8307e9b commit 8b46d43

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/Microsoft.AspNet.Security/Infrastructure/AuthenticationHandler.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,6 @@ public virtual void Authenticate(IAuthenticateContext context)
153153
}
154154
}
155155

156-
public AuthenticationTicket Authenticate()
157-
{
158-
return LazyInitializer.EnsureInitialized(
159-
ref _authenticate,
160-
ref _authenticateInitialized,
161-
ref _authenticateSyncLock,
162-
() =>
163-
{
164-
return Task.FromResult(AuthenticateCore());
165-
}).Result;
166-
}
167-
168-
protected abstract AuthenticationTicket AuthenticateCore();
169-
170156
public virtual async Task AuthenticateAsync(IAuthenticateContext context)
171157
{
172158
if (context.AuthenticationTypes.Contains(BaseOptions.AuthenticationType, StringComparer.Ordinal))
@@ -176,6 +162,10 @@ public virtual async Task AuthenticateAsync(IAuthenticateContext context)
176162
{
177163
context.Authenticated(ticket.Identity, ticket.Properties.Dictionary, BaseOptions.Description.Dictionary);
178164
}
165+
else
166+
{
167+
context.NotAuthenticated(BaseOptions.AuthenticationType, properties: null, description: BaseOptions.Description.Dictionary);
168+
}
179169
}
180170

181171
if (PriorHandler != null)
@@ -184,6 +174,20 @@ public virtual async Task AuthenticateAsync(IAuthenticateContext context)
184174
}
185175
}
186176

177+
public AuthenticationTicket Authenticate()
178+
{
179+
return LazyInitializer.EnsureInitialized(
180+
ref _authenticate,
181+
ref _authenticateInitialized,
182+
ref _authenticateSyncLock,
183+
() =>
184+
{
185+
return Task.FromResult(AuthenticateCore());
186+
}).Result;
187+
}
188+
189+
protected abstract AuthenticationTicket AuthenticateCore();
190+
187191
/// <summary>
188192
/// Causes the authentication logic in AuthenticateCore to be performed for the current request
189193
/// at most once and returns the results. Calling Authenticate more than once will always return

0 commit comments

Comments
 (0)