Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

Follow publication

🏆Refresh token and Access token in JWT, step-by-step guide

Let's Code Future
Stackademic
Published in
4 min readFeb 7, 2024

Refresh token and Access token

What is JWT ? ❓🤔

JSON Web Tokens (JWT) are a popular method for securely transmitting information between parties as a JSON object. JWTs consist of three parts: a header, a payload, and a signature. They are often used for authentication and information exchange in web applications. Within JWT-based authentication systems, access tokens and refresh tokens play crucial roles in managing user sessions securely.

If not member click here for free access

Access Token 👁️:

  • An access token is a credential used to access protected resources on behalf of a user.
  • It typically contains information about the user’s identity (such as user ID), permissions (scopes), and possibly additional metadata.
  • Access tokens have a limited lifespan, typically ranging from a few minutes to a few hours, after which they expire.
  • They are short-lived for security reasons, reducing the window of opportunity for attackers in case the token is compromised.
  • Once an access token expires, the client must obtain a new one to continue accessing protected resources.

Refresh Token 🔃:

  • A refresh token is a credential used to obtain a new access token when the current access token expires.
  • Refresh tokens are long-lived compared to access tokens, often lasting days, weeks, or even months.
  • They are securely stored on the client-side (typically in an HTTP-only cookie or local storage) and are used to request new access tokens without requiring the user to reauthenticate.
  • Refresh tokens are valuable targets for attackers since compromising a refresh token can lead to prolonged unauthorized access.
  • It’s important to handle refresh tokens securely, such as transmitting them over HTTPS and storing them securely on the client-side.

Let’s try to understand whole mechanism 🧐

  • Both access tokens and refresh tokens can be implemented as JWTs, although they serve different purposes and have different lifespans.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

No responses yet

To respond to this story,
get the free Medium app.