I have a backlist of tokens (JWT) stored in Redis and would like to enable users of my website to blacklist their tokens in a RESTful way.
I can either:
- Build the route
/sessions/<token>
with a DELETE method - Build the route
/sessions/
with a DELETE method and the token sent in the request body.
The first solution is simple but the token is stored in the server's logs and in the user's browser's history.
The second solution seems better but I'm not sure I'm not breaking HTTP RFC's idempotency principle by sending a DELETE request with a body.
What's the best practice in this case?
JWT tokens are URL-safe when it comes to the syntax. From the RFC 7519:
However, when using JWT as bearer tokens, it's advisable to avoid sending them in the URL. See the following quote from the RFC 6750:
For the situation mentioned in your question, you may not need to send the full token. You could give the token a unique identifier (stored in the
jti
claim) and then send only the token identifier to the server.See how the
jti
claim is defined in the above mentioned RFC:A UUID should be unique enough to identify your tokens without collisions.
You don't need to store the full token in the blacklist either: store only the value of the
jti
claim and some other claims that you may find relevant (such assub
andexp
, for example).DELETE
requests shouldn't contain a body. So you could useDELETE /sessions/{id}
, where{id}
is the unique identifier of your token.