Home  Firebase   Firebase id ...

Firebase Id Token vs Access Token

In Firebase, the ID token and the access token serve different purposes, though they are both involved in authentication and authorization processes. Here's a detailed comparison:

Firebase ID Token

Access Token

Differences and Use Cases

  1. Purpose:

    • ID Token: Primarily for user authentication and to identify the user. Used to secure interactions with Firebase services.
    • Access Token: Primarily for authorizing applications to access external APIs or resources.
  2. Contents:

    • ID Token: Includes user identity information, custom claims, and metadata.
    • Access Token: Includes scopes, permissions, and access rights.
  3. Verification:

    • ID Token: Can be verified by Firebase Admin SDK to ensure the user's authenticity and claims.
    • Access Token: Typically verified by the resource server (e.g., Google API server) to grant access to resources.

Example Workflow in Firebase

  1. User Signs In:

    • User signs in using Firebase Authentication (e.g., with email/password, Google Sign-In).
    • Firebase Authentication issues an ID token.
  2. Accessing Firebase Services:

    • The ID token is used to authenticate requests to Firebase services like Firestore, ensuring that the request is made by an authenticated user.
  3. Accessing Third-Party APIs:

    • If the application needs to access Google APIs on behalf of the user, an OAuth flow is initiated.
    • The user grants permission, and an access token is issued by Google.
    • The access token is used to make authorized requests to Google APIs.

Practical Example

Published on: Jul 16, 2024, 10:16 AM  
 

Comments

Add your comment