#53 - Reduce auth exceptions for missing handlers.

This commit is contained in:
Chris Ross 2014-04-25 11:42:17 -07:00
parent be5a98d38f
commit cfe76de294
2 changed files with 20 additions and 25 deletions

View File

@ -153,13 +153,12 @@ namespace Microsoft.AspNet.PipelineCore
throw new ArgumentNullException();
}
var handler = HttpAuthentication.Handler;
if (handler == null)
{
throw new InvalidOperationException("No authentication handlers present.");
}
var authenticateContext = new AuthenticateContext(authenticationTypes);
handler.Authenticate(authenticateContext);
if (handler != null)
{
handler.Authenticate(authenticateContext);
}
// Verify all types ack'd
IEnumerable<string> leftovers = authenticationTypes.Except(authenticateContext.Accepted);
@ -178,13 +177,12 @@ namespace Microsoft.AspNet.PipelineCore
throw new ArgumentNullException();
}
var handler = HttpAuthentication.Handler;
if (handler == null)
{
throw new InvalidOperationException("No authentication handlers present.");
}
var authenticateContext = new AuthenticateContext(authenticationTypes);
await handler.AuthenticateAsync(authenticateContext);
if (handler != null)
{
await handler.AuthenticateAsync(authenticateContext);
}
// Verify all types ack'd
IEnumerable<string> leftovers = authenticationTypes.Except(authenticateContext.Accepted);

View File

@ -135,13 +135,12 @@ namespace Microsoft.AspNet.PipelineCore
}
HttpResponseInformation.StatusCode = 401;
var handler = HttpAuthentication.Handler;
if (handler == null)
{
throw new InvalidOperationException("No authentication handlers present.");
}
var challengeContext = new ChallengeContext(authenticationTypes, properties == null ? null : properties.Dictionary);
handler.Challenge(challengeContext);
if (handler != null)
{
handler.Challenge(challengeContext);
}
// Verify all types ack'd
IEnumerable<string> leftovers = authenticationTypes.Except(challengeContext.Accepted);
@ -158,13 +157,12 @@ namespace Microsoft.AspNet.PipelineCore
throw new ArgumentNullException();
}
var handler = HttpAuthentication.Handler;
if (handler == null)
{
throw new InvalidOperationException("No authentication handlers present.");
}
var signInContext = new SignInContext(identities, properties == null ? null : properties.Dictionary);
handler.SignIn(signInContext);
if (handler != null)
{
handler.SignIn(signInContext);
}
// Verify all types ack'd
IEnumerable<string> leftovers = identities.Select(identity => identity.AuthenticationType).Except(signInContext.Accepted);
@ -181,13 +179,12 @@ namespace Microsoft.AspNet.PipelineCore
throw new ArgumentNullException();
}
var handler = HttpAuthentication.Handler;
if (handler == null)
{
throw new InvalidOperationException("No authentication handlers present.");
}
var signOutContext = new SignOutContext(authenticationTypes);
handler.SignOut(signOutContext);
if (handler != null)
{
handler.SignOut(signOutContext);
}
// Verify all types ack'd
IEnumerable<string> leftovers = authenticationTypes.Except(signOutContext.Accepted);