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

Commit e56658c

Browse files
committed
Switch to GetAuthenticationInfoAsync
1 parent 3e69df8 commit e56658c

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Security.Claims;
6+
7+
namespace Microsoft.AspNetCore.Http.Authentication
8+
{
9+
/// <summary>
10+
/// Used to store the results of an Authenticate call.
11+
/// </summary>
12+
public class AuthenticateInfo
13+
{
14+
/// <summary>
15+
/// The <see cref="ClaimsPrincipal"/>.
16+
/// </summary>
17+
public ClaimsPrincipal Principal { get; set; }
18+
19+
/// <summary>
20+
/// The <see cref="AuthenticationProperties"/>.
21+
/// </summary>
22+
public AuthenticationProperties Properties { get; set; }
23+
}
24+
}

src/Microsoft.AspNetCore.Http.Abstractions/Authentication/AuthenticationManager.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,11 @@ public abstract class AuthenticationManager
2020

2121
public abstract IEnumerable<AuthenticationDescription> GetAuthenticationSchemes();
2222

23-
public abstract Task AuthenticateAsync(AuthenticateContext context);
23+
public abstract Task<AuthenticateInfo> GetAuthenticateInfoAsync(string authenticationScheme);
2424

2525
public virtual async Task<ClaimsPrincipal> AuthenticateAsync(string authenticationScheme)
2626
{
27-
if (authenticationScheme == null)
28-
{
29-
throw new ArgumentNullException(nameof(authenticationScheme));
30-
}
31-
32-
var context = new AuthenticateContext(authenticationScheme);
33-
await AuthenticateAsync(context);
34-
return context.Principal;
27+
return (await GetAuthenticateInfoAsync(authenticationScheme))?.Principal;
3528
}
3629

3730
public virtual Task ChallengeAsync()

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ public override IEnumerable<AuthenticationDescription> GetAuthenticationSchemes(
5050
return describeContext.Results.Select(description => new AuthenticationDescription(description));
5151
}
5252

53-
public override async Task AuthenticateAsync(AuthenticateContext context)
53+
public override async Task<AuthenticateInfo> GetAuthenticateInfoAsync(string authenticationScheme)
5454
{
55-
if (context == null)
55+
if (authenticationScheme == null)
5656
{
57-
throw new ArgumentNullException(nameof(context));
57+
throw new ArgumentNullException(nameof(authenticationScheme));
5858
}
5959

6060
var handler = HttpAuthenticationFeature.Handler;
61+
var context = new AuthenticateContext(authenticationScheme);
6162
if (handler != null)
6263
{
6364
await handler.AuthenticateAsync(context);
@@ -67,6 +68,12 @@ public override async Task AuthenticateAsync(AuthenticateContext context)
6768
{
6869
throw new InvalidOperationException($"No authentication handler is configured to authenticate for the scheme: {context.AuthenticationScheme}");
6970
}
71+
72+
return new AuthenticateInfo
73+
{
74+
Principal = context.Principal,
75+
Properties = new AuthenticationProperties(context.Properties)
76+
};
7077
}
7178

7279
public override async Task ChallengeAsync(string authenticationScheme, AuthenticationProperties properties, ChallengeBehavior behavior)

0 commit comments

Comments
 (0)