title: How to use JWT in MVC application for authentication and authorization?
body: <p>I planned to use ASP.NET Identity 2.0 in an ASP.NET MVC application for authentication and authorization.</p>
  
  <p>Referring the below link</p>
  
  <p><a href="http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/" rel="noreferrer">JSON Web Token in ASP.NET Web API 2 using Owin</a></p>
  
  <p>I was able to create a access token(JWT) for the valid user i.e., When user Logs in to the application I will validate the user with name and password then I will issue a JSON web token for that valid user.</p>
  
  <p>Now, I read in some articles that we need to pass the bearer token in headers for every request to validate the user for authentication. In MVC we will provide Authorize attribute for the methods that needs to be protected as shown below…</p>
  
  <pre><code>      public class UserController : BaseHRAppController
        {
              [Authorize]
              public ActionResult Index()
              {          
                 return View();
              }
         }
  </code></pre>
  
  <p>How to tell my MVC application to use JWT for validating the user?</p>
  
  <p>I want to make my MVC application validate the user using JWT whenever the user tries to access the method with authorize attribute. Since I will use AJAX calls in many pages to access method present in MVC controller, I don't think it's good to pass a token on every AJAX request. I need help to accomplish authentication and authorization in an efficient way using ASP.NET Identity in an MVC applicaton. </p>
  
  <p>Currently, I don't know how to use this JWT token for authentication and authorization in an MVC application.</p>