Protecting some APIs with an APIKEY.

This commit is contained in:
John Livingston
2021-05-05 17:06:19 +02:00
parent 787fed19d0
commit 6b77c3585d
4 changed files with 46 additions and 4 deletions

17
server/lib/apikey.ts Normal file
View File

@ -0,0 +1,17 @@
/*
For internal API, we will generate an api Key that must be provided as
GET parameter for every API call.
*/
async function getAPIKey ({ storageManager }: RegisterServerOptions): Promise<string> {
let value: string = await storageManager.getData('APIKEY')
if (!value) {
value = Math.random().toString(36).slice(2, 12)
await storageManager.storeData('APIKEY', value)
}
return value
}
export {
getAPIKey
}