Skip to content

Instantly share code, notes, and snippets.

@torresalmonte
Last active July 6, 2022 19:50
Show Gist options
  • Save torresalmonte/f1c10e22bc8ac282febdb49ed7d7a438 to your computer and use it in GitHub Desktop.
Save torresalmonte/f1c10e22bc8ac282febdb49ed7d7a438 to your computer and use it in GitHub Desktop.
const admin = require('firebase-admin');
// expects the environment variable GOOGLE_APPLICATION_CREDENTIALS
const serviceAccount = require(process.env.GOOGLE_APPLICATION_CREDENTIALS);
const credential = admin.credential.cert(serviceAccount);
const PROJECT_ID = '<FIREBASE_PROJECT_ID>';
const app = admin.initializeApp({
credential: credential
});
// example of how to use the REST API
// https://cloud.google.com/identity-platform/docs/reference/rest/v2/projects/updateConfig
(async () => {
let response = await getConfig();
console.log(JSON.stringify(response, null, 4));
console.log("--------------------------------------------------------");
console.log("updating 'notification.sendEmail.resetPasswordTemplate.bodyFormat'");
console.log("--------------------------------------------------------");
response = await updateConfig();
console.log(JSON.stringify(response, null, 4));
process.exit(0);
})();
// ----------------------------
// ------ functions
// ----------------------------
async function getAccessToken () {
let googleOAuthAccessToken = await credential.getAccessToken();
return googleOAuthAccessToken.access_token;
} // getAccessToken
async function getConfig () {
let accessToken = await getAccessToken();
let request = {
url: `https://identitytoolkit.googleapis.com/admin/v2/projects/${PROJECT_ID}/config`,
headers: {
'Authorization': `Bearer ${accessToken}`
},
method: 'GET'
}
let response = await app.INTERNAL.credential_.httpClient.send(request);
return response;
} // getConfig
async function updateConfig (uid) {
let accessToken = await getAccessToken();
let Config = {
notification: {
sendEmail: {
resetPasswordTemplate: {
bodyFormat: "HTML"
}
}
}
};
let queryParams = `updateMask=notification.sendEmail.resetPasswordTemplate.bodyFormat`;
// testing
//let queryParams = `updateMask=notification.sendEmail.verifyEmailTemplate.bodyFormat`;
let request = {
url: `https://identitytoolkit.googleapis.com/admin/v2/projects/${PROJECT_ID}/config?${queryParams}`,
data: Config,
headers: {
'Authorization': `Bearer ${accessToken}`
},
method: 'PATCH'
}
let response = await app.INTERNAL.credential_.httpClient.send(request);
return response;
} // updateConfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment