A PostgreSQL-backed cache provider for @node-saml/passport-saml.
$ npm install passport-saml-cache-postgres
Create a passport_saml_cache
table in your database. The default schema can be found in schema.sql.
import { Strategy as SamlStrategy } from '@node-saml/passport-saml'
import postgresCacheProvider from 'passport-saml-cache-postgres'
passport.use(new SamlStrategy({
... other passport-saml options,
cacheProvider: postgresCacheProvider(pool) // A pg.Pool object
}))
The postgresCacheProvider
function accepts an optional second argument. The default options are as follows:
postgresCacheProvider(pool, {
// The maximum age of a cache entry in milliseconds. Entries older than this are deleted automatically.
// A scheduled job deletes old cache entries every `ttlMillis` milliseconds.
ttlMillis: 1000 * 60 * 60, // 1 hour,
// A logger to use. By default, messages are logged to console.
// The logger should support at least `logger.info()` and `logger.error()` methods.
logger: console,
})
The cache can be closed by calling the .close()
-method. This stops the
scheduled job that periodically clears stale cache entries.