feat: generate real api key

This also hides the api key from users without the ADMIN permission. It will not be returned from
the api for them. Regenerate functionality is not in the commit.
This commit is contained in:
sct
2020-12-08 05:04:15 +00:00
parent 20769d58dd
commit a8393707fe
8 changed files with 64 additions and 40 deletions

View File

@@ -102,7 +102,7 @@ class Settings {
this.data = {
clientId: '',
main: {
apiKey: 'temp',
apiKey: '',
applicationUrl: '',
},
plex: {
@@ -144,6 +144,10 @@ class Settings {
}
get main(): MainSettings {
if (!this.data.main.apiKey) {
this.data.main.apiKey = this.generateApiKey();
this.save();
}
return this.data.main;
}
@@ -200,6 +204,16 @@ class Settings {
return this.data.clientId;
}
public regenerateApiKey(): MainSettings {
this.main.apiKey = this.generateApiKey();
this.save();
return this.main;
}
private generateApiKey(): string {
return Buffer.from(`${Date.now()}${this.clientId}`).toString('base64');
}
/**
* Settings Load
*