Skip to main content

Features ›Authentication

Modifier sur GitHub

Cette documentation est disponible en anglais.

Authentication

Open the Auth tab and choose a type. DotFetch builds the right header or query parameter for you, and a preview shows exactly what will be sent.

TypeSends
No AuthNothing
Basic AuthAuthorization: Basic <base64 of user:password>
Bearer TokenAuthorization: Bearer <token>
API KeyYour key name and value, as a header or a query parameter
OAuth 2.0 (Client Credentials)Fetches a token from your token URL, then sends Authorization: Bearer <token>

Every field accepts {{VARIABLES}}, so secrets can stay in your .env file instead of being typed into the UI. Click 👁️ to show a hidden value and 🙈 to hide it again.

Basic Auth

FieldExample
Username{{API_USER}}
Password{{API_PASS}}
BASH
# .env
API_USER=testuser
API_PASS=testpass

Try it against httpbin, which only returns 200 for the right credentials:

GET https://httpbin.org/basic-auth/testuser/testpass

DotFetch fills in the variables first, then Base64-encodes testuser:testpass, so the header is correct even when the password comes from .env.

Bearer Token

FieldExample
Token{{ACCESS_TOKEN}}
CODE
GET https://httpbin.org/bearer
→ Authorization: Bearer eyJhbGciOi...

Type only the token. DotFetch adds the Bearer prefix.

API Key

FieldExample
Key nameX-API-Key
Value{{API_KEY}}
Add toHeader or Query Params

Header

X-API-Key: sk_test_123

Query Params

https://api.example.com/v1/weather?city=Cairo&api_key=sk_test_123

If the URL or the Params tab already has a parameter with the same name, the Auth tab's value replaces it, so the key is never sent twice:

CODE
URL typed:   https://api.example.com/v1/data?x=1&api_key=old
Auth tab:    api_key = new   (Add to Query Params)
Sent:        https://api.example.com/v1/data?x=1&api_key=new

OAuth 2.0 (Client Credentials)

Use this for machine-to-machine APIs where you have a client ID and secret.

FieldExample
Token URLhttps://auth.example.com/oauth/token
Client ID{{CLIENT_ID}}
Client Secret{{CLIENT_SECRET}}
Scope (optional)read:users write:users
  1. Fill in the fields and click ⚡ Fetch & Inject Token.
  2. DotFetch sends grant_type=client_credentials to the token URL, putting the client ID and secret in a Basic Authorization header (RFC 6749 §2.3.1).
  3. A card shows the token and when it expires. Every request you send now carries Authorization: Bearer <token>.

When the token expires, Send is blocked with "OAuth token expired — please fetch a new token". Click ⚡ Fetch & Inject Token again to get a new one.

Which header wins?

The Auth tab always has the last word:

  1. Your Headers tab rows are applied first.
  2. Your Pre-Request script runs and may change headers.
  3. The Auth tab is applied last. It replaces any Authorization header (in any letter case) from steps 1 and 2.
JS
// Pre-Request script, with Auth = Bearer Token
dotfetch.request.headers['Authorization'] = 'Bearer from-script';
// → ignored: the Auth tab's Bearer token is what gets sent

Want a script to build the Authorization header itself, for a custom signature scheme? Set Auth to No Auth, and the script's header is sent as-is.

What gets saved

Secrets are never written to disk. When you save a request to a collection, or it's recorded in History, the secret fields are handled like this:

Field holdsSaved asWhy
{{API_KEY}}{{API_KEY}}It's only a variable name; the secret stays in .env
sk_live_123(empty)A real secret is never stored
Bearer {{TOKEN}}(empty)Any literal text next to the variable could be part of a secret

This applies to the Basic Password, Bearer Token, API Key Value, and OAuth Client Secret. The fetched OAuth access token is never saved. The username, key name, token URL, client ID, and scope are saved as typed.

Tip: put every secret in .env and type only {{VARIABLE}} in the Auth tab. Saved requests then work as soon as you load them, and no secret ever reaches DotFetch's storage.

cURL export and secrets

📤 Export (cURL) copies the auth values exactly as they appear in the Auth tab:

  • If you typed the real secret, the copied command contains it. Treat it like a password and don't paste it into tickets or chat.
  • If you used {{API_KEY}}, the command contains the literal text {{API_KEY}}. curl doesn't know your .env, so replace it before running the command.
Authentication · DotFetch Docs | dotsuite