title: Implementating OAuth access token in ASP.NET Web API2 webservice
body: <p>I use ASP.NET Web API and using a jquery ajax method.</p>
  
  <p>I would like to create secure Web services using OAuth access token.</p>
  
  <p>How can I implement OAuth2 to ASP.NET Web API2 Web Services?</p>
  
  <p>I want to prevent the use of the web services without logging in - no access token.</p>
  
  <p>There is a sample project with the implementation of oauth2 to web services?</p>
  
  <p><strong>WebApi Controller for example:</strong></p>
  
  <pre><code>public class GetDataController : ApiController
  {
      public string Get(int id, string accessToken)
      {
  
          //Check access token
          //How can I implementing this logic for authorization valid access token
          if (accessToken == isInvalid)
          {
              return "Access denied";
          }
  
          //If accessToken is valid return value
          return "value";
      }
  }
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>$.get( "api/getdata", { id: 1, accessToken: "KEY" } )
  .done(function( data ) {
  alert( "Data Loaded: " + data );
  });
  </code></pre>