Securing sensitive information in Google Apps Script can be achieved by utilizing the PropertiesService:
To safeguard the secret(s), employ a function similar to this:
function protectSecrets() {
PropertiesService.getScriptProperties().setProperties({
'secret1': 'myHighlyConfidentialPasscode',
'secret2': 'mySecureToken',
// and so on...
})
}
This function must be executed once using clasp push
in the editor (or clasp run protectSecrets
), after which you should remove it, all while avoiding any commits to version control.
Following this process, access the stored secrets in your code with something like:
let token = PropertiesService.getScriptProperties().getProperty('secret2')
Keep in mind that individuals with editing privileges to your project can still access these secrets; however, this method effectively prevents them from being exposed through version control.