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

Commit cfe76de

Browse files
committed
#53 - Reduce auth exceptions for missing handlers.
1 parent be5a98d commit cfe76de

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,12 @@ public override IEnumerable<AuthenticationResult> Authenticate(IList<string> aut
153153
throw new ArgumentNullException();
154154
}
155155
var handler = HttpAuthentication.Handler;
156-
if (handler == null)
157-
{
158-
throw new InvalidOperationException("No authentication handlers present.");
159-
}
160156

161157
var authenticateContext = new AuthenticateContext(authenticationTypes);
162-
handler.Authenticate(authenticateContext);
158+
if (handler != null)
159+
{
160+
handler.Authenticate(authenticateContext);
161+
}
163162

164163
// Verify all types ack'd
165164
IEnumerable<string> leftovers = authenticationTypes.Except(authenticateContext.Accepted);
@@ -178,13 +177,12 @@ public override async Task<IEnumerable<AuthenticationResult>> AuthenticateAsync(
178177
throw new ArgumentNullException();
179178
}
180179
var handler = HttpAuthentication.Handler;
181-
if (handler == null)
182-
{
183-
throw new InvalidOperationException("No authentication handlers present.");
184-
}
185180

186181
var authenticateContext = new AuthenticateContext(authenticationTypes);
187-
await handler.AuthenticateAsync(authenticateContext);
182+
if (handler != null)
183+
{
184+
await handler.AuthenticateAsync(authenticateContext);
185+
}
188186

189187
// Verify all types ack'd
190188
IEnumerable<string> leftovers = authenticationTypes.Except(authenticateContext.Accepted);

src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,12 @@ public override void Challenge(IList<string> authenticationTypes, Authentication
135135
}
136136
HttpResponseInformation.StatusCode = 401;
137137
var handler = HttpAuthentication.Handler;
138-
if (handler == null)
139-
{
140-
throw new InvalidOperationException("No authentication handlers present.");
141-
}
142138

143139
var challengeContext = new ChallengeContext(authenticationTypes, properties == null ? null : properties.Dictionary);
144-
handler.Challenge(challengeContext);
140+
if (handler != null)
141+
{
142+
handler.Challenge(challengeContext);
143+
}
145144

146145
// Verify all types ack'd
147146
IEnumerable<string> leftovers = authenticationTypes.Except(challengeContext.Accepted);
@@ -158,13 +157,12 @@ public override void SignIn(IList<ClaimsIdentity> identities, AuthenticationProp
158157
throw new ArgumentNullException();
159158
}
160159
var handler = HttpAuthentication.Handler;
161-
if (handler == null)
162-
{
163-
throw new InvalidOperationException("No authentication handlers present.");
164-
}
165160

166161
var signInContext = new SignInContext(identities, properties == null ? null : properties.Dictionary);
167-
handler.SignIn(signInContext);
162+
if (handler != null)
163+
{
164+
handler.SignIn(signInContext);
165+
}
168166

169167
// Verify all types ack'd
170168
IEnumerable<string> leftovers = identities.Select(identity => identity.AuthenticationType).Except(signInContext.Accepted);
@@ -181,13 +179,12 @@ public override void SignOut(IList<string> authenticationTypes)
181179
throw new ArgumentNullException();
182180
}
183181
var handler = HttpAuthentication.Handler;
184-
if (handler == null)
185-
{
186-
throw new InvalidOperationException("No authentication handlers present.");
187-
}
188182

189183
var signOutContext = new SignOutContext(authenticationTypes);
190-
handler.SignOut(signOutContext);
184+
if (handler != null)
185+
{
186+
handler.SignOut(signOutContext);
187+
}
191188

192189
// Verify all types ack'd
193190
IEnumerable<string> leftovers = authenticationTypes.Except(signOutContext.Accepted);

0 commit comments

Comments
 (0)