> ## Documentation Index
> Fetch the complete documentation index at: https://docs.loadforge.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Firebase Authentication

> Integrate Firebase Authentication with LoadForge to simulate user authentication scenarios during load testing.

## Overview

Integrating Firebase Authentication with Locust can enhance your load testing by simulating real-world user authentication scenarios.

## Setup

**1. Set Up Firebase Authentication:**

* **Create a Firebase Project:** If you haven't already, create a project in the [Firebase Console](https://console.firebase.google.com/).

* **Enable Authentication Methods:** Navigate to the "Authentication" section and enable the desired sign-in methods, such as Email/Password, Google, or others.

**2. Obtain Firebase Authentication Tokens:**

To authenticate users during load testing, you'll need to generate Firebase Authentication tokens. This can be achieved using Firebase's REST API:

* **Email/Password Authentication:**

  Send a POST request to Firebase's identity toolkit endpoint with the user's email and password to receive an ID token. Detailed instructions are available in the [Firebase Authentication REST API guide](https://firebase.google.com/docs/reference/rest/auth).

* **Custom Authentication Systems:**

  If you're using a custom authentication system, you can integrate it with Firebase Authentication to generate tokens. This process is outlined in the [Firebase Authentication documentation](https://firebase.google.com/docs/auth).

**3. Integrate Firebase Authentication with Locust:**

Once you have the ID tokens, you can incorporate them into your Locust tests:

* **Include the ID Token in Requests:**

  In your Locust tasks, add the `Authorization` header with the ID token for each request:

  ```python theme={null}
  from locust import HttpUser, task

  class FirebaseUser(HttpUser):
      def on_start(self):
          # Obtain the Firebase ID token
          self.id_token = "YOUR_FIREBASE_ID_TOKEN"

      @task
      def authenticated_request(self):
          headers = {
              "Authorization": f"Bearer {self.id_token}"
          }
          self.client.get("/your/protected/endpoint", headers=headers)
  ```

* **Automate Token Retrieval (Optional):**

  For dynamic token generation, implement a method to obtain the ID token programmatically within the `on_start` method. This ensures each simulated user has a unique token.
