Back to all articles
Cloudflare

Using Cloudflare Workers to Optimize Auth0 Universal Login

Nate Totten
·
October 19, 2022
·
1 min read

Use Cloudflare Workers to force Auth0 to use a single connection for every authorization request.

October 19, 2022

Auth0 is still one of the best ways to add authorization to your app. However, one minor annoyance I have found is that there is no way to force every login to use a single identity provider (i.e. connection) without configuring each client with the connection parameter. So even for an app that only allows users to login with a single social connection (i.e. Google) users will still see the Auth0 login picker by default.

Auth0 login picker

With Cloudflare Workers and an Auth0 custom domain it is easy to fix this issue. After you setup your custom domain, you need to make sure you are proxying the CNAME through Cloudflare.

Cloudflare CNAME

Next, create a simple Cloudflare Worker with the following code.

TypeScriptts
export default {
  async fetch(request, env) {
    return await handleRequest(request);
  },
};

const AUTH0_CONNECTION = "my-connection";

async function handleRequest(request) {
  const url = new URL(request.url);
  // Checking path just in case, but this
  // worker should only run on this path
  if (url.pathname === "/authorize") {
    if (url.searchParams.get("connection")) {
      return fetch(request);
    } else {
      url.searchParams.set("connection", AUTH0_CONNECTION);
      const newRequest = new Request(url.toString(), new Request(request));
      return fetch(newRequest);
    }
  }
  return fetch(request);
}

Finally, configure a Route for the Cloudflare worker to run on the /authorize path. The route should look like this: my-cname.example.com/authorize*. Make sure to put the * at the end; otherwise, requests with the query parameters will not be sent to the worker.

Cloudflare worker routes configuration

When a request comes to the regular /authorize URL to start an OAuth flow, the connection query parameter is added automatically. Every user will skip the Auth0 login page and immediately go to the login page of the specified connection.

One word of caution, I am unsure if Auth0 supports this configuration. It works for me, but Auth0 could make changes that break this at some point.

Hopefully, this helps solve a minor annoyance you might have with Auth0.

Related Articles

Continue reading from the Zuplo blog.

API Monetization 101

API Monetization 101: Your Guide to Charging for Your API

A three-part series on API monetization: what to count, how to structure plans, and how to decide what to charge. Start here for the full picture.

4 min read
API Monetization 101

Use AI to Plan Your API Pricing Strategy

Get clear tiers, a comparison table, and reasoning so you can price your API with confidence and move on to implementation faster.

3 min read

Scale your APIs with
confidence.

Start for free or book a demo with our team.
Book a demoStart for Free
SOC 2 TYPE 2High Performer Spring 2025Momentum Leader Spring 2025Best Estimated ROI Spring 2025Easiest To Use Spring 2025Fastest Implementation Spring 2025

Get Updates From Zuplo

Zuplo logo
© 2026 zuplo. All rights reserved.
Products & Features
API ManagementAI GatewayMCP ServersMCP GatewayDeveloper PortalRate LimitingOpenAPI NativeGitOpsProgrammableAPI Key ManagementMulti-cloudAPI GovernanceMonetizationSelf-Serve DevX
Developers
DocumentationBlogLearning CenterCommunityChangelogIntegrations
Product
PricingSupportSign InCustomer Stories
Company
About UsMedia KitCareersStatusTrust & Compliance
Privacy PolicySecurity PoliciesTerms of ServiceTrust & Compliance
Docs
Pricing
Sign Up
Login
ContactBook a demoFAQ
Zuplo logo
DocsPricingSign Up
Login