I am trying to build a custom input binding that takes an array of strings (which are actually scopes) and validate that the scopes in the array are available in the JWT of the HttpRequest (as demonstrated below).
[FunctionName(nameof(Put))]
public async Task<IActionResult> Put(
[HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "route")] HttpRequest req,
ILogger log,
[AuthorizeFunction(new[] { Scopes.Delete })] AuthorizationResult result
)
Currently, I have an HttpTrigger with an associated HttpRequest that contains the contents of the Authorization Header. The issue I'm encountering is during the creation of the binding rule in my implementation of the IExtensionConfigProvider.
public class AuthorizationExtensionProvider : IExtensionConfigProvider
{
public AuthorizationExtensionProvider() { }
public void Initialize(ExtensionConfigContext context)
{
// Creates a rule that links the attribute to the binding
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var rule = context.AddBindingRule<AuthorizeFunctionAttribute>();
rule.BindToInput(BuildInputFromAttribute);
}
public Task<string[]> BuildInputFromAttribute(
AuthorizeFunctionAttribute arg,
ValueBindingContext context
)
{
return Task.FromResult(arg.Scopes);
}
}
In the example above, I am able to retrieve the input from the Binding, but am unable to pass that input to a IBindingProvider where I can simultaneously extract the contents of the HttpRequest.
Alternatively, in the code sample below, I am able to create a rule that binds the Attribute to an IBindingProvider which allows me to pass the context (including the HttpRequest) to an IValueProvider.
public void Initialize(ExtensionConfigContext context)
{
// Creates a rule that links the attribute to the binding
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var rule = context.AddBindingRule<AuthorizeFunctionAttribute>();
rule.Bind(new AuthorizationBindingProvider());
}
All of this of course being a longwinded way of asking how to both retrieve the contents of an input binding's arguments while also providing them to a IValueProvider. Any help would be greatly appreciated.