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

Commit 06e24a8

Browse files
committed
Handle null auth, null descriptions.
1 parent 0ed2692 commit 06e24a8

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Microsoft.AspNet.Http.Core/Authentication/AuthenticationDescription.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ public class AuthenticationDescription
2020
/// Initializes a new instance of the <see cref="AuthenticationDescription"/> class
2121
/// </summary>
2222
public AuthenticationDescription()
23+
: this(items: null)
2324
{
24-
Items = new Dictionary<string, object>(StringComparer.Ordinal);
2525
}
2626

2727
/// <summary>
2828
/// Initializes a new instance of the <see cref="AuthenticationDescription"/> class
2929
/// </summary>
3030
/// <param name="items"></param>
31-
public AuthenticationDescription([NotNull] IDictionary<string, object> items)
31+
public AuthenticationDescription(IDictionary<string, object> items)
3232
{
33-
Items = items;
33+
Items = items ?? new Dictionary<string, object>(StringComparer.Ordinal); ;
3434
}
3535

3636
/// <summary>

src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public override AuthenticationResult Authenticate([NotNull] string authenticatio
6161
throw new InvalidOperationException($"The following authentication scheme was not accepted: {authenticationScheme}");
6262
}
6363

64+
if (authenticateContext.Principal == null)
65+
{
66+
return null;
67+
}
68+
6469
return new AuthenticationResult(authenticateContext.Principal,
6570
new AuthenticationProperties(authenticateContext.Properties),
6671
new AuthenticationDescription(authenticateContext.Description));
@@ -82,6 +87,11 @@ public override async Task<AuthenticationResult> AuthenticateAsync([NotNull] str
8287
throw new InvalidOperationException($"The following authentication scheme was not accepted: {authenticationScheme}");
8388
}
8489

90+
if (authenticateContext.Principal == null)
91+
{
92+
return null;
93+
}
94+
8595
return new AuthenticationResult(authenticateContext.Principal,
8696
new AuthenticationProperties(authenticateContext.Properties),
8797
new AuthenticationDescription(authenticateContext.Description));

0 commit comments

Comments
 (0)