title: ASP.NET MVC4 and Web API Authentication + Authorization (Windows 8 and Web)
body: <p>I created an ASP.NET MVC 4 Internet Web Application using Simple Membership db for storing users, roles and profiles.</p>
  
  <p>In my app I created a Web API controller that will respond to the <code>http:// 127.0.0.1/api/users</code> and this call will return a list of all users stored in the db as <code>JSON</code>.</p>
  
  <p>The <code>UsersController</code> is decorated with <code>[Authorize]</code> attribute therefore any call to the <code>http:// 127.0.0.1/api/users</code> have to be authenticated.</p>
  
  <p>On the main page I have a button that once pressed a jQuery ajax get request is performed and will show the list of users returned by the Web API (json). </p>
  
  <p>If I am logged in and I press the button, everything works fine ... the list of users is retrieved and shown. </p>
  
  <p>If I am not logged in, the message show is <code>401 - Unauthorized</code> (custom message in jquery call statusCode) so it works as it should because of the <code>[Authorize]</code> attribute.</p>
  
  <p>My question: How can I authenticate when a Web API makes a request to it, to get the list of users and show them from a Windows 8 app or Windows Phone 8 or Windows Forms for example? In other words, from a client other than the web browser?</p>