Class ResourceAuthorizationOptions
Configures the resource-authorization pipeline's failure-exposure policy on a per-resource
basis. Register via services.AddResourceAuthorization(o => o.HideExistence<Incident>())
or through the TrellisServiceBuilder.UseResourceAuthorization(o => ...) composition slot.
public sealed class ResourceAuthorizationOptions
- Inheritance
-
ResourceAuthorizationOptions
- Inherited Members
- Extension Methods
Remarks
The default policy is Propagate — every command
returns the original Error.Forbidden / Error.AuthenticationRequired until the
consumer opts a resource into HideAsNotFound. There
is no global "hide everything" switch by design: hiding existence is a per-resource
security decision and a blanket default would silently change the wire shape of every
authorization failure.
Translation scope. The pipeline normalizes root Error.NotFound, Error.Gone, Error.Forbidden, and
Error.AuthenticationRequired to the same public NotFound. Its type and identifier
come from the configured public resource and message, and its code/detail come only from
this configuration. Original metadata and causes are not copied to the public error.
Other direct-resource and via-leaf errors pass through unchanged. Via intermediate/owner
load failures retain their collapse-to-denial behavior.
Pipeline interaction. When a command implements both
IAuthorize and IAuthorizeResource<T>, the static-permission
AuthorizationBehavior runs BEFORE the resource-authorization behavior. An
unauthenticated caller whose request fails the static gate sees the original 401/403 — the
hide-as-NotFound translation never runs. Commands that need existence-hiding to apply to
every failure mode should omit IAuthorize and let
HideAsNotFound cover the resource-authorization
branch alone.
Cache safety. Hidden 404s can be shared across actors regardless of body differences. Protect them
with Cache-Control: no-store or private — a shared cache will otherwise
serve an unauthorized actor's synthetic 404 to a later authorized actor.
Normalization applies to the resource-authorization stage, not unrelated handler errors or application response customization. It does not equalize response timing.
Properties
DefaultExposurePolicy
Gets or sets the default exposure policy applied to resources that have no per-resource override. Defaults to Propagate.
public AuthFailureExposurePolicy DefaultExposurePolicy { get; set; }
Property Value
Methods
HideExistence<TResource>()
Opt the given resource into HideAsNotFound.
Missing resources and authorization denials receive the same public NotFound using
TResource as both the public type and ID extraction source.
The default code and detail are used.
public ResourceAuthorizationOptions HideExistence<TResource>() where TResource : class
Returns
- ResourceAuthorizationOptions
This options instance for chaining.
Type Parameters
TResourceThe resource type to hide. Must be a reference type because the resource-authorization behaviors already constrain
where TResource : class.
HideExistence<TResource>(string?, string?)
Hides existence using fixed public metadata shared by missing and withheld resources.
public ResourceAuthorizationOptions HideExistence<TResource>(string? code = null, string? detail = null) where TResource : class
Parameters
codestringThe public reason code. Null, empty, or whitespace uses the default unspecified code.
detailstringThe public detail, or null to use the standard NotFound rendering.
Returns
- ResourceAuthorizationOptions
This options instance for chaining.
Type Parameters
TResourceThe reference-type resource to hide.
Remarks
Replaces this resource's previous configuration. Parameterless reconfiguration resets code/detail.
HideExistence<TAuthorizationResource, TPublicResource>()
Opt the given resource into HideAsNotFound
using a separate public resource type for the canonical NotFound payload.
Use this when the loader projects to an internal authorization shape that is not the
canonical wire-public type (for example loading OrderOwnership for the
authorization check while exposing Order as the public resource).
public ResourceAuthorizationOptions HideExistence<TAuthorizationResource, TPublicResource>() where TAuthorizationResource : class
Returns
- ResourceAuthorizationOptions
This options instance for chaining.
Type Parameters
TAuthorizationResourceThe resource type the loader returns (what the pipeline authorizes against).
TPublicResourceThe resource type to publish in the synthetic
NotFound'sResourceRef. The pipeline also uses this type to locate anIIdentifyResource<TPublicResource, TId>implementation on the message for ID extraction, falling back toIIdentifyResource<TAuthorizationResource, TId>if the public variant is not present.
HideExistence<TAuthorizationResource, TPublicResource>(string?, string?)
Hides a projected authorization resource using a public resource type and fixed public metadata. Missing and withheld resources receive the same public NotFound.
public ResourceAuthorizationOptions HideExistence<TAuthorizationResource, TPublicResource>(string? code = null, string? detail = null) where TAuthorizationResource : class
Parameters
codestringThe public reason code. Null, empty, or whitespace uses the default unspecified code.
detailstringThe public detail, or null to use the standard NotFound rendering.
Returns
- ResourceAuthorizationOptions
This options instance for chaining.
Type Parameters
TAuthorizationResourceThe reference-type resource returned by the loader.
TPublicResourceThe public resource type used for the NotFound and identifier lookup.
Remarks
Replaces this resource's previous configuration. Parameterless reconfiguration resets code/detail.
Propagate<TResource>()
Explicitly opt the given resource into Propagate. Useful for overriding a non-Propagate DefaultExposurePolicy on individual resources.
public ResourceAuthorizationOptions Propagate<TResource>() where TResource : class
Returns
- ResourceAuthorizationOptions
This options instance for chaining.
Type Parameters
TResourceThe resource type whose failures must always propagate.