title: How to implement web api token authorization with asp mvc and javascript
body: <p>I have a very thin ASP MVC application, that basically authenticates the user and render the views. I have a separate WebApi project where all the logic resides. What I need is to call the API from the views rendered by MVC using JS, but those API calls must be authenticated.</p>
  
  <p>According to the documentation, I should get a token from the API by sending username and password, and then contact the api endpoint passing the token received in order to be allowed to access the resource.</p>
  
  <p>It doesnt seem right to be passing the username and password from mvc to the view, so that the view can then contact the api to finally get the token.</p>
  
  <p>What is the appropiate way of doing this? Should I request a token to the API from MVC (server-side) directly, at the moment the user logs in, save that token somewhere (cookie, session) and make it available to the views so I could call the api from JS using that same token?</p>