In the following statement, the AsBffApiEndpoint() adds an attribute to all endpoints. Then there is a middleware specifically looking for that attribute and if present will check for an antiforgery header to be present.
endpoints.MapControllers().RequireAuthorization().AsBffApiEndpoint();
I need to be able to bypass that check on all GET endpoints. Most importantly, this is third party library, hence I have no control over the implementation.
I have try many things without success. Last attempt was to add a middleware custom middleware app.Use(...) and if the attribute was present, then remove it. However that's not possible since the list of metadata is readonly. Then, my last hope is to find a way to add same attribute -to all GET- with a flag false which ignores the check. In other words, all AsBffApiEndpoint() does is decorate an endpoint with [BffApi] attribute. This attribute ignores antiforery headers if use like this [BffApi(false)]. I know the solution is hacky because I will end up with something like this.
[BffApi]
[BffApi(false)]
//endpoint definition here
The good news is they get the endpoint metadata ordered endpoint.Metadata.GetOrderedMetadata<BffApiAttribute>(). Meaning as long as [BffApi(false)] takes priority in the list I should be good.