Firebase中的自定义authDomain

Ste*_*ili 7 firebase firebase-authentication

我正在将Firebase的内置oAuth功能用于SPA。

例如,此SPA属于自己的域名 foobar.com

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

我的init看起来像这样

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

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

 code: "auth/popup-closed-by-user", message: "The popup has been closed by the user before finalizing the operation."}
Run Code Online (Sandbox Code Playgroud)

简而言之,有没有一种方法可以自定义Firebase的oAuth网址?

Mic*_*igh 7

authDomain依赖于特定的脚本在该域可用。如果您的Single-Page App通过自定义域托管在Firebase Hosting上,则可以将该域用作authDomain

或者,您可以在域的子域上为Firebase Hosting设置自定义域,例如auth.foobar.com,然后您就可以将其auth.foobar.com用作authDomain

当前不支持将非Firebase托管域用作authDomain


kip*_*ip2 7

我在Google OAuth 2 授权中看到了很多答案- 错误:redirect_uri_mismatch指出需要设置自定义域授权、检查 HTTP/S URI 方案等(我遵循了其中的大部分内容,包括确保我的自定义域是在 Firebase 托管、Firebase 身份验证甚至 GCP 身份平台“授权域”设置下授权 ( https://console.cloud.google.com/customer-identity/settings?project=\ <your-gcp-project-id> )也就是说,所有链接的答案似乎都不是 Firebase Auth 特有的,所以这是我的经验,FWIW:

以下Authorisation Error消息显示在“使用 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}
Run Code Online (Sandbox Code Playgroud)

经过大量挖掘,我意识到我需要将“授权重定向 URI”的值设置为https://<my-auth-subdomain>.mydomain.org/__/auth/handler,引用我的自定义域。请参阅以下附件。

OAuth 客户端 ID 设置 Google API 凭据设置

这对我来说并不是很明显,但我还必须对 Google 服务自动生成的 OAuth 2.0 客户端 ID 进行上述设置。按照这个相关的答案,我最初创建了一个新的客户端 ID,它最终没有任何区别。

  • 你节省了我很多时间! (4认同)