chore(xo-server/authentication): parseDuration in constructor
This commit is contained in:
parent
1d3978ce2f
commit
92cf6bb887
@ -14,8 +14,10 @@ const log = createLogger('xo:authentification')
|
|||||||
const noSuchAuthenticationToken = id => noSuchObject(id, 'authenticationToken')
|
const noSuchAuthenticationToken = id => noSuchObject(id, 'authenticationToken')
|
||||||
|
|
||||||
export default class {
|
export default class {
|
||||||
constructor(xo, config) {
|
constructor(xo, { authentication: config }) {
|
||||||
this._config = config.authentication
|
this._defaultTokenValidity = parseDuration(config.defaultTokenValidity)
|
||||||
|
this._maxTokenValidity = parseDuration(config.maxTokenValidity)
|
||||||
|
|
||||||
this._providers = new Set()
|
this._providers = new Set()
|
||||||
this._xo = xo
|
this._xo = xo
|
||||||
|
|
||||||
@ -158,11 +160,11 @@ export default class {
|
|||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
|
|
||||||
async createAuthenticationToken({ expiresIn = this._config.defaultTokenValidity, userId }) {
|
async createAuthenticationToken({ expiresIn = this._defaultTokenValidity, userId }) {
|
||||||
const token = new Token({
|
const token = new Token({
|
||||||
id: await generateToken(),
|
id: await generateToken(),
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
expiration: Date.now() + Math.min(parseDuration(expiresIn), parseDuration(this._config.maxTokenValidity)),
|
expiration: Date.now() + Math.min(expiresIn, this._maxTokenValidity),
|
||||||
})
|
})
|
||||||
|
|
||||||
await this._tokens.add(token)
|
await this._tokens.add(token)
|
||||||
|
Loading…
Reference in New Issue
Block a user