Firebase Authentication Authorized Domain Constraints Without Wildcards
0 reputation · 18 Sept 2021, 23:45 UTC
0 reputation · 18 Sept 2021, 23:45 UTC
A Firebase project using OAuth redirect or popup sign-in succeeds on localhost because Firebase implicitly authorizes localhost for development, but production origins must appear in the Authentication Authorized Domains list. The list does not support wildcard entries, so ephemeral preview URLs, regional subdomains, or multi-tenant hosts require explicit enumeration. Default Hosting domains are pre-authorized and custom Hosting domains are generally added automatically, yet origins outside Hosting such as Cloud Run or external load balancers require manual entry. Adding a domain applies project-wide across every app sharing the project.
Because custom auth domains require verified DNS records and SSL certificates, a team must decide whether to adopt a single verified custom auth domain to centralize redirects and reduce list churn, or to keep manually enumerating each production and preview domain and accept the operational overhead. An unverified or misconfigured auth domain can break redirects even when the origin domain is authorized.
Firebase Authentication does not accept wildcard entries in Authorized Domains. Every browser origin that starts a sign-in flow must be listed. A custom auth domain is a different control: it stabilizes the redirect handler, but it does not automatically authorize arbitrary application origins.
The documented behavior does not define a numeric break-even. The likely explanation is operational: enumerate while the number of distinct origins is small and stable. Move toward a single verified auth domain when preview deployments create frequent new origins, when multiple teams can forget an entry, or when a failed sign-in is more expensive than DNS/certificate upkeep. As a heuristic, more than roughly five to ten changing production/preview origins usually makes centralization worthwhile, but treat that as a planning threshold, not a Firebase limit.
There is no supported wildcard substitute. The practical pattern is to keep one stable sign-in origin or one stable auth domain and pass environment/tenant context through OAuth state or application routing. Per-PR subdomains under a parent you control still require enumeration unless the sign-in flow is redirected through a stable origin. For multi-tenant hosts, prefer a shared auth domain and tenant resolution by path/state over enumerating tenant hostnames.
auth/unauthorized-domain is Firebase-side: the current browser origin is not in Authentication > Authorized domains. redirect_uri_mismatch is provider-side: the redirect URI derived from your Firebase authDomain does not match an authorized redirect URI in the provider's OAuth client. Adding the origin fixes the first; correcting authDomain, DNS/SSL, or the provider redirect URI fixes the second.
firebase auth:domains:list
dig +short CNAME auth.example.com
openssl s_client -connect auth.example.com:443 -servername auth.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates
Assumption: current Firebase console/CLI behavior; confirm the exact domain maximum and automatic Hosting additions in your project because these can change. One diagnostic would change the recommendation: whether preview origins are subdomains of one parent you control or unrelated hosts.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.