What is the difference between Access and Refresh Token?

Access Token:

  • Function: Grants access to specific resources on a server. Think of it like a key for a specific door.

  • Lifetime: Short-lived, typically expiring in minutes or hours. However, the exact duration can vary depending on the application and its security needs. In some cases, it might be a day or two, while others might use shorter windows of just a few hours. This short validity period enhances security by limiting the potential damage if an access token is compromised.

  • Storage: Placed within the application or browser

Refresh Token:

  • Function: Used to acquire new access tokens once the original access token expires. Imagine it like a keycard to get new building keys.

  • Lifetime: Long-lived, lasting days, weeks or even months. They are stored securely as they can be used to generate new access tokens.

  • Storage: Secured on the authorization server, not accessible by the application or user directly.

Watch this amazing explanation from Hitesh Choudhary sir on Chai aur Code Youtube channel.