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

Commit dff0c5f

Browse files
committed
Add doc comments
1 parent abfdf5a commit dff0c5f

17 files changed

+336
-19
lines changed

src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticateContext.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55

66
namespace Microsoft.AspNetCore.Authentication
77
{
8+
/// <summary>
9+
/// Base class used by <see cref="IAuthenticationHandler"/> methods.
10+
/// </summary>
811
public class AuthenticateContext : BaseAuthenticationContext
912
{
13+
/// <summary>
14+
/// Constructor.
15+
/// </summary>
16+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
17+
/// <param name="authenticationScheme">The name of the authentication scheme.</param>
1018
public AuthenticateContext(HttpContext context, string authenticationScheme) : base(context, authenticationScheme, properties: null)
1119
{ }
1220
}

src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticateResult.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,13 @@ private AuthenticateResult() { }
1616
/// <summary>
1717
/// If a ticket was produced, authenticate was successful.
1818
/// </summary>
19-
public bool Succeeded
20-
{
21-
get
22-
{
23-
return Ticket != null;
24-
}
25-
}
19+
public bool Succeeded => Ticket != null;
2620

2721
/// <summary>
2822
/// The authentication ticket.
2923
/// </summary>
3024
public AuthenticationTicket Ticket { get; private set; }
3125

32-
// REVIEW: should we also remember AuthenticationScheme?
33-
3426
/// <summary>
3527
/// Gets the claims-principal with authenticated user identities.
3628
/// </summary>
@@ -57,6 +49,11 @@ public bool Succeeded
5749
/// </summary>
5850
public bool Nothing { get; private set; }
5951

52+
/// <summary>
53+
/// Indicates that authentication was successful.
54+
/// </summary>
55+
/// <param name="ticket">The ticket representing the authentication result.</param>
56+
/// <returns>The result.</returns>
6057
public static AuthenticateResult Success(AuthenticationTicket ticket)
6158
{
6259
if (ticket == null)
@@ -66,25 +63,43 @@ public static AuthenticateResult Success(AuthenticationTicket ticket)
6663
return new AuthenticateResult() { Ticket = ticket };
6764
}
6865

66+
/// <summary>
67+
/// Indicates that stage of authentication was directly handled by user intervention and no
68+
/// further processing should be attempted.
69+
/// </summary>
70+
/// <returns>The result.</returns>
6971
public static AuthenticateResult Handle()
7072
{
7173
return new AuthenticateResult() { Handled = true };
7274
}
7375

76+
/// <summary>
77+
/// Indicates that there was no information returned for this authentication scheme.
78+
/// </summary>
79+
/// <returns>The result.</returns>
7480
public static AuthenticateResult None()
7581
{
7682
return new AuthenticateResult() { Nothing = true };
7783
}
7884

85+
/// <summary>
86+
/// Indicates that there was a failure during authentication.
87+
/// </summary>
88+
/// <param name="failure">The failure exception.</param>
89+
/// <returns>The result.</returns>
7990
public static AuthenticateResult Fail(Exception failure)
8091
{
8192
return new AuthenticateResult() { Failure = failure };
8293
}
8394

95+
/// <summary>
96+
/// Indicates that there was a failure during authentication.
97+
/// </summary>
98+
/// <param name="failureMessage">The failure message.</param>
99+
/// <returns>The result.</returns>
84100
public static AuthenticateResult Fail(string failureMessage)
85101
{
86102
return new AuthenticateResult() { Failure = new Exception(failureMessage) };
87103
}
88-
89104
}
90105
}

src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticationHttpContextExtensions.cs

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,154 @@
44
using System.Security.Claims;
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Http;
7-
using Microsoft.Extensions.DependencyInjection;
87

98
namespace Microsoft.AspNetCore.Authentication
109
{
10+
/// <summary>
11+
/// Extension methods to expose Authentication on HttpContext.
12+
/// </summary>
1113
public static class AuthenticationHttpContextExtensions
1214
{
15+
/// <summary>
16+
/// Extension method for authenticate using the <see cref="AuthenticationOptions.DefaultAuthenticationScheme"/> scheme.
17+
/// </summary>
18+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
19+
/// <returns>The <see cref="AuthenticateResult"/>.</returns>
1320
public static Task<AuthenticateResult> AuthenticateAsync(this HttpContext context) =>
1421
context.AuthenticateAsync(scheme: null);
1522

23+
/// <summary>
24+
/// Extension method for authenticate.
25+
/// </summary>
26+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
27+
/// <param name="scheme">The name of the authentication scheme.</param>
28+
/// <returns>The <see cref="AuthenticateResult"/>.</returns>
1629
public static Task<AuthenticateResult> AuthenticateAsync(this HttpContext context, string scheme) =>
1730
context.RequestServices.GetRequiredService<IAuthenticationService>().AuthenticateAsync(context, scheme);
1831

32+
/// <summary>
33+
/// Extension method for Challenge.
34+
/// </summary>
35+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
36+
/// <param name="scheme">The name of the authentication scheme.</param>
37+
/// <returns>The result.</returns>
1938
public static Task ChallengeAsync(this HttpContext context, string scheme) =>
2039
context.ChallengeAsync(scheme, properties: null);
2140

41+
/// <summary>
42+
/// Extension method for authenticate using the <see cref="AuthenticationOptions.DefaultChallengeScheme"/> scheme.
43+
/// </summary>
44+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
45+
/// <returns>The task.</returns>
2246
public static Task ChallengeAsync(this HttpContext context) =>
2347
context.ChallengeAsync(scheme: null, properties: null);
2448

49+
/// <summary>
50+
/// Extension method for Challenge.
51+
/// </summary>
52+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
53+
/// <param name="scheme">The name of the authentication scheme.</param>
54+
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
55+
/// <returns>The task.</returns>
2556
public static Task ChallengeAsync(this HttpContext context, string scheme, AuthenticationProperties properties) =>
2657
context.ChallengeAsync(scheme, properties: properties, behavior: ChallengeBehavior.Automatic);
2758

59+
/// <summary>
60+
/// Extension method for Challenge.
61+
/// </summary>
62+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
63+
/// <param name="scheme">The name of the authentication scheme.</param>
64+
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
65+
/// <param name="behavior">The <see cref="ChallengeBehavior"/> behavior.</param>
66+
/// <returns>The task.</returns>
2867
public static Task ChallengeAsync(this HttpContext context, string scheme, AuthenticationProperties properties, ChallengeBehavior behavior) =>
2968
context.RequestServices.GetRequiredService<IAuthenticationService>().ChallengeAsync(context, scheme, properties, behavior);
3069

70+
/// <summary>
71+
/// Extension method for Forbid.
72+
/// </summary>
73+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
74+
/// <param name="scheme">The name of the authentication scheme.</param>
75+
/// <returns>The task.</returns>
3176
public static Task ForbidAsync(this HttpContext context, string scheme) =>
3277
context.ForbidAsync(scheme, properties: null);
3378

79+
/// <summary>
80+
/// Extension method for Forbid.
81+
/// </summary>
82+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
83+
/// <param name="scheme">The name of the authentication scheme.</param>
84+
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
85+
/// <returns>The task.</returns>
3486
public static Task ForbidAsync(this HttpContext context, string scheme, AuthenticationProperties properties) =>
3587
context.RequestServices.GetRequiredService<IAuthenticationService>().ChallengeAsync(context, scheme, properties, ChallengeBehavior.Forbidden);
3688

89+
/// <summary>
90+
/// Extension method for SignIn.
91+
/// </summary>
92+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
93+
/// <param name="scheme">The name of the authentication scheme.</param>
94+
/// <param name="principal">The user.</param>
95+
/// <returns>The task.</returns>
3796
public static Task SignInAsync(this HttpContext context, string scheme, ClaimsPrincipal principal) =>
3897
context.SignInAsync(scheme, principal, properties: null);
3998

99+
/// <summary>
100+
/// Extension method for SignIn using the <see cref="AuthenticationOptions.DefaultSignInScheme"/>.
101+
/// </summary>
102+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
103+
/// <param name="principal">The user.</param>
104+
/// <returns>The task.</returns>
40105
public static Task SignInAsync(this HttpContext context, ClaimsPrincipal principal) =>
41106
context.SignInAsync(scheme: null, principal: principal, properties: null);
42107

108+
/// <summary>
109+
/// Extension method for SignIn using the <see cref="AuthenticationOptions.DefaultSignInScheme"/>.
110+
/// </summary>
111+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
112+
/// <param name="principal">The user.</param>
113+
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
114+
/// <returns>The task.</returns>
43115
public static Task SignInAsync(this HttpContext context, ClaimsPrincipal principal, AuthenticationProperties properties) =>
44116
context.SignInAsync(scheme: null, principal: principal, properties: properties);
45117

118+
/// <summary>
119+
/// Extension method for SignIn.
120+
/// </summary>
121+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
122+
/// <param name="scheme">The name of the authentication scheme.</param>
123+
/// <param name="principal">The user.</param>
124+
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
125+
/// <returns>The task.</returns>
46126
public static Task SignInAsync(this HttpContext context, string scheme, ClaimsPrincipal principal, AuthenticationProperties properties) =>
47127
context.RequestServices.GetRequiredService<IAuthenticationService>().SignInAsync(context, scheme, principal, properties);
48128

49-
129+
/// <summary>
130+
/// Extension method for SignOut.
131+
/// </summary>
132+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
133+
/// <param name="scheme">The name of the authentication scheme.</param>
134+
/// <returns>The task.</returns>
50135
public static Task SignOutAsync(this HttpContext context, string scheme) => context.SignOutAsync(scheme, properties: null);
51136

137+
/// <summary>
138+
/// Extension method for SignOut.
139+
/// </summary>
140+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
141+
/// <param name="scheme">The name of the authentication scheme.</param>
142+
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
143+
/// <returns></returns>
52144
public static Task SignOutAsync(this HttpContext context, string scheme, AuthenticationProperties properties) =>
53145
context.RequestServices.GetRequiredService<IAuthenticationService>().SignOutAsync(context, scheme, properties);
54146

55-
public static Task<string> GetTokenAsync(this HttpContext context, string signInScheme, string tokenName) =>
56-
context.RequestServices.GetRequiredService<IAuthenticationService>().GetTokenAsync(context, signInScheme, tokenName);
147+
/// <summary>
148+
/// Extension method for getting the value of an authentication token.
149+
/// </summary>
150+
/// <param name="context">The <see cref="HttpContext"/> context.</param>
151+
/// <param name="scheme">The name of the authentication scheme.</param>
152+
/// <param name="tokenName">The name of the token.</param>
153+
/// <returns>The value of the token.</returns>
154+
public static Task<string> GetTokenAsync(this HttpContext context, string scheme, string tokenName) =>
155+
context.RequestServices.GetRequiredService<IAuthenticationService>().GetTokenAsync(context, scheme, tokenName);
57156
}
58157
}

src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticationSchemeBuilder.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,34 @@
55

66
namespace Microsoft.AspNetCore.Authentication
77
{
8+
/// <summary>
9+
/// Used to build <see cref="AuthenticationScheme"/>s.
10+
/// </summary>
811
public class AuthenticationSchemeBuilder
912
{
13+
/// <summary>
14+
/// Constructor.
15+
/// </summary>
16+
/// <param name="name">The name of the scheme being built.</param>
1017
public AuthenticationSchemeBuilder(string name)
1118
{
1219
Name = name;
1320
}
1421

22+
/// <summary>
23+
/// The name of the scheme being built.
24+
/// </summary>
1525
public string Name { get; }
1626

27+
/// <summary>
28+
/// The <see cref="IAuthenticationHandler"/> type responsible for this scheme.
29+
/// </summary>
1730
public Type HandlerType { get; set; }
1831

32+
/// <summary>
33+
/// Builds the <see cref="AuthenticationScheme"/> instance.
34+
/// </summary>
35+
/// <returns></returns>
1936
public AuthenticationScheme Build() => new AuthenticationScheme(Name, HandlerType);
2037
}
2138
}

src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticationToken.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@
44

55
namespace Microsoft.AspNetCore.Authentication
66
{
7+
/// <summary>
8+
/// Name/Value representing an token.
9+
/// </summary>
710
public class AuthenticationToken
811
{
12+
/// <summary>
13+
/// Name.
14+
/// </summary>
915
public string Name { get; set; }
16+
17+
/// <summary>
18+
/// Value.
19+
/// </summary>
1020
public string Value { get; set; }
1121
}
1222
}

src/Microsoft.AspNetCore.Authentication.Abstractions/BaseAuthenticationContext.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66

77
namespace Microsoft.AspNetCore.Authentication
88
{
9+
/// <summary>
10+
/// Base context for authentication.
11+
/// </summary>
912
public abstract class BaseAuthenticationContext : BaseContext
1013
{
14+
/// <summary>
15+
/// Constructor.
16+
/// </summary>
17+
/// <param name="context">The context.</param>
18+
/// <param name="authenticationScheme">The name of the scheme.</param>
19+
/// <param name="properties">The properties.</param>
1120
protected BaseAuthenticationContext(HttpContext context, string authenticationScheme, AuthenticationProperties properties) : base(context)
1221
{
1322
if (string.IsNullOrEmpty(authenticationScheme))
@@ -19,6 +28,9 @@ protected BaseAuthenticationContext(HttpContext context, string authenticationSc
1928
Properties = properties ?? new AuthenticationProperties();
2029
}
2130

31+
/// <summary>
32+
/// The name of the scheme.
33+
/// </summary>
2234
public string AuthenticationScheme { get; }
2335

2436
/// <summary>

src/Microsoft.AspNetCore.Authentication.Abstractions/BaseContext.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
namespace Microsoft.AspNetCore.Authentication
88
{
9+
/// <summary>
10+
/// Base class used by other context classes.
11+
/// </summary>
912
public abstract class BaseContext
1013
{
14+
/// <summary>
15+
/// Constructor.
16+
/// </summary>
17+
/// <param name="context">The request context.</param>
1118
protected BaseContext(HttpContext context)
1219
{
1320
if (context == null)
@@ -18,13 +25,22 @@ protected BaseContext(HttpContext context)
1825
HttpContext = context;
1926
}
2027

28+
/// <summary>
29+
/// The context.
30+
/// </summary>
2131
public HttpContext HttpContext { get; }
2232

33+
/// <summary>
34+
/// The request.
35+
/// </summary>
2336
public HttpRequest Request
2437
{
2538
get { return HttpContext.Request; }
2639
}
2740

41+
/// <summary>
42+
/// The response.
43+
/// </summary>
2844
public HttpResponse Response
2945
{
3046
get { return HttpContext.Response; }

src/Microsoft.AspNetCore.Authentication.Abstractions/ChallengeBehavior.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace Microsoft.AspNetCore.Authentication
55
{
6+
/// <summary>
7+
/// Controls how challenge will behave (i.e. 401 vs 403).
8+
/// </summary>
69
public enum ChallengeBehavior
710
{
811
Automatic,

0 commit comments

Comments
 (0)