CoreID/app/routing/middleware/auth/RequireTrust.middleware.js
2020-05-03 20:16:54 -05:00

16 lines
451 B
JavaScript

const { Middleware } = require('libflitter')
class RequireTrustMiddleware extends Middleware {
async test(req, res, next, { scope, deplete = false }) {
if ( !req.trust.has(scope) ) {
req.trust.init_flow(scope, req.originalUrl)
return res.redirect('/auth/trust/token/issue')
}
if ( deplete ) req.trust.deplete(scope)
return next()
}
}
module.exports = exports = RequireTrustMiddleware