Skip to content
Snippets Groups Projects
Commit 19ae65c5 authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

if fetch of .well-known fails, then fall back to proxy_idps from the config file

parent 66c28d8f
No related branches found
No related tags found
No related merge requests found
...@@ -104,8 +104,6 @@ function parseWellKnownBody(body, domain, delegates, cb) { ...@@ -104,8 +104,6 @@ function parseWellKnownBody(body, domain, delegates, cb) {
}); });
} }
// Support "shimmed primaries" for local development. That is an environment variable that is any number of // Support "shimmed primaries" for local development. That is an environment variable that is any number of
// CSV values of the form: // CSV values of the form:
// <domain>|<origin>|<path to .well-known/browserid>, // <domain>|<origin>|<path to .well-known/browserid>,
...@@ -131,14 +129,29 @@ if (process.env['SHIMMED_PRIMARIES']) { ...@@ -131,14 +129,29 @@ if (process.env['SHIMMED_PRIMARIES']) {
} }
var getWellKnown = function (domain, delegates, cb) { var getWellKnown = function (domain, delegates, cb) {
// called when we fail to fetch well-known. Looks in configuration for proxyidp
// configuration, if that exists, it's as if a delegation of authority existed.
function handleProxyIDP() {
var proxyIDPs = config.get('proxy_idps');
if (proxyIDPs.hasOwnProperty(domain)) {
var generatedBody = JSON.stringify({
authority: proxyIDPs[domain]
});
cb(null, generatedBody, domain, delegates);
} else {
cb(null, false, null);
}
}
function handleResponse(res) { function handleResponse(res) {
if (res.statusCode !== 200) { if (res.statusCode !== 200) {
logger.debug(domain + ' is not a browserid primary - non-200 response code to ' + WELL_KNOWN_URL); logger.debug(domain + ' is not a browserid primary - non-200 response code to ' + WELL_KNOWN_URL);
return cb(null, false, null); return handleProxyIDP();
} }
if (res.headers['content-type'].indexOf('application/json') !== 0) { if (res.headers['content-type'].indexOf('application/json') !== 0) {
logger.debug(domain + ' is not a browserid primary - non "application/json" response to ' + WELL_KNOWN_URL); logger.debug(domain + ' is not a browserid primary - non "application/json" response to ' + WELL_KNOWN_URL);
return cb(null, false, null); return handleProxyIDP();
} }
var body = ""; var body = "";
...@@ -178,7 +191,7 @@ var getWellKnown = function (domain, delegates, cb) { ...@@ -178,7 +191,7 @@ var getWellKnown = function (domain, delegates, cb) {
req.on('error', function(e) { req.on('error', function(e) {
logger.debug(domain + ' is not a browserid primary: ' + e.toString()); logger.debug(domain + ' is not a browserid primary: ' + e.toString());
cb(null, false, null); handleProxyIDP();
}); });
}; };
...@@ -198,7 +211,6 @@ exports.checkSupport = function(domain, cb, delegates) { ...@@ -198,7 +211,6 @@ exports.checkSupport = function(domain, cb, delegates) {
return process.nextTick(function() { cb("invalid domain"); }); return process.nextTick(function() { cb("invalid domain"); });
} }
getWellKnown(domain, delegates, function (err, body, domain, cbdelegates) { getWellKnown(domain, delegates, function (err, body, domain, cbdelegates) {
if (err) { if (err) {
logger.debug(err); logger.debug(err);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment