提问者:小点点

Firebase中的自定义authDomain


我使用Firebase的内置oAuth特性来做SPA。

这个SPA在它自己的域上,比如 foobar.com

问题是,当打开oauth弹出窗口时,将使用旧的foobar.firebaseapp.com域,而不是新的foobar.com

我的初始化看起来像这样

firebase.initializeApp({
  apiKey: '...',
  authDomain: 'foobar.firebaseapp.com',
  databaseURL: 'https://foobar.firebaseio.com',
  storageBucket: 'foobar.appspot.com',
  messagingSenderId: '123456'
})

我猜,authDomain可能与它有关,但如果我将其更改为foobar.com,我会得到错误:

 code: "auth/popup-closed-by-user", message: "The popup has been closed by the user before finalizing the operation."}

简而言之,我缺少一种方法来自定义Firebase的oAuth网址?


共3个答案

匿名用户

我在Google OAuth 2授权中看到了很多答案-错误:redirect_uri_mismatch,指出需要设置自定义域授权、检查HTTP/S uri方案等(我已经遵循了其中的大多数,包括确保我的自定义域在Firebase托管、Firebase身份验证,甚至在GCP Identity Platform“授权域”设置下获得授权(https://console.cloud.google.com/customer-identity/settings?project=\

以下< code >授权错误消息出现在“使用Google登录”弹出窗口中:

Error 400: redirect_uri_mismatch
The redirect URI in the request, https://<project-id>.firebaseapp.com/__/auth/handler, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/${your_client_id}?project=${your_project_number}

经过大量挖掘,我意识到我需要将“授权重定向URI”的值设置为https://

这对我来说不是很明显,但我还必须对由Google Service自动生成的OAuth 2.0客户端ID进行上述设置。根据这个相关的回答,我最初创建了一个新的客户端ID,但最终没有产生任何影响。

匿名用户

AuthDomain依赖于该域上可用的特定脚本。如果您的单页应用程序托管在具有自定义域的Firebase主机上,您将能够将该域用作AuthDomain

或者,您可以在您的域的子域(例如auth.foobar.com)上为Firebase托管设置自定义域,然后您就可以使用auth.foobar.com作为您的AuthDomain

目前不支持使用非Firebase托管域作为您的< code>authDomain

匿名用户

转到身份验证--