50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
const { Controller } = require('libflitter')
|
|
|
|
class TrustController extends Controller {
|
|
static get services() {
|
|
return [...super.services, 'Vue']
|
|
}
|
|
|
|
/*
|
|
* Prompts the user to re-authenticate.
|
|
* If successful, a trust token will be issued for the specified scope.
|
|
*
|
|
* Requires req.session.trust_flow = { scope: String, next: String }
|
|
*/
|
|
async get_issue(req, res, next) {
|
|
if ( !req.trust.has_flow() )
|
|
return res.status(400).message('Missing trust flow data.').send()
|
|
|
|
// Check if the session already has a token for this scope
|
|
const has_scope = req.trust.has(req.trust.flow_scope())
|
|
|
|
// If so, redirect them to the destination
|
|
if ( has_scope ) {
|
|
return res.redirect(req.trust.end())
|
|
}
|
|
|
|
// Otherwise, show the trust prompt for re-authorization
|
|
const token = req.trust.start()
|
|
return res.page('auth:trust:grant', {
|
|
...this.Vue.data({
|
|
grant_code: token,
|
|
login_message: 'Please re-authenticate to continue.',
|
|
}),
|
|
...this.Vue.session(req)
|
|
})
|
|
}
|
|
|
|
/*async get_continue(req, res, next) {
|
|
if ( !req.trust.has_flow() )
|
|
return res.status(400).message('Missing trust flow data.')
|
|
|
|
if ( !req.trust.in_progress() )
|
|
return res.status(401).message('No flow in progress. Please try again.')
|
|
|
|
req.trust.grant(req.trust.flow_scope())
|
|
return res.redirect(req.trust.end())
|
|
}*/
|
|
}
|
|
|
|
module.exports = exports = TrustController
|