2022-08-12
1634
Fernando Doglio
72
Aug 12, 2022 ⋅ 5 min read

How to secure a REST API using JWT authentication

Fernando Doglio Technical Manager at Globant. Author of books and maker of software things. Find me online at fdoglio.com.

Recent posts:

the replay graphic november 5

The Replay (11/5/25): Developer elitism, REST APIs, and more

Discover what’s new in The Replay, LogRocket’s newsletter for dev and engineering leaders, in the November 5th issue.

Matt MacCormack
Nov 5, 2025 ⋅ 32 sec read
lewis cianci quote developer elitism

It’s time to break the cycle of developer elitism

A senior developer discusses how developer elitism breeds contempt and over-reliance on AI, and how you can avoid it in your own workplace.

Lewis Cianci
Nov 5, 2025 ⋅ 13 min read
open ai agent kit

I tried OpenAI’s AgentKit: Does it make Zapier and n8n obsolete?

Examine AgentKit, Open AI’s new tool for building agents. Conduct a side-by-side comparison with n8n by building AI agents with each tool.

Clara Ekekenta
Nov 4, 2025 ⋅ 11 min read

A Jarvis for everyone: AI agents as new interfaces

AI agents powered by MCP are redefining interfaces, shifting from clicks to intelligent, context-aware conversations.

Peter Aideloje
Nov 4, 2025 ⋅ 10 min read
View all posts

7 Replies to "How to secure a REST API using JWT authentication"

  1. You swapped the meaning of the issuer and the subject. The issuer is the authentication server which issued the token (usually a URI). The subject is the user being authenticated.

  2. this is best article, I have read every with context of explaining. you have explaines evrythig nicely and to the point. Thank you very much.

  3. That is a nice explanation! What about the need of changing the shared key, in case of symmetric encryption and signing? What option is there?
    I think the asymmetric encryptions would not be feasible for many client apps and even those keys have to be changed after some time!

  4. What problem does this solve that isn’t solved by, for example, Basic Authentication with a simple shared secret? How do you revoke access for a live JWT?

  5. Overall good explanation with the exception of having the JWT-secret known to the client.
    The only validation of the JWT that the client should do is to check the expiration-date of the JWT before using it.
    If it’s expired, then the client can go the route of re-authenticating the user.

    The back-end (API) is the only place that should know the JWT-secret so that it can verify if any JWT it receives was actually created by the back-end and was not tampered with.

  6. Great article. Note that JSON Web Tokens come in two flavors (or structures) – JSON Web Signature (JWS) and JSON Web Encryption (JWE). From the RFC: “JWT – A string representing a set of claims as a JSON object that is encoded in a JWS or JWE, enabling the claims to be digitally signed or MACed and/or encrypted.”

    The JWE compact serialization results in 5 parts, JWS is 3 parts.

Leave a Reply

Would you be interested in joining LogRocket's developer community?

Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.

Sign up now