2012-05-17 00:58:40 +04:00
|
|
|
/* This is code to allow one instance of 123done.org to run against
|
|
|
|
* all browserid environments - production, staging, development, and
|
|
|
|
* ephemeral testing deployments.
|
|
|
|
*
|
|
|
|
* The details of this code aren't very important, but what it basically
|
|
|
|
* does is populate res.persona_url with the appropriate url based on the
|
|
|
|
* Host headers sent with the request.
|
|
|
|
*/
|
|
|
|
var url = require('url'),
|
2015-12-11 21:51:45 +03:00
|
|
|
crypto = require('crypto');
|
2012-05-17 00:58:40 +04:00
|
|
|
|
|
|
|
var pp = require('postprocess')(function(req, buf) {
|
2012-10-11 05:04:10 +04:00
|
|
|
var re = new RegExp('https://login.persona.org', 'g');
|
2012-05-17 00:58:40 +04:00
|
|
|
return buf.replace(re, req.persona_url);
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = function(req, res, next) {
|
|
|
|
// determine the URL of the browserid deployment we'll use
|
|
|
|
req.headers.host = req.headers.host || '123done.org';
|
|
|
|
var host = req.headers.host.split(':')[0].toString();
|
2015-12-11 21:51:45 +03:00
|
|
|
if (process.env['PERSONA_URL']) {
|
|
|
|
req.persona_url = process.env['PERSONA_URL'];
|
|
|
|
} else if (host === 'www.123done.org') {
|
|
|
|
req.persona_url = 'https://login.persona.org';
|
|
|
|
} else if (host === 'beta.123done.org') {
|
|
|
|
req.persona_url = 'https://login.anosrep.org';
|
|
|
|
} else if (host === 'dev.123done.org') {
|
|
|
|
req.persona_url = 'https://login.dev.anosrep.org';
|
|
|
|
} else if (host === 'firefoxos.123done.org') {
|
|
|
|
req.persona_url = 'https://firefoxos.persona.org';
|
|
|
|
} else if (host === 'ffxosproxy.123done.org') {
|
|
|
|
req.persona_url = 'https://ffxosproxy.persona.org';
|
|
|
|
} else if (/\.123done\.org$/.test(host)) {
|
2012-06-13 13:39:11 +04:00
|
|
|
req.persona_url = 'https://' + host.substr(0, host.length - 12) + '.personatest.org';
|
2012-05-17 00:58:40 +04:00
|
|
|
} else {
|
2012-10-11 05:04:10 +04:00
|
|
|
req.persona_url = 'https://login.persona.org';
|
2012-05-17 00:58:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// concoct a unique identifier for the (virtual) instance
|
|
|
|
// of 123done being hit
|
|
|
|
var hash = crypto.createHash('md5');
|
|
|
|
hash.update(req.headers.host);
|
|
|
|
req.deployment_id = hash.digest('hex').slice(0, 6);
|
|
|
|
|
|
|
|
// and determine the hostname of the verifier
|
|
|
|
req.verifier_host = url.parse(req.persona_url).hostname;
|
|
|
|
|
|
|
|
pp(req, res, next);
|
|
|
|
};
|