1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 10:39:25 +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

View file

@ -7,6 +7,7 @@ var logger = require('../../util/logger')
var requtil = require('../../util/requtil')
var jwtutil = require('../../util/jwtutil')
var pathutil = require('../../util/pathutil')
var urlutil = require('../../util/urlutil')
module.exports = function(options) {
var log = logger.createLogger('auth-mock')
@ -59,12 +60,6 @@ module.exports = function(options) {
requtil.validate(req, function() {
req.checkBody('name').notEmpty()
req.checkBody('email').isEmail()
// This is a security risk. Someone might forward the user
// to the login page with their own redirect set, and they'd
// then be able to steal the token. Some kind of a whitelist
// or a fixed redirect URL is needed.
req.checkBody('redirect').isUrl()
})
.then(function() {
log.info('Authenticated "%s"', req.body.email)
@ -75,14 +70,12 @@ module.exports = function(options) {
}
, secret: options.secret
})
var target = url.parse(req.body.redirect)
target.query = {
jwt: token
}
res.status(200)
.json({
success: true
, redirect: url.format(target)
, redirect: urlutil.addParams(options.appUrl, {
jwt: token
})
})
})
.catch(requtil.ValidationError, function(err) {