diff --git a/src/oauth.js b/src/oauth.js index 5892026..a6cb8a7 100644 --- a/src/oauth.js +++ b/src/oauth.js @@ -12,7 +12,6 @@ const debug = { } const wellKnownObject = {} -let wellKnownTimeoutId module.exports = async function (clientId, clientSecret, options) { const byuJwt = ByuJwt(options) @@ -188,14 +187,15 @@ async function getTokenEndpoints (wellKnown) { } // set cache timeout - wellKnownTimeoutId = setTimeout(() => { + // NOTE: added 'unref' to allow scripts to finish when not running package within a server + setTimeout(() => { debug.wellKnown('cache expired') getTokenEndpoints(wellKnown) .catch(err => { debug.wellKnown('unable to refresh well known information') console.error(err.stack) }) - }, cacheDuration * 1000) + }, cacheDuration * 1000).unref() } function revoke (context, token, type) { @@ -209,9 +209,3 @@ function revoke (context, token, type) { url: context.revocationEndpoint }) } - -process.on('exit', () => clearTimeout(wellKnownTimeoutId)) // app is closing -process.on('SIGINT', () => clearTimeout(wellKnownTimeoutId)) // catches ctrl+c event -process.on('SIGBREAK', () => clearTimeout(wellKnownTimeoutId)) // catches Windows ctrl+c event -process.on('SIGUSR1', () => clearTimeout(wellKnownTimeoutId)) // catches "kill pid" -process.on('SIGUSR2', () => clearTimeout(wellKnownTimeoutId)) // catches "kill pid"