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,
],
}),
});
})();
4条答案
按热度按时间ee7vknir1#
云函数解决方案中的JavaScript
其他语言的快速说明
原则应该是相同的:
如果您找不到SDK,也可以使用原始http请求:https://cloud.google.com/identity-platform/docs/reference/rest/v2/projects/getConfig(手动执行所有操作时,进行身份验证会比较麻烦)
pokxtpni2#
没有API可以实现这一点--你必须通过控制台来完成。如果你愿意的话,你也可以file a feature request with Firebase support。
似乎没有任何文档说明域的数量限制。同样,如果文档不清楚,请联系Firebase支持。
pkmbmrz73#
谢谢@Jean Costa
完全为我工作。
下面是C#实现
v09wglhw4#
感谢Jean Costa和Yan Naing
这是我PHP实现