This API enables you to securely store sensitive data. This data is stored in the following ways for each desktop platform.
Linux: Using the Secret Service API/libsecret
Mac: Using Keychain
Windows: Using Credential Vault
This API can be used for storing sensitive information such as access tokens or other secret credentials.
We expose a secureStorage
object with set
, get
, getAll
and remove
helper methods.
window.todesktop.secureStorage.set(identifier, value)
stores the value under the identifier given. The identifier and the value are of type string
.
If there was already a value stored at the identifier, it will be overwritten. It returns a Promise which resolves without a value.
/*Securely store the value "secret" at the identifier "SDF34FSDG"*/âawait window.todesktop.secureStorage.set("SDF34FSDG", "secret")â
window.todesktop.secureStorage.get(identifier)
returns a Promise which resolves to the stored value if the identifier exists, or undefined if it does not.
/*Get the value which is stored at the identifier "SDF34FSDG"*/âconst secret = await window.todesktop.secureStorage.get("SDF34FSDG")
window.todesktop.secureStorage.getAll()
returns a Promise which resolves to an array of { identifier, value }
objects.
This retrieves all stored values for the app. The array will be empty if there are no values stored.
const secrets = await window.todesktop.secureStorage.getAll()âconsole.log(secrets)// [// {// identifier: "SDF34FSDG",// value: "secret"// }// ]
window.todesktop.secureStorage.remove(identifier)
returns a Promise which resolves to a boolean: true if there was a value at the identifier and it was removed, false if the identifier didn't exist.
/*removes the value stored at the identifier "SDF34FSDG" if it exists*/âconst isRemoved = await window.todesktop.secureStorage.remove("SDF34FSDG")