title: Why does the order of auth middleware declaration matter in Owin Startup class?
body: <p>I read some examples(<a href="http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/" rel="noreferrer">1</a>,<a href="http://www.moqdigital.com.au/insights/technical/12-steps-to-token-authentication-using-owin" rel="noreferrer">2</a>,<a href="https://auth0.com/docs/quickstart/backend/webapi-owin" rel="noreferrer">3</a>,<a href="http://johnatten.com/2015/01/19/asp-net-web-api-understanding-owinkatana-authenticationauthorization-part-i-concepts/" rel="noreferrer">4</a>) about setting up authentication in the owin pipeline when using web api and the examples declare the 
  authentication middleware as the first middleware in the Configuration method but doesn't tell why it needs to be first.</p>
  
  <p>In <a href="https://stackoverflow.com/questions/42710362/401-unauthorized-errors-when-accessing-webapi-from-angularjs-adal-js-client">this</a> question the auther had the webapi middleware attached before the authentication middleware and then the authentication didn't work correctly.
  When the auther moved it to the top of the method then everything work as expected..</p>
  
  <p>Does anyone know why the authentication middleware needs to be added as the first middleware in the Startup Configuration method?</p>