๐ŸŽ‰ Premium Proxies ยท 3-Day Free TrialClaim Now โ†’
Proxy Basic

How Proxy Authentication Works

Proxy authentication verifies who can use a proxy. Learn how username-password, IP whitelisting, and token-based proxy auth work, with code examples.

S SparkProxy 4 15 min read
Share
How Proxy Authentication Works

Proxy authentication is the mechanism a proxy server uses to verify that a connecting client has permission to use it. Without it, any device on the internet could route traffic through your proxy, running up your bandwidth, burning your IPs, and exposing your operations to interference.

The two dominant methods are username-password authentication, where credentials travel with every request in an HTTP header, and IP whitelisting, where the proxy grants access based on the source IP of the connecting machine. Each has a different security profile, a different failure mode, and a different fit for automated scraping stacks.

Understanding how proxy auth works at the protocol level makes misconfiguration errors easier to diagnose, and helps you pick the right method before you're debugging a silent authentication failure at scale.

Key Takeaways

  • Proxy authentication is a challenge-response protocol: the proxy returns HTTP 407, the client retries with credentials in a Proxy-Authorization header (MDN, developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Proxy-Authorization)
  • Username-password auth sends credentials as Base64-encoded username:password, Base64 is not encryption; always use HTTPS tunneling (CONNECT method) when credentials are in transit
  • IP whitelisting requires no credentials in your code, but breaks silently when your machine's IP changes (DHCP renewal, VPN toggle, mobile network switch)
  • Most production scraping stacks use username-password auth because it survives IP changes and scales cleanly to multiple machines without dashboard changes

What Is Proxy Authentication?

Proxy authentication is the process of verifying that a client, a script, browser, or tool, is authorized to send traffic through a proxy server. It serves two purposes: access control (only authorized users can use the proxy) and attribution (the provider knows whose traffic is whose for billing, rate limiting, and abuse prevention).

Every proxy provider implements at least one authentication method. The choice of method determines how credentials are handled, where they live in your codebase, how they degrade when things change, and what happens when they fail.

There are three methods in widespread use:

  1. Username-password authentication, credentials embedded in the proxy connection string or HTTP headers
  2. IP whitelisting, access granted to specific source IPs; no credentials required in requests
  3. Token-based auth, a rotating or session-scoped token passed in headers or the proxy URL

Our finding: The most common proxy authentication failure mode isn't wrong credentials, it's IP whitelist entries that go stale. A machine running overnight scraping jobs changes IP at 3am via DHCP renewal, VPN reconnection, or cellular handover. The proxy starts rejecting every request with 407. Your scraper sees it as a generic connection failure. The actual cause, an expired whitelist entry, generates no descriptive error message. Username-password auth never has this problem. For unattended infrastructure, credentials in the connection string are more reliable than IP-based access.

proxy setup guide


The 407 Challenge-Response Flow

When a proxy requires authentication and a client connects without credentials, the proxy responds with HTTP status 407 Proxy Authentication Required along with a Proxy-Authenticate header describing the required auth scheme. The client then retries the request with a Proxy-Authorization header containing credentials.

The full exchange for HTTP (non-tunneled) requests:

1. Client โ†’ Proxy:   GET http://example.com/ HTTP/1.1
                     Host: example.com

2. Proxy โ†’ Client:   HTTP/1.1 407 Proxy Authentication Required
                     Proxy-Authenticate: Basic realm="SparkProxy"

3. Client โ†’ Proxy:   GET http://example.com/ HTTP/1.1
                     Host: example.com
                     Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==

4. Proxy โ†’ Target:   Forwards authenticated request
5. Target โ†’ Proxy:   Response
6. Proxy โ†’ Client:   Response forwarded

For HTTPS (tunneled) requests, the flow changes slightly because the client must establish a tunnel through the proxy using the CONNECT method before the TLS handshake with the target:

1. Client โ†’ Proxy:   CONNECT example.com:443 HTTP/1.1
                     Host: example.com:443
                     Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==

2. Proxy โ†’ Client:   HTTP/1.1 200 Connection Established

3. Client โ†’ Target:  (TLS handshake through the tunnel)
4. Client โ†’ Target:  Encrypted HTTPS request

Note that for HTTPS, the Proxy-Authorization header must be included in the CONNECT request, not in the encrypted request inside the tunnel, the proxy can't see inside the encrypted payload.

Proxy Authentication 407 Challenge-Response Flow Proxy Authentication: 407 Challenge-Response Flow Client Proxy Server Target โ‘  GET http://example.com/ โ‘ก 407, Proxy-Authenticate: Basic โ‘ข GET + Proxy-Authorization: Basic โ€ฆ โ‘ฃ Authenticated request forwarded โ‘ค Response โ‘ฅ Response relayed to client Source: MDN Web Docs, HTTP Proxy-Authorization header, developer.mozilla.org
The 407 challenge-response flow. Step โ‘ก is the 407 response with the Proxy-Authenticate header telling the client which auth scheme to use. Step โ‘ข is the retry with credentials in Proxy-Authorization. Source: MDN Web Docs.

Free trial

Scraping at scale? Skip the blocks.

Fast, unblockable datacentre proxies with unlimited bandwidth.

Username-Password Proxy Authentication

Username-password authentication is the most common proxy auth method for production use. Your credentials, a username and password assigned by your provider, are included in every connection attempt. No IP registration is required, and the same credentials work from any machine.

How the Header Works

The Proxy-Authorization header carries credentials in this format:

Proxy-Authorization: <auth-scheme> <credentials>

For Basic auth (the most common scheme), credentials are formatted as username:password, then Base64-encoded:

username:password โ†’ Base64 โ†’ dXNlcm5hbWU6cGFzc3dvcmQ=

Full header:

Proxy-Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

The MDN specification notes explicitly: "Base64 encoding is reversible, and therefore offers no cryptographic security. This method can be considered equivalent to sending the credentials in clear text." (MDN, Proxy-Authorization)

Practical implication: Use HTTPS connections (which tunnel through the proxy via CONNECT) or ensure your connection to the proxy itself is encrypted. If you send HTTP requests through a proxy over a plaintext connection and include Basic credentials, those credentials can be intercepted in transit.

Credentials in the Proxy URL

Most HTTP clients also support embedding credentials directly in the proxy URL, which sets the Proxy-Authorization header automatically:

http://username:password@proxy.example.com:10000

This is the format used in Python requests, Scrapy, Playwright, and most scraping frameworks. The client library Base64-encodes the credentials and adds the header on every request.

Sub-User / Sub-Account Authentication

Many providers allow you to create sub-users under your main account, each with their own username and password. This lets you:

  • Assign different credentials to different scraping jobs
  • Revoke access to one job without affecting others
  • Track per-job bandwidth consumption against separate sub-user budgets
  • Set rate limits or IP type restrictions per sub-user

Sub-user credentials follow the same username:password format and work identically in your code, only the string changes.

proxy account management


IP Whitelisting Authentication

IP whitelisting grants access to the proxy based on the source IP address of the incoming connection. No credentials are required in your code, if your machine's public IP is on the provider's allowlist, requests go through. If it isn't, they're rejected with 407.

How Whitelist Auth Works

The proxy server reads the source IP of each incoming connection. It checks that IP against an allowlist configured in your provider dashboard. If the IP matches, the connection is accepted without any Proxy-Authorization header. If it doesn't match, the 407 response fires even on requests that don't include credentials, because the IP isn't recognized.

Whitelisting in Code

With IP whitelisting configured, your connection string drops the credentials entirely:

http://proxy.example.com:10000

The proxy confirms identity by IP; your code needs no secrets.

When IP Whitelisting Breaks Down

IP whitelisting works reliably on machines with static IP addresses. It breaks in several common scenarios:

ScenarioWhat Happens
DHCP lease renewalMachine gets a new public IP, whitelist entry is stale
VPN connection or disconnectionEgress IP changes, requests immediately fail with 407
Cloud instance restartNew instance may get a different Elastic IP or shared NAT IP
Mobile or cellular connectionCarrier-grade NAT gives you a different IP per session
Multiple machines needing accessRequires adding each machine's IP to the allowlist separately

The silent failure mode is the real risk. When your machine's IP changes, requests fail with 407. But in most scraping stacks, 407 looks like a generic proxy error, the error message doesn't say "your whitelisted IP has changed." You need to diagnose it manually.

Rule of thumb: Use IP whitelisting for fixed-IP server infrastructure where the IP is stable and managed (e.g., a dedicated server with a static IP, or a cloud instance with an Elastic IP). Avoid it for developer machines, laptops, or any environment where the public IP can change without notice.


Token-Based Proxy Auth

Some providers offer token-based authentication as an alternative to static username-password credentials. A token is a string, typically alphanumeric, 32, 64 characters, that acts as an API key for the proxy connection.

Tokens appear in proxy URLs or headers in two formats:

In the proxy URL (treated as username):

http://<token>@proxy.example.com:10000

As a Bearer token in headers:

Proxy-Authorization: Bearer kNTktNTA1My00YzLT1234

Token-based auth offers one practical advantage over static username:password credentials: tokens can be scoped, rotated, or revoked independently. If a token is compromised, you rotate it without changing your account password. This is useful for CI/CD pipelines where credentials are stored as environment variables in deployment systems.


Comparing Proxy Auth Methods

AttributeUsername-PasswordIP WhitelistingToken-Based
Credential locationHTTP header (Base64)No credential in requestHTTP header or URL
Works from any IPโœ“ Yesโœ— No, fixed IP requiredโœ“ Yes
Silent failure riskLow, 407 on wrong passwordHigh, IP changes silentlyLow, expired token gives 407
Setup complexityLowMedium (manage IP list)Low to medium
Multi-machine supportโœ“ Same credentialsโœ— Each IP whitelisted separatelyโœ“ Same or separate tokens
Credential exposure riskPresent (Base64 reversible)None (no credential)Present (token in URL/header)
Rotate without downtimeโœ“ With overlap periodN/Aโœ“ Token swap
Best forMost production scrapingFixed-IP dedicated serversAPI-integrated or CI/CD workflows

How to Configure Proxy Auth in Your Stack

Python requests

import requests

proxies = {
    "http":  "http://username:password@proxy.sparkproxy.io:10000",
    "https": "http://username:password@proxy.sparkproxy.io:10000",
}

response = requests.get("https://httpbin.org/ip", proxies=proxies)
print(response.json())

The library Base64-encodes the credentials from the URL and adds Proxy-Authorization on every request automatically.

curl

curl --proxy http://username:password@proxy.sparkproxy.io:10000 \
     https://httpbin.org/ip

Or using the --proxy-user flag:

curl --proxy proxy.sparkproxy.io:10000 \
     --proxy-user "username:password" \
     https://httpbin.org/ip

Scrapy

In settings.py:

HTTPPROXY_AUTH_ENCODING = "latin-1"

# Or use PROXY middleware:
DOWNLOADER_MIDDLEWARES = {
    "scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware": 110,
}

PROXY = "http://username:password@proxy.sparkproxy.io:10000"

Playwright (Python)

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(
        proxy={
            "server": "http://proxy.sparkproxy.io:10000",
            "username": "your_username",
            "password": "your_password",
        }
    )
    page = browser.new_page()
    page.goto("https://httpbin.org/ip")
    print(page.content())
    browser.close()

Common Proxy Auth Errors

ErrorLikely CauseFix
`407 Proxy Authentication Required`Credentials missing, wrong, or IP not whitelistedCheck credentials or whitelist your current IP
`407` with valid credentialsUsername/password correct but special characters in password not URL-encodedPercent-encode special chars: `@` โ†’ `%40`, `:` โ†’ `%3A`
`407` from IP whitelistSource IP changed (DHCP, VPN, cloud restart)Update whitelist in provider dashboard
`403 Forbidden` (not 407)Authentication passed but your plan doesn't include access to this proxy type or regionCheck plan permissions in dashboard
Connection refusedWrong proxy host or portVerify host/port string, common mistake is using HTTP port on SOCKS endpoint
SSL/TLS error through proxyLibrary trying to verify proxy cert instead of tunnelingEnsure you're using CONNECT tunneling for HTTPS targets

Special characters in passwords are the most common silent misconfiguration in username-password auth. If your password contains @, :, /, ?, or #, these need to be percent-encoded in the proxy URL string. Otherwise the URL parser splits the credential on the wrong character and sends a truncated password.

Example, password p@ss:w0rd! in a URL:

# Wrong, parser reads 'p' as password, '@ss:w0rd!' as host
http://user:p@ss:w0rd!@proxy.example.com:10000

# Correct, special chars encoded
http://user:p%40ss%3Aw0rd!@proxy.example.com:10000
Proxy Auth Method Comparison, Failure Modes Auth Method Failure Mode Frequency (Relative) Low Med High Med Low N/A High Low Low Credential mistake Silent IP failure Low / N/A Username-Password IP Whitelist Token-Based
Relative failure mode frequency by auth method. IP whitelisting has a high silent failure risk due to IP changes; username-password and token-based auth have low silent failure rates but can surface credential mistakes. N/A = no credentials to misconfigure.

Security Considerations

Use HTTPS connections. Basic auth credentials are Base64-encoded, not encrypted. Over a plaintext HTTP connection, they're visible to anyone intercepting traffic between your machine and the proxy. When you connect to an HTTPS target through a proxy using the CONNECT method, the Proxy-Authorization header is sent in the CONNECT request, which is plaintext, before the TLS tunnel is established. Ensure your proxy endpoint itself supports or enforces a secure transport layer if credential interception is a concern for your threat model.

Don't hardcode credentials in source files. Use environment variables or a secrets manager. Credentials committed to version control are one of the most common causes of credential leakage.

Rotate credentials on team changes. If a team member who had access to proxy credentials leaves, rotate them. Most providers support creating sub-users with independent credentials specifically for this reason, you revoke the sub-user without affecting other jobs.

Apply the principle of least privilege. If your provider supports sub-users with plan restrictions (bandwidth caps, allowed proxy types, rate limits), apply the minimum necessary to each credential set. A credential used only for residential IP access shouldn't also have access to your datacenter pool.

Audit credential usage. Check your provider dashboard regularly for unexpected usage spikes under your credentials. A 10ร— bandwidth spike you didn't initiate means either a misconfigured script or a leaked credential.

proxy security best practices


Picking the Right Proxy Auth Method

For most scraping and automation use cases, username-password authentication is the more reliable default. It works from any machine, survives IP changes, scales to multiple machines without dashboard updates, and produces clear 407 errors when something is wrong.

IP whitelisting works well on stable server infrastructure where you control the IP and can guarantee it won't change. It keeps secrets out of your code entirely, which is a genuine security benefit in environments where code is shared or audited.

Token-based auth fits best in CI/CD pipelines and API-integrated workflows where credential rotation and scope control matter.

The security rule applies to all three: always transmit proxy credentials over encrypted connections, always store credentials in environment variables rather than source code, and always rotate credentials when access changes.

SparkProxy supports username-password authentication with sub-user management, IP whitelisting, and token-based access, configurable per account. See our authentication documentation for setup guides by platform.


Frequently asked questions

Proxy authentication is how a proxy server verifies that a connecting client has permission to use it. The two common methods are username-password (credentials in an HTTP header) and IP whitelisting (access granted to specific source IPs). The HTTP standard defines the 407 challenge-response flow: the proxy issues a 407, the client retries with a Proxy-Authorization header.

The client formats credentials as username:password, Base64-encodes the string, and sends it in the Proxy-Authorization: Basic header on every proxied request. The proxy decodes the header and checks the credentials against its user database. Incorrect or missing credentials return a 407.

Base64 is not encryption, it's reversible by anyone who intercepts the header. Basic proxy auth is safe when used over HTTPS connections (where the CONNECT tunnel encrypts traffic between client and target) or when the proxy connection itself is over a secure channel. It's not safe over unencrypted HTTP connections on untrusted networks.

Most commonly: special characters in the password that aren't percent-encoded in the URL string. Characters like @, :, and / break URL parsing. Less common: credentials are correct but the plan doesn't include access to the proxy type or region you're connecting to.

Use IP whitelisting on fixed-IP dedicated infrastructure, servers with static IPs, cloud instances with Elastic IPs, where the machine's public IP is stable and managed. Avoid it for developer machines, dynamic cloud instances, or any environment where the IP can change without notice.

Many providers support this. If your IP is whitelisted, no credentials are needed. If it's not, credentials in the request still authenticate you. This lets machines with static IPs connect without credentials while other machines use username-password auth as a fallback.


Limited-time ยท 50% off

Get 50% off your first purchase

Premium datacentre proxies with unlimited bandwidth. Use the code at checkout.

Offer ends soon โ€” claim it before it's gone

Claim Discount

About the Author

SparkProxy Technical Team writes practical proxy infrastructure guides for digital agencies, SEO professionals, e-commerce teams, and data engineers. Our guides are based on real-world proxy deployment experience across high-volume scraping, ad verification, price monitoring, and competitive intelligence use cases. SparkProxy's mission: Scrape the Web with Confidence and Anonymity.

Keep reading

Related articles

What Is a Dedicated Datacenter Proxy?

What Is a Dedicated Datacenter Proxy?

A dedicated datacenter proxy is a datacenter IP assigned to one user. Learn how exclusivity works, its reputation and pricing benefits, and when to use one.

SparkProxyยทProxy Basic
What Is an Exit Node in a Proxy Network?

What Is an Exit Node in a Proxy Network?

An exit node proxy is the last hop whose IP the target site sees. Learn how exit nodes work, why exit IP quality drives block rates, and how rotation works.

SparkProxyยทProxy Basic