X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FUI.git;a=blobdiff_plain;f=skyquake%2Fframework%2Fcore%2Fapi_utils%2Futils.js;h=bd99fe1a9a8924f37b77d330068b9e4af5a29213;hp=163769a981b7038bec09dad021e4e39b8c944a1f;hb=b78fbe20fd7d976b3e15abb2387b4e329a5ea918;hpb=3a0a737a065670c4928fe841941aa9c4f4d02a56 diff --git a/skyquake/framework/core/api_utils/utils.js b/skyquake/framework/core/api_utils/utils.js index 163769a98..bd99fe1a9 100644 --- a/skyquake/framework/core/api_utils/utils.js +++ b/skyquake/framework/core/api_utils/utils.js @@ -1,5 +1,5 @@ /* - * + * * Copyright 2016 RIFT.IO Inc * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -217,6 +217,34 @@ var passThroughConstructor = function(app) { }); } + +var testAuthentication = function(app) { + app.get('/check-auth', function(req, res) { + console.log('testing auth') + var api_server = req.query["api_server"]; + var uri = confdPort(api_server) + '/api/config/'; + new Promise(function(resolve, reject) { + request({ + uri: uri, + method: 'GET', + headers: _.extend({}, CONSTANTS.HTTP_HEADERS.accept[type], { + 'Authorization': req.get('Authorization'), + forever: CONSTANTS.FOREVER_ON, + rejectUnauthorized: false, + }) + }, function(error, response, body) { + if (validateResponse('Passthrough: ' + url, error, response, body, resolve, reject)) { + resolve(JSON.parse(response.body)) + }; + }); + }).then(function(data) { + res.send(data); + }, function(error) { + res.send({'error': error, uri: uri}) + });; + }) +} + module.exports = { /** * Ensure confd port is on api_server variable. @@ -233,5 +261,7 @@ module.exports = { sendSuccessResponse: sendSuccessResponse, - passThroughConstructor: passThroughConstructor + passThroughConstructor: passThroughConstructor, + + testAuthentication: testAuthentication };