Ability to define auth timeout (#82)

This commit is contained in:
Simon J
2021-12-02 14:24:44 +11:00
committed by GitHub
parent d1300b8119
commit 8a0140b728
4 changed files with 15 additions and 2 deletions

View File

@@ -145,6 +145,7 @@ item | default value | description
BNB_PORT | 4534 | Default http port for bonob to listen on BNB_PORT | 4534 | Default http port for bonob to listen on
BNB_URL | http://$(hostname):4534 | URL (including path) for bonob so that sonos devices can communicate. **This must be either the public IP or DNS entry of the bonob instance so that the sonos devices can communicate with it.** BNB_URL | http://$(hostname):4534 | URL (including path) for bonob so that sonos devices can communicate. **This must be either the public IP or DNS entry of the bonob instance so that the sonos devices can communicate with it.**
BNB_SECRET | bonob | secret used for encrypting credentials BNB_SECRET | bonob | secret used for encrypting credentials
BNB_AUTH_TIMEOUT | 1h | Timeout for the sonos auth token, described in the format [ms](https://github.com/vercel/ms), ie. '5s' == 5 seconds, '11h' == 11 hours. In the case of using Navidrome this should be less than the value for ND_SESSIONTIMEOUT
BNB_SONOS_AUTO_REGISTER | false | Whether or not to try and auto-register on startup BNB_SONOS_AUTO_REGISTER | false | Whether or not to try and auto-register on startup
BNB_SONOS_DEVICE_DISCOVERY | true | Enable/Disable sonos device discovery entirely. Setting this to 'false' will disable sonos device search, regardless of whether a seed host is specified. BNB_SONOS_DEVICE_DISCOVERY | true | Enable/Disable sonos device discovery entirely. Setting this to 'false' will disable sonos device search, regardless of whether a seed host is specified.
BNB_SONOS_SEED_HOST | undefined | sonos device seed host for discovery, or ommitted for for auto-discovery BNB_SONOS_SEED_HOST | undefined | sonos device seed host for discovery, or ommitted for for auto-discovery

View File

@@ -21,7 +21,7 @@ import { JWTSmapiLoginTokens } from "./smapi_auth";
const config = readConfig(); const config = readConfig();
const clock = SystemClock; const clock = SystemClock;
logger.info(`Starting bonob with config ${JSON.stringify(config)}`); logger.info(`Starting bonob with config ${JSON.stringify({ ...config, secret: "*******" })}`);
const bonob = bonobService( const bonob = bonobService(
config.sonos.serviceName, config.sonos.serviceName,
@@ -89,7 +89,7 @@ const app = server(
applyContextPath: true, applyContextPath: true,
logRequests: true, logRequests: true,
version, version,
smapiAuthTokens: new JWTSmapiLoginTokens(clock, config.secret, '1h'), smapiAuthTokens: new JWTSmapiLoginTokens(clock, config.secret, config.authTimeout),
externalImageResolver: artistImageFetcher externalImageResolver: artistImageFetcher
} }
); );

View File

@@ -63,6 +63,7 @@ export default function () {
port, port,
bonobUrl: url(bonobUrl), bonobUrl: url(bonobUrl),
secret: bnbEnvVar("SECRET", { default: "bonob" })!, secret: bnbEnvVar("SECRET", { default: "bonob" })!,
authTimeout: bnbEnvVar("AUTH_TIMEOUT", { default: "1h" })!,
icons: { icons: {
foregroundColor: bnbEnvVar("ICON_FOREGROUND_COLOR", { foregroundColor: bnbEnvVar("ICON_FOREGROUND_COLOR", {
validationPattern: COLOR, validationPattern: COLOR,

View File

@@ -262,6 +262,17 @@ describe("config", () => {
}); });
}); });
describe("authTimeout", () => {
it("should default to 1h", () => {
expect(config().authTimeout).toEqual("1h");
});
it(`should be overridable using BNB_AUTH_TIMEOUT`, () => {
process.env["BNB_AUTH_TIMEOUT"] = "33s";
expect(config().authTimeout).toEqual("33s");
});
});
describe("sonos", () => { describe("sonos", () => {
describe("serviceName", () => { describe("serviceName", () => {
it("should default to bonob", () => { it("should default to bonob", () => {