fixed bug not being able to discover azp

This commit is contained in:
tigerbot 2017-06-23 17:22:45 -06:00
rodzic 7a2f0f0984
commit 3ac0f3077e
4 zmienionych plików z 52 dodań i 57 usunięć

Wyświetl plik

@ -114,54 +114,6 @@ module.exports = function (myDeps, conf, overrideHttp) {
return result;
});
}
, tunnel: function (deps, session) {
// TODO save session to config and turn tunnel on
var OAUTH3 = deps.OAUTH3;
var owner = session.id;
var url = require('url');
var providerUri = session.token.aud;
var urlObj = url.parse(OAUTH3.url.normalize(session.token.azp));
var oauth3 = OAUTH3.create(urlObj, {
providerUri: providerUri
, session: session
});
return oauth3.setProvider(providerUri).then(function () {
/*
return oauth3.api('domains.list').then(function (domains) {
var domainsMap = {};
domains.forEach(function (d) {
if (!d.device) {
return;
}
if (d.device !== conf.device.hostname) {
return;
}
domainsMap[d.name] = true;
});
*/
//console.log('domains matching hostname', Object.keys(domainsMap));
//console.log('device', conf.device);
return oauth3.api('tunnel.token', {
data: {
// filter to all domains that are on this device
//domains: Object.keys(domainsMap)
device: {
hostname: conf.device.hostname
, id: conf.device.uid || conf.device.id
}
}
}).then(function (result) {
console.log('got a token from the tunnel server?');
result.owner = owner;
return deps.tunnelClients.add(result);
});
/*
});
*/
});
}
};
return require('../packages/apis/com.daplie.goldilocks').create(myDeps, conf);

Wyświetl plik

@ -66,6 +66,42 @@ module.exports.create = function (deps, config) {
}
};
function acquireToken(session) {
var OAUTH3 = deps.OAUTH3;
// session seems to be changed by the API call for some reason, so save the
// owner before that happens.
var owner = session.id;
// The OAUTH3 library stores some things on the root session object that we usually
// just leave inside the token, but we need to pull those out before we use it here
session.provider_uri = session.provider_uri || session.token.provider_uri || session.token.iss;
session.client_uri = session.client_uri || session.token.azp;
session.scope = session.scope || session.token.scp;
console.log('asking for tunnel token from', session.token.aud);
return OAUTH3.discover(session.token.aud).then(function (directives) {
var opts = {
api: 'tunnel.token'
, session: session
, data: {
// filter to all domains that are on this device
//domains: Object.keys(domainsMap)
device: {
hostname: config.device.hostname
, id: config.device.uid || config.device.id
}
}
};
console.log(directives);
return OAUTH3.api(directives.api, opts).then(function (result) {
console.log('got a token from the tunnel server?');
result.owner = owner;
return result;
});
});
}
function addToken(data) {
if (!data.tunnelUrl) {
var decoded;
@ -147,7 +183,14 @@ module.exports.create = function (deps, config) {
});
return {
add: function (data) {
start: function (session) {
return acquireToken(session).then(function (token) {
return addToken(token).then(function () {
return storage.save(token);
});
});
}
, add: function (data) {
return addToken(data).then(function () {
return storage.save(data);
});

Wyświetl plik

@ -3,8 +3,8 @@
module.exports.create = function (deps, config) {
if (!config.tunnelServer || !Array.isArray(config.tunnelServer.servernames) || !config.tunnelServer.secret) {
return {
isAdminDomain: function () { return false; },
isClientDomain: function () { return false; },
isAdminDomain: function () { return false; }
, isClientDomain: function () { return false; }
};
}
@ -50,12 +50,12 @@ module.exports.create = function (deps, config) {
return {
isAdminDomain: function (domain) {
return config.tunnelServer.servernames.indexOf(domain) !== -1;
},
handleAdminConn: function (conn) {
}
, handleAdminConn: function (conn) {
httpServer.emit('connection', conn);
},
}
isClientDomain: tunnelServer.isClientDomain,
handleClientConn: tunnelServer.tcp
, isClientDomain: tunnelServer.isClientDomain
, handleClientConn: tunnelServer.tcp
};
};

Wyświetl plik

@ -169,7 +169,7 @@ module.exports.create = function (deps, conf) {
}
return deps.storage.owners.get(req.userId).then(function (session) {
return api.tunnel(deps, session).then(function () {
return deps.tunnelClients.start(session).then(function () {
res.setHeader('Content-Type', 'application/json;');
res.end(JSON.stringify({ success: true }));
}, function (err) {