Skip to content

Commit ef9d910

Browse files
committed
Add docs for Authentication.Abstractions
Contributes to #26397
1 parent e62bd65 commit ef9d910

12 files changed

+92
-58
lines changed

src/Http/Authentication.Abstractions/src/AuthenticationHttpContextExtensions.cs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ namespace Microsoft.AspNetCore.Authentication
1414
public static class AuthenticationHttpContextExtensions
1515
{
1616
/// <summary>
17-
/// Extension method for authenticate using the <see cref="AuthenticationOptions.DefaultAuthenticateScheme"/> scheme.
17+
/// Authenticate the current request using the default authentication scheme.
18+
/// The default authentication scheme can be configured using <see cref="AuthenticationOptions.DefaultAuthenticateScheme"/>.
1819
/// </summary>
1920
/// <param name="context">The <see cref="HttpContext"/> context.</param>
2021
/// <returns>The <see cref="AuthenticateResult"/>.</returns>
2122
public static Task<AuthenticateResult> AuthenticateAsync(this HttpContext context) =>
2223
context.AuthenticateAsync(scheme: null);
2324

2425
/// <summary>
25-
/// Extension method for authenticate.
26+
/// Authenticate the current request using the specified scheme.
2627
/// </summary>
2728
/// <param name="context">The <see cref="HttpContext"/> context.</param>
2829
/// <param name="scheme">The name of the authentication scheme.</param>
@@ -31,7 +32,8 @@ public static Task<AuthenticateResult> AuthenticateAsync(this HttpContext contex
3132
context.RequestServices.GetRequiredService<IAuthenticationService>().AuthenticateAsync(context, scheme);
3233

3334
/// <summary>
34-
/// Extension method for Challenge.
35+
/// Challenge the current request using the specified scheme.
36+
/// An authentication challenge can be issued when an unauthenticated user requests an endpoint that requires authentication.
3537
/// </summary>
3638
/// <param name="context">The <see cref="HttpContext"/> context.</param>
3739
/// <param name="scheme">The name of the authentication scheme.</param>
@@ -40,15 +42,19 @@ public static Task ChallengeAsync(this HttpContext context, string? scheme) =>
4042
context.ChallengeAsync(scheme, properties: null);
4143

4244
/// <summary>
43-
/// Extension method for authenticate using the <see cref="AuthenticationOptions.DefaultChallengeScheme"/> scheme.
45+
/// Challenge the current request using the default challenge scheme.
46+
/// An authentication challenge can be issued when an unauthenticated user requests an endpoint that requires authentication.
47+
/// The default challenge scheme can be configured using <see cref="AuthenticationOptions.DefaultChallengeScheme"/>.
4448
/// </summary>
4549
/// <param name="context">The <see cref="HttpContext"/> context.</param>
4650
/// <returns>The task.</returns>
4751
public static Task ChallengeAsync(this HttpContext context) =>
4852
context.ChallengeAsync(scheme: null, properties: null);
4953

5054
/// <summary>
51-
/// Extension method for authenticate using the <see cref="AuthenticationOptions.DefaultChallengeScheme"/> scheme.
55+
/// Challenge the current request using the default challenge scheme.
56+
/// An authentication challenge can be issued when an unauthenticated user requests an endpoint that requires authentication.
57+
/// The default challenge scheme can be configured using <see cref="AuthenticationOptions.DefaultChallengeScheme"/>.
5258
/// </summary>
5359
/// <param name="context">The <see cref="HttpContext"/> context.</param>
5460
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
@@ -57,7 +63,8 @@ public static Task ChallengeAsync(this HttpContext context, AuthenticationProper
5763
context.ChallengeAsync(scheme: null, properties: properties);
5864

5965
/// <summary>
60-
/// Extension method for Challenge.
66+
/// Challenge the current request using the specified scheme.
67+
/// An authentication challenge can be issued when an unauthenticated user requests an endpoint that requires authentication.
6168
/// </summary>
6269
/// <param name="context">The <see cref="HttpContext"/> context.</param>
6370
/// <param name="scheme">The name of the authentication scheme.</param>
@@ -67,7 +74,8 @@ public static Task ChallengeAsync(this HttpContext context, string? scheme, Auth
6774
context.RequestServices.GetRequiredService<IAuthenticationService>().ChallengeAsync(context, scheme, properties);
6875

6976
/// <summary>
70-
/// Extension method for Forbid.
77+
/// Forbid the current request using the specified scheme.
78+
/// Forbid is used when an authenticated user attempts to access a resource they are not permitted to access.
7179
/// </summary>
7280
/// <param name="context">The <see cref="HttpContext"/> context.</param>
7381
/// <param name="scheme">The name of the authentication scheme.</param>
@@ -76,15 +84,19 @@ public static Task ForbidAsync(this HttpContext context, string? scheme) =>
7684
context.ForbidAsync(scheme, properties: null);
7785

7886
/// <summary>
79-
/// Extension method for Forbid using the <see cref="AuthenticationOptions.DefaultForbidScheme"/> scheme..
87+
/// Forbid the current request using the default forbid scheme.
88+
/// Forbid is used when an authenticated user attempts to access a resource they are not permitted to access.
89+
/// The default forbid scheme can be configured using <see cref="AuthenticationOptions.DefaultForbidScheme"/>.
8090
/// </summary>
8191
/// <param name="context">The <see cref="HttpContext"/> context.</param>
8292
/// <returns>The task.</returns>
8393
public static Task ForbidAsync(this HttpContext context) =>
8494
context.ForbidAsync(scheme: null, properties: null);
8595

8696
/// <summary>
87-
/// Extension method for Forbid.
97+
/// Forbid the current request using the default forbid scheme.
98+
/// Forbid is used when an authenticated user attempts to access a resource they are not permitted to access.
99+
/// The default forbid scheme can be configured using <see cref="AuthenticationOptions.DefaultForbidScheme"/>.
88100
/// </summary>
89101
/// <param name="context">The <see cref="HttpContext"/> context.</param>
90102
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
@@ -93,7 +105,8 @@ public static Task ForbidAsync(this HttpContext context, AuthenticationPropertie
93105
context.ForbidAsync(scheme: null, properties: properties);
94106

95107
/// <summary>
96-
/// Extension method for Forbid.
108+
/// Forbid the current request using the specified scheme.
109+
/// Forbid is used when an authenticated user attempts to access a resource they are not permitted to access.
97110
/// </summary>
98111
/// <param name="context">The <see cref="HttpContext"/> context.</param>
99112
/// <param name="scheme">The name of the authentication scheme.</param>
@@ -103,7 +116,7 @@ public static Task ForbidAsync(this HttpContext context, string? scheme, Authent
103116
context.RequestServices.GetRequiredService<IAuthenticationService>().ForbidAsync(context, scheme, properties);
104117

105118
/// <summary>
106-
/// Extension method for SignIn.
119+
/// Sign in a principal for the specified scheme.
107120
/// </summary>
108121
/// <param name="context">The <see cref="HttpContext"/> context.</param>
109122
/// <param name="scheme">The name of the authentication scheme.</param>
@@ -113,7 +126,8 @@ public static Task SignInAsync(this HttpContext context, string? scheme, ClaimsP
113126
context.SignInAsync(scheme, principal, properties: null);
114127

115128
/// <summary>
116-
/// Extension method for SignIn using the <see cref="AuthenticationOptions.DefaultSignInScheme"/>.
129+
/// Sign in a principal for the default authentication scheme.
130+
/// The default scheme for signing in can be configured using <see cref="AuthenticationOptions.DefaultSignInScheme"/>.
117131
/// </summary>
118132
/// <param name="context">The <see cref="HttpContext"/> context.</param>
119133
/// <param name="principal">The user.</param>
@@ -122,7 +136,8 @@ public static Task SignInAsync(this HttpContext context, ClaimsPrincipal princip
122136
context.SignInAsync(scheme: null, principal: principal, properties: null);
123137

124138
/// <summary>
125-
/// Extension method for SignIn using the <see cref="AuthenticationOptions.DefaultSignInScheme"/>.
139+
/// Sign in a principal for the default authentication scheme.
140+
/// The default scheme for signing in can be configured using <see cref="AuthenticationOptions.DefaultForbidScheme"/>.
126141
/// </summary>
127142
/// <param name="context">The <see cref="HttpContext"/> context.</param>
128143
/// <param name="principal">The user.</param>
@@ -132,7 +147,7 @@ public static Task SignInAsync(this HttpContext context, ClaimsPrincipal princip
132147
context.SignInAsync(scheme: null, principal: principal, properties: properties);
133148

134149
/// <summary>
135-
/// Extension method for SignIn.
150+
/// Sign in a principal for the specified scheme.
136151
/// </summary>
137152
/// <param name="context">The <see cref="HttpContext"/> context.</param>
138153
/// <param name="scheme">The name of the authentication scheme.</param>
@@ -143,30 +158,32 @@ public static Task SignInAsync(this HttpContext context, string? scheme, ClaimsP
143158
context.RequestServices.GetRequiredService<IAuthenticationService>().SignInAsync(context, scheme, principal, properties);
144159

145160
/// <summary>
146-
/// Extension method for SignOut using the <see cref="AuthenticationOptions.DefaultSignOutScheme"/>.
161+
/// Sign out a principal for the default authentication scheme.
162+
/// The default scheme for signing out can be configured using <see cref="AuthenticationOptions.DefaultSignOutScheme"/>.
147163
/// </summary>
148164
/// <param name="context">The <see cref="HttpContext"/> context.</param>
149165
/// <returns>The task.</returns>
150166
public static Task SignOutAsync(this HttpContext context) => context.SignOutAsync(scheme: null, properties: null);
151167

152168
/// <summary>
153-
/// Extension method for SignOut using the <see cref="AuthenticationOptions.DefaultSignOutScheme"/>.
169+
/// Sign out a principal for the default authentication scheme.
170+
/// The default scheme for signing out can be configured using <see cref="AuthenticationOptions.DefaultSignOutScheme"/>.
154171
/// </summary>
155172
/// <param name="context">The <see cref="HttpContext"/> context.</param>
156173
/// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param>
157174
/// <returns>The task.</returns>
158175
public static Task SignOutAsync(this HttpContext context, AuthenticationProperties? properties) => context.SignOutAsync(scheme: null, properties: properties);
159176

160177
/// <summary>
161-
/// Extension method for SignOut.
178+
/// Sign out a principal for the specified scheme.
162179
/// </summary>
163180
/// <param name="context">The <see cref="HttpContext"/> context.</param>
164181
/// <param name="scheme">The name of the authentication scheme.</param>
165182
/// <returns>The task.</returns>
166183
public static Task SignOutAsync(this HttpContext context, string? scheme) => context.SignOutAsync(scheme, properties: null);
167184

168185
/// <summary>
169-
/// Extension method for SignOut.
186+
/// Sign out a principal for the specified scheme.
170187
/// </summary>
171188
/// <param name="context">The <see cref="HttpContext"/> context.</param>
172189
/// <param name="scheme">The name of the authentication scheme.</param>
@@ -176,21 +193,22 @@ public static Task SignOutAsync(this HttpContext context, string? scheme, Authen
176193
context.RequestServices.GetRequiredService<IAuthenticationService>().SignOutAsync(context, scheme, properties);
177194

178195
/// <summary>
179-
/// Extension method for getting the value of an authentication token.
196+
/// Authenticates the request using the specified scheme and returns the value for the token.
180197
/// </summary>
181198
/// <param name="context">The <see cref="HttpContext"/> context.</param>
182199
/// <param name="scheme">The name of the authentication scheme.</param>
183200
/// <param name="tokenName">The name of the token.</param>
184-
/// <returns>The value of the token.</returns>
201+
/// <returns>The value of the token if present.</returns>
185202
public static Task<string?> GetTokenAsync(this HttpContext context, string? scheme, string tokenName) =>
186203
context.RequestServices.GetRequiredService<IAuthenticationService>().GetTokenAsync(context, scheme, tokenName);
187204

188205
/// <summary>
189-
/// Extension method for getting the value of an authentication token.
206+
/// Authenticates the request using the default authentication scheme and returns the value for the token.
207+
/// The default authentication scheme can be configured using <see cref="AuthenticationOptions.DefaultAuthenticateScheme"/>.
190208
/// </summary>
191209
/// <param name="context">The <see cref="HttpContext"/> context.</param>
192210
/// <param name="tokenName">The name of the token.</param>
193-
/// <returns>The value of the token.</returns>
211+
/// <returns>The value of the token if present.</returns>
194212
public static Task<string?> GetTokenAsync(this HttpContext context, string tokenName) =>
195213
context.RequestServices.GetRequiredService<IAuthenticationService>().GetTokenAsync(context, tokenName);
196214
}

src/Http/Authentication.Abstractions/src/AuthenticationOptions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
namespace Microsoft.AspNetCore.Authentication
1111
{
12+
/// <summary>
13+
/// Options to configure authentication.
14+
/// </summary>
1215
public class AuthenticationOptions
1316
{
1417
private readonly IList<AuthenticationSchemeBuilder> _schemes = new List<AuthenticationSchemeBuilder>();
@@ -93,7 +96,8 @@ public void AddScheme(string name, Action<AuthenticationSchemeBuilder> configure
9396
public string? DefaultForbidScheme { get; set; }
9497

9598
/// <summary>
96-
/// If true, SignIn should throw if attempted with a ClaimsPrincipal.Identity.IsAuthenticated = false.
99+
/// If true, SignIn should throw if attempted with a user is not authenticated.
100+
/// A user is considered authenticated if <see cref="ClaimsIdentity.IsAuthenticated"/> returns <see langword="true" /> for the <see cref="ClaimsPrincipal"/> associated with the HTTP request.
97101
/// </summary>
98102
public bool RequireAuthenticatedSignIn { get; set; } = true;
99103
}

src/Http/Authentication.Abstractions/src/AuthenticationProperties.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Diagnostics.CodeAnalysis;
76
using System.Globalization;
87

98
namespace Microsoft.AspNetCore.Authentication
@@ -122,10 +121,10 @@ public bool? AllowRefresh
122121
}
123122

124123
/// <summary>
125-
/// Set a string value in the <see cref="Items"/> collection.
124+
/// Sets or remove a string value from the <see cref="Items"/> collection.
126125
/// </summary>
127126
/// <param name="key">Property key.</param>
128-
/// <param name="value">Value to set or <c>null</c> to remove the property.</param>
127+
/// <param name="value">Value to set or <see langword="null" /> to remove the property.</param>
129128
public void SetString(string key, string? value)
130129
{
131130
if (value != null)
@@ -157,10 +156,10 @@ public void SetParameter<T>(string key, T value)
157156
=> Parameters[key] = value;
158157

159158
/// <summary>
160-
/// Get a bool value from the <see cref="Items"/> collection.
159+
/// Get a nullable <see cref="bool"/> from the <see cref="Items"/> collection.
161160
/// </summary>
162161
/// <param name="key">Property key.</param>
163-
/// <returns>Retrieved value or <c>null</c> if the property is not set.</returns>
162+
/// <returns>Retrieved value or <see langword="null" /> if the property is not set.</returns>
164163
protected bool? GetBool(string key)
165164
{
166165
if (Items.TryGetValue(key, out var value) && bool.TryParse(value, out var boolValue))
@@ -171,10 +170,10 @@ public void SetParameter<T>(string key, T value)
171170
}
172171

173172
/// <summary>
174-
/// Set a bool value in the <see cref="Items"/> collection.
173+
/// Set or removes a <see cref="bool"/> value in the <see cref="Items"/> collection.
175174
/// </summary>
176175
/// <param name="key">Property key.</param>
177-
/// <param name="value">Value to set or <c>null</c> to remove the property.</param>
176+
/// <param name="value">Value to set or <see langword="null" /> to remove the property.</param>
178177
protected void SetBool(string key, bool? value)
179178
{
180179
if (value.HasValue)
@@ -188,10 +187,10 @@ protected void SetBool(string key, bool? value)
188187
}
189188

190189
/// <summary>
191-
/// Get a DateTimeOffset value from the <see cref="Items"/> collection.
190+
/// Get a nullable <see cref="DateTimeOffset"/> value from the <see cref="Items"/> collection.
192191
/// </summary>
193192
/// <param name="key">Property key.</param>
194-
/// <returns>Retrieved value or <c>null</c> if the property is not set.</returns>
193+
/// <returns>Retrieved value or <see langword="null" /> if the property is not set.</returns>
195194
protected DateTimeOffset? GetDateTimeOffset(string key)
196195
{
197196
if (Items.TryGetValue(key, out var value)
@@ -203,10 +202,10 @@ protected void SetBool(string key, bool? value)
203202
}
204203

205204
/// <summary>
206-
/// Set a DateTimeOffset value in the <see cref="Items"/> collection.
205+
/// Sets or removes a <see cref="DateTimeOffset" /> value in the <see cref="Items"/> collection.
207206
/// </summary>
208207
/// <param name="key">Property key.</param>
209-
/// <param name="value">Value to set or <c>null</c> to remove the property.</param>
208+
/// <param name="value">Value to set or <see langword="null" /> to remove the property.</param>
210209
protected void SetDateTimeOffset(string key, DateTimeOffset? value)
211210
{
212211
if (value.HasValue)

src/Http/Authentication.Abstractions/src/AuthenticationScheme.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Authentication
1313
public class AuthenticationScheme
1414
{
1515
/// <summary>
16-
/// Constructor.
16+
/// Initializes a new instance of <see cref="AuthenticationScheme"/>.
1717
/// </summary>
1818
/// <param name="name">The name for the authentication scheme.</param>
1919
/// <param name="displayName">The display name for the authentication scheme.</param>

src/Http/Authentication.Abstractions/src/AuthenticationSchemeBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ public AuthenticationSchemeBuilder(string name)
2121
}
2222

2323
/// <summary>
24-
/// The name of the scheme being built.
24+
/// Gets the name of the scheme being built.
2525
/// </summary>
2626
public string Name { get; }
2727

2828
/// <summary>
29-
/// The display name for the scheme being built.
29+
/// Gets or sets the display name for the scheme being built.
3030
/// </summary>
3131
public string? DisplayName { get; set; }
3232

3333
/// <summary>
34-
/// The <see cref="IAuthenticationHandler"/> type responsible for this scheme.
34+
/// Gets or sets the <see cref="IAuthenticationHandler"/> type responsible for this scheme.
3535
/// </summary>
3636
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
3737
public Type? HandlerType { get; set; }
3838

3939
/// <summary>
4040
/// Builds the <see cref="AuthenticationScheme"/> instance.
4141
/// </summary>
42-
/// <returns></returns>
42+
/// <returns>The <see cref="AuthenticationScheme"/>.</returns>
4343
public AuthenticationScheme Build()
4444
{
4545
if (HandlerType is null)

0 commit comments

Comments
 (0)