diff --git a/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs b/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs index 462e5a593e..539319b868 100644 --- a/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs +++ b/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs @@ -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 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 leftovers = authenticationTypes.Except(authenticateContext.Accepted); diff --git a/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs b/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs index 2a24076c19..0b6fe2c349 100644 --- a/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs +++ b/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs @@ -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 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 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 leftovers = authenticationTypes.Except(signOutContext.Accepted);