RIFT-14989: Login fixes for Accounts and RO Config pages
[osm/UI.git] / skyquake / framework / core / api_utils / utils.js
index 163769a..bd99fe1 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   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.
 module.exports = {
        /**
         * Ensure confd port is on api_server variable.
@@ -233,5 +261,7 @@ module.exports = {
 
        sendSuccessResponse: sendSuccessResponse,
 
 
        sendSuccessResponse: sendSuccessResponse,
 
-       passThroughConstructor: passThroughConstructor
+    passThroughConstructor: passThroughConstructor,
+
+    testAuthentication: testAuthentication
 };
 };