1 | var request = require('request');
|
2 | var Promise = require('bluebird');
|
3 | var evoke = require('./evoke');
|
4 | var log = require('./log');
|
5 |
|
6 | module.exports = {
|
7 | check: function(domo){
|
8 | return new Promise(function(resolve, reject){
|
9 | var options = {
|
10 | url: 'https://' + domo.instance + '/auth/validate',
|
11 | method: 'GET'
|
12 | };
|
13 |
|
14 | domo.processRequest(options)
|
15 | .then(function(res) {
|
16 | try{
|
17 | var isValid = JSON.parse(res.body).isValid;
|
18 | if(isValid){
|
19 | resolve(true);
|
20 | }
|
21 | else {
|
22 | reject(false);
|
23 | }
|
24 | }
|
25 | catch(e){
|
26 |
|
27 |
|
28 | resolve(true);
|
29 | }
|
30 | })
|
31 | .catch(evoke(log.clientRequestFailed, 'Not authenticated'));
|
32 | });
|
33 | }
|
34 | }
|