-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
37 lines (30 loc) · 1012 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const request = require('request');
class Login {
constructor(config, stuff) {
this.config = config;
this.logger = stuff.logger;
}
authenticate(user, password, callback) {
const self = this;
const autenticacao = 'Basic '+ Buffer.from(':' + password).toString('base64');
const options = {
method: 'GET',
url: `https://${self.config.account}.vsaex.visualstudio.com/_apis/userentitlementsummary`,
qs: { select: 'projects' },
headers: { Authorization: autenticacao, Accept: 'application/json' }
};
return request(options, function (error, response, body) {
if (error || !body) return callback(error || 'body empty');
try {
const objJson = JSON.parse(body);
const ids = objJson.projectRefs.map((array)=>{
return array.id;
});
return callback(null,ids)
} catch (erro) {
return callback(erro);
}
});
}
}
module.exports = (...args) => new Login(...args);