dam*_*gzi 9 firebase firebase-authentication
只是想检查一下,是否有任何 API 可以以编程方式添加授权域,而不是通过 Firebase 控制台手动添加?
另外,添加为授权域的域数量是否有限制?
import { google } from "googleapis";
(async () => {
/**
* ! START - Update Firebase allowed domains
*/
// Change this to whatever you want
const URL_TO_ADD = "engineering.acme-corp.net";
// Acquire an auth client, and bind it to all future calls
const auth = new google.auth.GoogleAuth({
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
});
const authClient = await auth.getClient();
google.options({ auth: authClient });
// Get the Identity Toolkit API client
const idToolkit = google.identitytoolkit("v3").relyingparty;
/**
* When calling the methods from the Identity Toolkit API, we are
* overriding the default target URLs and payloads (that interact
* with the v3 endpoint) so we can talk to the v2 endpoint, which is
* what Firebase Console uses.
*/
// Generate the request URL
const projectId = await auth.getProjectId();
const idToolkitConfigUrl = `https://identitytoolkit.googleapis.com/admin/v2/projects/${projectId}/config`;
// Get current config so we can use it when we later update it
const currentConfig = await idToolkit.getProjectConfig(undefined, {
url: idToolkitConfigUrl,
method: "GET",
});
// Update the config based on the values that already exist
await idToolkit.setProjectConfig(undefined, {
url: idToolkitConfigUrl,
method: "PATCH",
params: { updateMask: "authorizedDomains" },
body: JSON.stringify({
authorizedDomains: [
...(currentConfig.data.authorizedDomains || []),
URL_TO_ADD,
],
}),
});
})();
Run Code Online (Sandbox Code Playgroud)
原则应该是相同的:
如果您找不到 SDK,您还可以使用原始 http 请求: https: //cloud.google.com/identity-platform/docs/reference/rest/v2/projects/getConfig(这有点棘手手动执行所有操作时进行身份验证)
没有用于此目的的 API - 您必须通过控制台来完成此操作。如果需要,您还可以向 Firebase 支持人员提交功能请求。
似乎没有任何文档说明域数量的限制。如果文档不清楚,请再次联系 Firebase 支持。
| 归档时间: |
|
| 查看次数: |
1874 次 |
| 最近记录: |