HeaderDial › Guides

How to send HTTP Basic auth without the login prompt

To open a staging site protected by HTTP Basic authentication without the browser's username and password dialog, send the credentials yourself in an Authorization header. Encode user:pass as base64 (printf 'user:pass' | base64 gives dXNlcjpwYXNz), then in HeaderDial add the request header Authorization with the value Basic dXNlcjpwYXNz, limited to the staging host. This works in Chrome, Edge or Firefox. Base64 is an encoding, not encryption, so only do this over HTTPS.

Why the prompt appears and how the header avoids it

A server using Basic authentication answers an unauthenticated request with 401 Unauthorized and a header like WWW-Authenticate: Basic realm="Staging". The browser reacts by showing its login dialog, then repeats the request with Authorization: Basic <base64 of username:password>. The browser remembers what you typed only for the current session, so the dialog comes back after a restart, in a private window and on every new test profile.

If the very first request already carries a valid Authorization header, the server never sends the 401 and the browser never asks. We checked this in Chrome 159 and Firefox 158 with HeaderDial 0.1.0, against a test server that returns 401 for any request without the right header: with the header set, the protected page loaded directly.

Compute the header value

Join the username and password with a colon and base64-encode the result. In a terminal:

printf 'user:pass' | base64
# dXNlcjpwYXNz

# if the password contains a % sign, pass it as an argument instead
printf '%s' 'user:p%ss' | base64

Avoid echo 'user:pass' | base64: echo adds a newline, which gets encoded too (dXNlcjpwYXNzCg==) and the server rejects it. In the browser's DevTools console:

btoa('user:pass')   // "dXNlcjpwYXNz"

// btoa only accepts Latin-1 text; for other characters encode as UTF-8 first
btoa(String.fromCharCode(...new TextEncoder().encode('jürgen:pass')))

The username cannot contain a colon, because the first colon separates it from the password. The password can contain colons. To check a value you were given, decode it with printf 'dXNlcjpwYXNz' | base64 -d.

Steps

  1. Click the HeaderDial icon to open the popup. If the site-access banner appears, choose Allow on all sites or Only <current host>.
  2. Click + Request header, type Authorization as the name and Basic dXNlcjpwYXNz as the value: the word Basic, one space, then your encoded string. Leave the operation on set.
  3. Open Where it applies, click + Only on…, choose Domain and enter the staging host, for example staging.example.com.
  4. Optionally pick 8 hours or 1 day in the expiry select. The row counts down and the header switches itself off when the time is up.
  5. Open the staging site. No dialog should appear. If it still does, the encoded value is wrong or the filter does not match the host.

When the site uses Authorization itself

set replaces any Authorization header a request would have carried. If the staging app's own JavaScript sends Authorization: Bearer … to an API on the same host, your Basic value overwrites it and API calls fail. Add a + Never on… filter with type URL pattern for the API path, such as ||staging.example.com/api/, so those requests keep their own token. For Bearer tokens themselves, see how to add an Authorization header.

The curl equivalent

# let curl build the header
curl -u user:pass https://staging.example.com/

# or send it yourself
curl -H "Authorization: Basic dXNlcjpwYXNz" https://staging.example.com/

Security caveats

Base64 is not encryption. Anyone who sees the header can decode it in a second. Over plain HTTP the password crosses the network readable by anyone on the path. Only send Basic credentials to HTTPS sites.

Pitfalls

Add to ChromeFirefox: coming soon