title: How cookies and tokens work
body: <p>I'm designing a web application and now I'm working on the authentication function. I read that there are two approaches: cookies and tokens. I do not really understanding how these two work. </p>
  
  <p>I'm planing to use django-rest-framework-jwt if I chose tokens. Here's where I am at : </p>
  
  <p><strong>Tokens</strong></p>
  
  <p>The user sends his data (login and password). The application verifies that the data are correct and calculates a token and then send it back to the user. When the user make a request he includes the token in the request. The application decodes the request and we get the information about the user.</p>
  
  <p>My question :</p>
  
  <p><strong>- How do we get the token? Is it like calculating a hash code?
  - How do we get the user information after we decode the token?
  - How is it determined that the token is dead? 
  - Can a web application that uses tokens be used through a browser</strong></p>
  
  <p><strong>Cookies</strong></p>
  
  <p>Same as tokens but cookie are sent using the HTTP header not in request body. Cookies must stored in the server side. </p>
  
  <p>My question :</p>
  
  <p><strong>- In articles I read they say that tokens have the advantage that they have life time. But cookies have that too. So what's the difference between the life time of a cookie and a token?
  - How we identify the user who made the request? Do we store a dictionary (cookie, user id)?</strong></p>