2020-12-10 08:32:40 -05:00
|
|
|
const { callbackify, promisify } = require('util')
|
|
|
|
const JWT = require('jsonwebtoken')
|
2021-07-07 05:38:56 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2020-12-10 08:32:40 -05:00
|
|
|
|
|
|
|
const jwtSign = promisify(JWT.sign)
|
|
|
|
|
|
|
|
async function sign(payload, options = {}) {
|
|
|
|
const key = Settings.jwt.key
|
|
|
|
const algorithm = Settings.jwt.algorithm
|
|
|
|
if (!key || !algorithm) {
|
|
|
|
throw new Error('missing JWT configuration')
|
|
|
|
}
|
|
|
|
const token = await jwtSign(payload, key, { ...options, algorithm })
|
|
|
|
return token
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
sign: callbackify(sign),
|
|
|
|
promises: {
|
2021-04-27 03:52:58 -04:00
|
|
|
sign,
|
|
|
|
},
|
2020-12-10 08:32:40 -05:00
|
|
|
}
|