mirror of
https://github.com/openstf/stf
synced 2025-10-04 02:09:32 +02:00
29 lines
783 B
JavaScript
29 lines
783 B
JavaScript
var jwtutil = require('../util/jwtutil')
|
|
var urlutil = require('../util/urlutil')
|
|
|
|
module.exports = function(options) {
|
|
return function(req, res, next) {
|
|
if (req.query.jwt) {
|
|
// Coming from auth client
|
|
var data = jwtutil.decode(req.query.jwt, options.secret)
|
|
, redir = urlutil.removeParam(req.url, 'jwt')
|
|
if (data) {
|
|
// Redirect once to get rid of the token
|
|
req.session.jwt = data
|
|
res.redirect(redir)
|
|
}
|
|
else {
|
|
// Invalid token, forward to auth client
|
|
res.redirect(options.authUrl)
|
|
}
|
|
}
|
|
else if (req.session && req.session.jwt) {
|
|
// Continue existing session
|
|
next()
|
|
}
|
|
else {
|
|
// No session, forward to auth client
|
|
res.redirect(options.authUrl)
|
|
}
|
|
}
|
|
}
|