title: How to use a MVC WebAPI OData endpoint securely?
body: <p>I have an OData endpoint defined at <code>~/odata/</code>, which doesn't need to be accessed unless a user has been authenticated (in fact, how would you secure this for non-authenticated users).</p>
  
  <p>I setup role-based authentication to this path in the web.config with:</p>
  
  <pre><code>  &lt;location path="odata"&gt;
      &lt;system.web&gt;
        &lt;authorization&gt;
          &lt;allow roles="WaitConfirmation, etc...."/&gt;
        &lt;/authorization&gt;
      &lt;/system.web&gt;
    &lt;/location&gt;
  </code></pre>
  
  <p>When a user logs in, I don't use the OData endpoint for authentication (primarily because I need to figure out how to secure this).</p>
  
  <p>I use EntityFramework to validate the user, return the user object, and hydrate the membership/role details.</p>
  
  <p>Is this the standard method to follow to allow users' data calls to go through WebAPI paths, and if so, how do you ensure that any requests WebAPI requests (remember, I'm using OData) only return data related to the logged in user?</p>
  
  <p>I have only read about "securing" OData services by means of decorating controller methods (ie. <code>[Queryable(PageSize=10)]</code>) in order to limit DOS attacks, etc, but not how to ensure that a if a common parameter, (ie. <code>UserID=[this logged in user id]</code>) is not included, to include it on all EF requests.</p>