Skip to content

Commit 8ec8cbf

Browse files
authored
Clarify DefaultPolicy and FallbackPolicy Behavior in XML Docs (#60619)
1 parent a5b2b7e commit 8ec8cbf

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/Security/Authorization/Core/src/AuthorizationOptions.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,26 @@ public class AuthorizationOptions
2424
public bool InvokeHandlersAfterFailure { get; set; } = true;
2525

2626
/// <summary>
27-
/// Gets or sets the default authorization policy. Defaults to require authenticated users.
27+
/// Gets or sets the default authorization policy. Defaults to requiring authenticated users.
2828
/// </summary>
2929
/// <remarks>
30-
/// The default policy used when evaluating <see cref="IAuthorizeData"/> with no policy name specified.
30+
/// - The `DefaultPolicy` applies whenever authorization is required, but no specific policy is set.
31+
/// - If an `[Authorize]` attribute is present without a policy name, the `DefaultPolicy` is used instead of the `FallbackPolicy`.
32+
/// - This behavior ensures that endpoints explicitly requesting authorization (via `[Authorize]` or `RequireAuthorization()`) default to a secure policy.
33+
/// - When non-default behavior is needed, developers should define named policies.
3134
/// </remarks>
3235
public AuthorizationPolicy DefaultPolicy { get; set; } = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
3336

3437
/// <summary>
3538
/// Gets or sets the fallback authorization policy used by <see cref="AuthorizationPolicy.CombineAsync(IAuthorizationPolicyProvider, IEnumerable{IAuthorizeData})"/>
36-
/// when no IAuthorizeData have been provided. As a result, the AuthorizationMiddleware uses the fallback policy
37-
/// if there are no <see cref="IAuthorizeData"/> instances for a resource. If a resource has any <see cref="IAuthorizeData"/>
38-
/// then they are evaluated instead of the fallback policy. By default the fallback policy is null, and usually will have no
39-
/// effect unless you have the AuthorizationMiddleware in your pipeline. It is not used in any way by the
40-
/// default <see cref="IAuthorizationService"/>.
39+
/// when no authorization metadata (e.g., `[Authorize]` attribute, `RequireAuthorization()`) is explicitly provided for a resource.
4140
/// </summary>
41+
/// <remarks>
42+
/// - The `FallbackPolicy` only applies when there are no authorization attributes or explicit policies set.
43+
/// - If a resource has an `[Authorize]` attribute (even without a policy name), the `DefaultPolicy` is used instead of the `FallbackPolicy`.
44+
/// - This means `FallbackPolicy` is mainly relevant for middleware-based authorization flows where no per-endpoint authorization is specified.
45+
/// - By default, `FallbackPolicy` is `null`, meaning it has no effect unless explicitly set.
46+
/// </remarks>
4247
public AuthorizationPolicy? FallbackPolicy { get; set; }
4348

4449
/// <summary>

0 commit comments

Comments
 (0)