Class FormFieldCapabilityGrantRequestBindingProvider
- Namespace
- AsiBackbone.AspNetCore.CapabilityGrants
- Assembly
- AsiBackbone.AspNetCore.dll
Binds a capability grant to the submitted form fields of the request.
public sealed class FormFieldCapabilityGrantRequestBindingProvider : ICapabilityGrantRequestBindingProvider
- Inheritance
-
FormFieldCapabilityGrantRequestBindingProvider
- Implements
- Inherited Members
Remarks
The binding value is BindingPrefix followed by the lowercase hexadecimal SHA-256 hash of a canonical JSON encoding of the form fields: field names lower-cased with the invariant culture and sorted ordinally, each with its values in submitted order. The antiforgery field configured in FormFieldName, the token form field configured in TokenFormFieldName, and any name in ExcludedFieldNames are left out. Issuers compute the same value for the fields they intend to authorize with CreateBinding(IEnumerable<KeyValuePair<string, StringValues>>, IEnumerable<string>?).
A request that cannot carry a body binds the empty field set. A request with a form body that contains files, a body that is not a form, or a form that cannot be read is not bound, which denies it. Only the form body is covered: the query string and route values are not, so an endpoint that takes a resource identifier from its route should carry that identifier as a form field or use a provider that binds it.
Constructors
FormFieldCapabilityGrantRequestBindingProvider(IOptions<FormFieldCapabilityGrantBindingOptions>, IOptions<SignedCapabilityGrantOptions>, IOptions<AntiforgeryOptions>?)
Binds a capability grant to the submitted form fields of the request.
public FormFieldCapabilityGrantRequestBindingProvider(IOptions<FormFieldCapabilityGrantBindingOptions> bindingOptions, IOptions<SignedCapabilityGrantOptions> grantOptions, IOptions<AntiforgeryOptions>? antiforgeryOptions = null)
Parameters
bindingOptionsIOptions<FormFieldCapabilityGrantBindingOptions>The form-field binding options.
grantOptionsIOptions<SignedCapabilityGrantOptions>The signed capability grant options, whose token form field is excluded.
antiforgeryOptionsIOptions<AntiforgeryOptions>The antiforgery options, whose form field is excluded, when antiforgery is configured.
Remarks
The binding value is BindingPrefix followed by the lowercase hexadecimal SHA-256 hash of a canonical JSON encoding of the form fields: field names lower-cased with the invariant culture and sorted ordinally, each with its values in submitted order. The antiforgery field configured in FormFieldName, the token form field configured in TokenFormFieldName, and any name in ExcludedFieldNames are left out. Issuers compute the same value for the fields they intend to authorize with CreateBinding(IEnumerable<KeyValuePair<string, StringValues>>, IEnumerable<string>?).
A request that cannot carry a body binds the empty field set. A request with a form body that contains files, a body that is not a form, or a form that cannot be read is not bound, which denies it. Only the form body is covered: the query string and route values are not, so an endpoint that takes a resource identifier from its route should carry that identifier as a form field or use a provider that binds it.
Fields
BindingPrefix
Gets the prefix of every binding value produced by this provider.
public const string BindingPrefix = "form-sha256:"
Field Value
Methods
CreateBinding(IEnumerable<KeyValuePair<string, StringValues>>, IEnumerable<string>?)
Computes the binding value for a set of form fields, for an issuer to place in ResourceBinding.
public static string CreateBinding(IEnumerable<KeyValuePair<string, StringValues>> fields, IEnumerable<string>? excludedFieldNames = null)
Parameters
fieldsIEnumerable<KeyValuePair<string, StringValues>>The form fields to bind.
excludedFieldNamesIEnumerable<string>Field names to leave out, compared case-insensitively.
Returns
- string
The binding value.
Remarks
Pass the same exclusions the relying party applies. The relying party always excludes its antiforgery and token form fields, so an issuer that includes either here produces a binding that never matches.
Exceptions
- ArgumentNullException
fieldsis null.- ArgumentException
Two field names are equal once lower-cased, or a field name is blank.
ResolveAsync(HttpContext, EndpointGovernanceDescriptor, CancellationToken)
Resolves the resource binding expected for the current request.
public ValueTask<CapabilityGrantRequestBinding> ResolveAsync(HttpContext httpContext, EndpointGovernanceDescriptor descriptor, CancellationToken cancellationToken = default)
Parameters
httpContextHttpContextThe current HTTP context.
descriptorEndpointGovernanceDescriptorThe endpoint governance descriptor.
cancellationTokenCancellationTokenA token that can cancel binding resolution.
Returns
- ValueTask<CapabilityGrantRequestBinding>
The resolved binding.