A Beginner's Guide to Tokens and Their Uses
Imagine you need to enter a secure building. To do this, you need a special key, which is an access token. This token lets you enter the building and access certain rooms and areas, but it is only valid for a limited time before it expires.
To avoid a long process to get a new access token, you have a refresh token. Think of the refresh token as a VIP card that allows you to get a new access token without showing your ID and other proofs.
Here is more details breakdown :
Access Token
Purpose - An access token is a temporary key that allows you to access specific resources or perform certain actions. For instance, when you're logged into a website, the access token enables you to view your profile or make changes.
Duration - An access token usually lasts for a short period, from a few minutes to a few hours. Once it expires, you will need to get a new one to keep accessing the resources.
Refresh Token
Purpose - This is a long-lasting token that allows you to get a new access token without having to logged in again. It provides a new key whenever the current one expires. It can be stored in a database.
Duration - It lasts significantly longer than the access token, like days, weeks, or even months. This ensures a smooth experience without the need for constant logins.
How They Work Together:
You utilize your access token to access the necessary services or resources.
When the access token expires, your system can use the refresh token to obtain a new access token instead of requiring you to log in again.
This allows you to remain logged in and continue accessing services seamlessly.
So, the access token is like a short-term key for immediate access, and the refresh token is like a long-term VIP card that lets you get new keys when needed.
Subscribe to my newsletter
Read articles from ashish prakash Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by