For my OData based Web API, I have an additional layer of authentication which checks if the user has the proper rights to access a model. Now, when $expand is used in the query, the binding of models completely bypasses these authorization checks.
What I want, is when calling (for example) /odata/Countries(2)?$expand=Locations,People
, and the authorization layer reports that the current user has no rights to retrieve People
, a response is still given, but only with Locations
bound to Countries
. So the not-accessible People
model should not be returned alongside Countries
.
I could derive from SelectExpandQueryValidator
and modify the Validate
function. But this only allows me to declare an expand query invalid, not to modify it. Even more so, this is an authentication issue, and does not belong in validation. Also, I need the Countries
entity in order for the authentication layer to determine whether Locations
or People
may be accessed.
Subsequently, I took a look at the System.Web.Http.OData.Query namespace, and found that I should somehow modify the RawExpand
property SelectExpandQueryOption
. But since this is read-only (and also really seems like hacking), I started to look for alternatives. Only, I cannot find when the ODataQueryOptions
class is called in order to use the ApplyTo
methods (which in my case binds all expand models). So it comes down to this: how can I modify the way $expand binds models, whilst I'm already inside the method that is called?
Since this is a really specific $expand question, of beta functionality nonetheless, I'm probably looking at the ASP.NET Web API developers who are lingering around here. Am I missing some obvious functionality here, or are my demands too high? Thanks in advance!