You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase signInWithRedirect反向代理后无法重定向问题排查

Firebase Auth signInWithRedirect 重定向失败问题排查

问题场景

在阻止第三方存储的浏览器中使用signInWithRedirect,已将Firebase反向代理到自定义域名www.my-domain.com,应用托管在自有服务器(未使用Firebase Hosting)。登录跳转时正确指向https://www.my-domain.com/__/auth/handler?apiKey={api}&redirectUrl=my-domain.com/login.html,但登录后无法重定向回发起页,停留在该链接并显示Firebase的“Site Not Found”页面。

疑问解答及修复方案

1. Apache反向代理配置是否允许URL参数?

当前配置存在路径映射错误:默认会传递URL参数,但路径转发逻辑有误——你的配置将/__/auth路径转发到Firebase域名的根路径,导致/__/auth/handler会被转发到https://project-id.firebaseapp.com/handler(Firebase无此路径,因此返回404)。

修正后的配置:

SSLProxyEngine On

<Location /__/auth>
    ProxyPass https://project-id.firebaseapp.com/__/auth
    ProxyPassReverse https://project-id.firebaseapp.com/__/auth
</Location>

或添加尾部斜杠以避免路径拼接问题:

SSLProxyEngine On

<Location /__/auth/>
    ProxyPass https://project-id.firebaseapp.com/__/auth/
    ProxyPassReverse https://project-id.firebaseapp.com/__/auth/
</Location>

同时确保Apache已启用mod_proxy、mod_proxy_http和mod_ssl模块,可通过a2enmod proxy proxy_http ssl命令启用(Debian/Ubuntu系适用)。

2. Firebase配置的authDomain是否应设为www.my-domain.com?

是,必须将Firebase初始化配置中的authDomain设置为www.my-domain.com,这样Firebase Auth才能识别自定义域名的代理路径,正确处理认证流程。

3. Google Cloud中授权重定向URI设为https://www.my-domain.com/__/auth/handler是否正确?

正确,该URI是代理后的回调地址,Google登录完成后会跳转至此,符合配置要求。

额外排查点

  • 检查redirectUrl参数:发起登录时的redirectUrl必须是完整的HTTPS URL(如https://www.my-domain.com/login.html),而非仅域名+路径,避免Firebase无法解析正确的跳转目标。
  • Firebase授权域配置:在Firebase控制台的「Auth → 登录方法 → 授权域」中添加www.my-domain.com,确保该域名被允许参与认证流程。
  • 查看Apache错误日志:通过日志(通常在/var/log/apache2/error.log)检查代理请求是否有报错(如404或转发失败信息),定位具体问题。

内容的提问来源于stack exchange,提问作者kelsheikh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 18:22:36