CoreID/app/routing/middleware/auth/RequireTrust.middleware.js

16 lines
451 B
JavaScript
Raw Permalink Normal View History

2020-05-04 01:16:54 +00:00
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