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.

Jun 2, 2026 - 11:10
Jun 2, 2026 - 11:10
 3
How Proxy Authentication Works
How Proxy Authentication Works
  • What Is Proxy Authentication?

    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

    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

    1. Proxy → Client: HTTP/1.1 407 Proxy Authentication Required

    Proxy-Authenticate: Basic realm="SparkProxy"

    1. Client → Proxy: GET http://example.com/ HTTP/1.1

    Host: example.com

    Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==

    1. Proxy → Target: Forwards authenticated request
    2. Target → Proxy: Response
    3. 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==

    1. Proxy → Client: HTTP/1.1 200 Connection Established
    1. Client → Target: (TLS handshake through the tunnel)
    2. 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.

  • 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:

      ```

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

      ```

      username:password → Base64 → dXNlcm5hbWU6cGFzc3dvcmQ=

      ```

      Full header:

      ```http

      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:[email protected]: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:

      | Scenario | What Happens |

      |----------|-------------|

      | DHCP lease renewal | Machine gets a new public IP — whitelist entry is stale |

      | VPN connection or disconnection | Egress IP changes — requests immediately fail with 407 |

      | Cloud instance restart | New instance may get a different Elastic IP or shared NAT IP |

      | Mobile or cellular connection | Carrier-grade NAT gives you a different IP per session |

      | Multiple machines needing access | Requires 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://@proxy.example.com:10000

    ```

    As a Bearer token in headers:

    ```http

    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

    | Attribute | Username-Password | IP Whitelisting | Token-Based |

    |-----------|------------------|-----------------|-------------|

    | Credential location | HTTP header (Base64) | No credential in request | HTTP header or URL |

    | Works from any IP | ✓ Yes | ✗ No — fixed IP required | ✓ Yes |

    | Silent failure risk | Low — 407 on wrong password | High — IP changes silently | Low — expired token gives 407 |

    | Setup complexity | Low | Medium (manage IP list) | Low to medium |

    | Multi-machine support | ✓ Same credentials | ✗ Each IP whitelisted separately | ✓ Same or separate tokens |

    | Credential exposure risk | Present (Base64 reversible) | None (no credential) | Present (token in URL/header) |

    | Rotate without downtime | ✓ With overlap period | N/A | ✓ Token swap |

    | Best for | Most production scraping | Fixed-IP dedicated servers | API-integrated or CI/CD workflows |


  • How to Configure Proxy Auth in Your Stack

    • Python requests

      ```python

      import requests

      proxies = {

      "http": "http://username:[email protected]:10000",

      "https": "http://username:[email protected]: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.

    • Python requests with environment variables (recommended)

      ```python

      import os

      import requests

      proxy_user = os.environ["PROXY_USER"]

      proxy_pass = os.environ["PROXY_PASS"]

      proxy_host = "gateway.sparkproxy.io:10000"

      proxies = {

      "http": f"http://{proxy_user}:{proxy_pass}@{proxy_host}",

      "https": f"http://{proxy_user}:{proxy_pass}@{proxy_host}",

      }

      ```

      Never hardcode credentials in source files. Store them as environment variables and reference them at runtime.

    • curl

      ```bash

      curl --proxy http://username:[email protected]:10000 \

      https://httpbin.org/ip

      ```

      Or using the --proxy-user flag:

      ```bash

      curl --proxy gateway.sparkproxy.io:10000 \

      --proxy-user "username:password" \

      https://httpbin.org/ip

      ```

    • Scrapy

      In settings.py:

      ```python

      HTTPPROXY_AUTH_ENCODING = "latin-1"

      Or use PROXY middleware:

      DOWNLOADER_MIDDLEWARES = {

      "scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware": 110,

      }

      PROXY = "http://username:[email protected]:10000"

      ```

    • Playwright (Python)

      ```python

      from playwright.sync_api import sync_playwright

      with sync_playwright() as p:

      browser = p.chromium.launch(

      proxy={

      "server": "http://gateway.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

    | Error | Likely Cause | Fix |

    |-------|-------------|-----|

    | 407 Proxy Authentication Required | Credentials missing, wrong, or IP not whitelisted | Check credentials or whitelist your current IP |

    | 407 with valid credentials | Username/password correct but special characters in password not URL-encoded | Percent-encode special chars: @%40, :%3A |

    | 407 from IP whitelist | Source 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 region | Check plan permissions in dashboard |

    | Connection refused | Wrong proxy host or port | Verify host/port string — common mistake is using HTTP port on SOCKS endpoint |

    | SSL/TLS error through proxy | Library trying to verify proxy cert instead of tunneling | Ensure 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:[email protected]:10000

    Correct — special chars encoded

    http://user:p%40ss%[email protected]: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.


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