> ## 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.

# Getting Auth Tokens

> Send a login request to get an authorization token for the rest of your test

## Overview

Certain applications require a request in order to get an authentication token. This is common
with APIs or SPAs.

With LoadForge you can easily set any headers you need by tweaking your get() or post() calls to
include a header set.

Below is a partial test (just the `on_start` section) that shows how to set an authorization (or really any) header
based on response content at launch with your load test.

Naturally, you would not do all of these. They are 3 examples of getting a Bearer token in different ways.

## Code snippets

<Warning title="These are snippets!">
  These are just partial examples from a test. You may use the wizard or another example
  template and copy paste these into your test.
</Warning>

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

class UserBehavior(TaskSet):
  def on_start(self):

  	  # Send login request
      response = requests.post("http://mysite.com/login", {
        "username": "user",
        "password": "pass"
      })

      # THEN set "token" from response header
        self.client.headers.update({"Authorization": response.headers.get("token")})

      # OR set "token" from response cookies
        self.client.cookies.set("Authorization", response.cookies.get("token"))

      # OR set "token" from response body
        token = response.json().get("token")
        self.client.headers.update({"Authorization": token})

  # continue the rest of your test
```

***

<Note title="Locust Test Example">
  LoadForge is powered by locust, meaning open source locust users can copy this script as well.
  If you are a locust user, consider importing your script to [LoadForge](https://loadforge.com) to supercharge your testing!
</Note>
