1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 10:19:30 +02:00

Make app work with login.

This commit is contained in:
Simo Kinnunen 2014-01-27 15:38:40 +09:00
parent d8ca15d002
commit f2066b35fa
15 changed files with 237 additions and 26 deletions

29
lib/middleware/jwt.js Normal file
View file

@ -0,0 +1,29 @@
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)
}
}
}