ID Token vs Access Token

Malith Dilshan
5 min readMar 7, 2023

--

Introduction

Nowadays authorization is playing a major part in the internet and it’s all over there. Security becoming such an important thing in the world. To ensure that everyone should follow a good and solid authorization procedure in the development. ID tokens and access tokens are doing a huge role in this.

What is a token?

In general, a token is a digital or physical object that represents something of value or importance, such as a security or a form of currency. As a simple example coin is a type of token that can be used to buy things. Coin works as a token and it helps to get what we need. However, in the context of computer programming and computer security, a token typically refers to a piece of data that is used to authenticate or authorize access to a resource.

For example, in web development, a token may be used as part of an authentication system to ensure that a user is who they claim to be. This token can be generated by the server and sent to the client, where it is stored in a cookie or local storage. The token is then included in subsequent requests to the server as proof of authentication, allowing the user to access protected resources.

Tokens can also be used in other contexts, such as in blockchain technology, where tokens are used to represent digital assets or currencies. In this case, tokens are often created through the use of smart contracts and can be traded or exchanged on blockchain networks.

What is an ID Token?

An ID token is a type of JSON Web Token (JWT) that contains user identity information, typically used in the context of authentication and authorization in web applications.

When a user logs into a web application using an identity provider (such as Google, Facebook, or GitHub), the identity provider issues an ID token to the application. The ID token is a signed JSON object that contains information about the user, such as their name, email address, and unique identifier.

The ID token can be used by the web application to verify the identity of the user and to authorize access to resources or functionality based on the user’s permissions. It can also be used to personalize the user experience within the application.

ID tokens are commonly used in OpenID Connect, a widely adopted authentication and authorization protocol built on top of the OAuth 2.0 framework.

What is an Access token?

An access token is a credential that is used to authenticate and authorize access to protected resources, typically in the context of web applications and APIs.

When a user logs into a web application using an identity provider (such as Google, Facebook, or GitHub), the identity provider issues an access token to the application. The access token is a string of characters that can be used by the application to make requests on behalf of the user to other services or APIs that require authorization.

Access tokens typically have a limited lifespan and are used to authenticate and authorize specific actions or requests. For example, an access token may be used to grant permission for a user to read data from a particular database or to post a message to a social media platform.

Access tokens are commonly used in OAuth 2.0, a widely adopted authorization framework that enables third-party applications to access protected resources on behalf of a user without requiring the user to share their credentials with the third-party application.

What is the difference then?

You hope that ID tokens and access tokens look like almost doing the same thing right? But the answer is no. They are doing totally different tasks.

The main difference between an ID token and an access token is the information that they contain and the purpose for which they are used.

An ID token is a JSON Web Token (JWT) that contains information about the user’s identity, such as their name, email address, and unique identifier. It is typically used for authentication and to provide the web application with information about the user’s identity.

On the other hand, an access token is a credential that is used to authorize access to protected resources. It is typically used to make requests to APIs or other services that require authorization and can be used to grant specific permissions to the user or the application.

In summary, the key differences are:

  • ID token contains information about the user’s identity, while an access token does not.
  • The ID token is used for authentication, while an access token is used for authorization.
  • ID token provides information about the user to the web application, while access token is used by the web application to make requests to other services or APIs.

Relationship between ID Token and Access Token

The ID token is used for authentication and contains information about the user’s identity. The web application can use this information to personalize the user’s experience or to perform other actions based on the user’s identity.

The access token is used for authorization and is used to grant access to protected resources or APIs. The web application can use the access token to make requests to these resources or APIs on behalf of the user.

So, first, you will be entering login credentials and generate an ID Token. Using that now an access token will be created. Then access token will be used to do the communication.

Since the access token has a limited time span it uses a refresh token to get a new access token when the earlier one expires. Therefore users have to enter login credentials always. But still, you may be experienced that you have to enter credentials again from time to time right? That’s where the ID token expires. Then you have to get a new one by login in again.

session expired example

Conclusion

ID tokens and access tokens are important in authorization and security for web applications. Tokens are pieces of data used to authenticate or authorize access to resources. An ID token is a JSON Web Token (JWT) that contains user identity information used for authentication and authorization. An access token is a credential used to authorize access to protected resources. The main difference between the two is that an ID token contains information about the user’s identity, while an access token does not. The ID token is used for authentication, while an access token is used for authorization. The ID token is used by the web application to personalize the user’s experience or to perform other actions based on the user’s identity, while the access token is used to grant access to protected resources or APIs.

Thanks for reading!

Resources

  1. Id token vs access token
  2. AccessToken Vs ID Token Vs Refresh Token — What? Why?When?

--

--