Q:

What is the correct workflow for JWT?

I am working on an API and I am trying to wrap my head around authorization. I just learned about JSON Web Tokens and I understand the concept but there a few things I have questions about.

Once I get the initial JWT, do I just include it in the header whenever I make a request from the client to the server?
Do I also include it when responding to the client from the server?
Do I have to update the expiration time whenever I send it with a request (in either direction)?

Thank you!

A:

If you need to be able to authenticate the request, yes you will need to send the JWT with the request. Calls that do not need authentication can be made without this.
No, you don't need to include it in every response. Once the browser has the JWT assigned (at login), you can just store it in the browser (localstorage) until it should be adjusted or removed (such as logging out)
The expiration should be set so that the token remains valid for the period you need it for. Just like with cookie sessions, an expiration is set. The expiration timestamp makes the JWT valid until the expiration passes.

