17
I am creating an API, I use authentication via Token (JWT), I want this token to be valid for, for example, 10 minutes, and, with each request, return a new Token, so the user will have access while active, if disconnected for a long time (more than 10 min)you will have to re-use
Should the customer create two requests, one asking for the main feature (a user search, for example) and the other for a new token? Or it is better that the backend always returns, in addition to the search for users, a new token?
In the case of the second option, how to send this token? Pass as part of the body? Is there a specific HTTP header for this? Is there a problem in passing the token via Cookie?
I saw the use of a header Token
and of Authorization
but found nothing official, only on blogs. I know the second is used to pass the client token to the server, vice versa also?
The header Token
does not appear on MDN, nor on unofficial Wikipedia (en)
The header Authorization
only appears for requests, ie from client to server
First, I recommend reading: What is and what is JWT for?. In short: The client must make a request of the type
post
requesting thetoken
(composed ofcabelho.corpo.assinatura
), the response to that request should be added a hearderBaerer
with the Jwt token. You must have some mechanism in the back end to validate whether the token is valid in the next requets– Marconi
If it’s in C#: ASP.NET Core 2.0: JWT API authentication (JSON Web Tokens)
– Marconi
@Marconi the doubt is not how JWT works or how to implement it, the doubt is what is the most recommended way to send it from server to client, ie, the creation and validation is already ready and working. None of the links talk about it, just how to implement and how to send from client to server (what I already know)
– Costamilam
Mano follows a detailed tutorial on how to do , part 1 https://imasters.com.br/front-end/implementando-autheno-jwt-utilizando-react part 2 https://imasters.com.br/back-end/implementand-autheno-autheno-jwt-o-backend
– Daniel Brito
Hello friend, I believe that what you are looking for is something related to refresh tokens and Sliding-Sessions (sessions that expire in a given inactivity), take a look at this article, he talks about.
– MSLacerda