allow loopback to use providers that are not oauth3.org
This commit is contained in:
parent
f37730c97d
commit
a4aad3184a
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports.create = function () {
|
module.exports.create = function (deps) {
|
||||||
var PromiseA = require('bluebird');
|
var PromiseA = require('bluebird');
|
||||||
var request = PromiseA.promisify(require('request'));
|
var request = PromiseA.promisify(require('request'));
|
||||||
var pending = {};
|
var pending = {};
|
||||||
|
@ -8,7 +8,7 @@ module.exports.create = function () {
|
||||||
function checkPublicAddr(host) {
|
function checkPublicAddr(host) {
|
||||||
return request({
|
return request({
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
, url: 'https://'+host+'/api/org.oauth3.tunnel/checkip'
|
, url: host+'/api/org.oauth3.tunnel/checkip'
|
||||||
, json: true
|
, json: true
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
if (!result.body) {
|
if (!result.body) {
|
||||||
|
@ -18,7 +18,6 @@ module.exports.create = function () {
|
||||||
var err = new Error(result.body.error.message);
|
var err = new Error(result.body.error.message);
|
||||||
return PromiseA.reject(Object.assign(err, result.body.error));
|
return PromiseA.reject(Object.assign(err, result.body.error));
|
||||||
}
|
}
|
||||||
console.log(result.body, result.body.address);
|
|
||||||
return result.body.address;
|
return result.body.address;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -39,7 +38,7 @@ module.exports.create = function () {
|
||||||
|
|
||||||
return request({
|
return request({
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
, url: 'https://'+host+'/api/org.oauth3.tunnel/loopback'
|
, url: host+'/api/org.oauth3.tunnel/loopback'
|
||||||
, json: opts
|
, json: opts
|
||||||
})
|
})
|
||||||
.then(function (result) {
|
.then(function (result) {
|
||||||
|
@ -60,26 +59,22 @@ module.exports.create = function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loopback(session) {
|
function loopback(provider) {
|
||||||
var host;
|
return deps.OAUTH3.discover(provider).then(function (directives) {
|
||||||
if (!session) {
|
return checkPublicAddr(directives.api).then(function (address) {
|
||||||
host = 'api.oauth3.org';
|
console.log('checking to see if', address, 'gets back to us');
|
||||||
} else {
|
var ports = require('./servers').listeners.tcp.list();
|
||||||
host = 'api.' + ((session.token || {}).aud || 'oauth3.org');
|
return PromiseA.all(ports.map(function (port) {
|
||||||
}
|
return checkSinglePort(directives.api, address, port);
|
||||||
|
}))
|
||||||
return checkPublicAddr(host).then(function (address) {
|
.then(function (values) {
|
||||||
console.log('checking to see if', address, 'gets back to us');
|
console.log(pending);
|
||||||
var ports = require('./servers').listeners.tcp.list();
|
var result = {error: null, address: address};
|
||||||
return PromiseA.all(ports.map(function (port) {
|
ports.forEach(function (port, ind) {
|
||||||
return checkSinglePort(host, address, port);
|
result[port] = values[ind];
|
||||||
}))
|
});
|
||||||
.then(function (values) {
|
return result;
|
||||||
var result = {error: null, address: address};
|
|
||||||
ports.forEach(function (port, ind) {
|
|
||||||
result[port] = values[ind];
|
|
||||||
});
|
});
|
||||||
return result;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,9 +313,18 @@ module.exports.create = function (deps, conf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isAuthorized(req, res, function () {
|
isAuthorized(req, res, function () {
|
||||||
|
var prom;
|
||||||
|
var query = require('querystring').parse(require('url').parse(req.url).query);
|
||||||
|
if (query.provider) {
|
||||||
|
prom = deps.loopback(query.provider);
|
||||||
|
} else {
|
||||||
|
prom = deps.storage.owners.get(req.userId).then(function (session) {
|
||||||
|
return deps.loopback(session.token.aud);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.setHeader('Content-Type', 'application/json');
|
||||||
deps.loopback()
|
prom.then(function (result) {
|
||||||
.then(function (result) {
|
|
||||||
res.end(JSON.stringify(result));
|
res.end(JSON.stringify(result));
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
res.end(JSON.stringify({error: {message: err.message, code: err.code}}));
|
res.end(JSON.stringify({error: {message: err.message, code: err.code}}));
|
||||||
|
|
Loading…
Reference in New Issue