alicezetion 1.8.9 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +69 -288
- package/leiamnash/listenMqtt.js +2 -1
- package/package.json +1 -2
- package/utils.js +1382 -1334
- package/leiamnash/token.js +0 -112
package/leiamnash/token.js
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var utils = require('../utils');
|
4
|
-
var log = require('npmlog');
|
5
|
-
|
6
|
-
module.exports = function (http, api, ctx) {
|
7
|
-
return function getAccess(authCode = '', callback) {
|
8
|
-
var cb;
|
9
|
-
var url = 'https://business.facebook.com/';
|
10
|
-
var Referer = url + 'security/twofactor/reauth/?twofac_next=' + encodeURIComponent(url + 'content_management') + '&type=avoid_bypass&app_id=0&save_device=0';
|
11
|
-
var rt = new Promise(function (resolve, reject) {
|
12
|
-
cb = (error, token) => token ? resolve(token) : reject(error);
|
13
|
-
});
|
14
|
-
|
15
|
-
if (typeof authCode == 'function') {
|
16
|
-
callback = authCode;
|
17
|
-
authCode = '';
|
18
|
-
}
|
19
|
-
if (typeof callback == 'function') cb = callback;
|
20
|
-
if (!!ctx.access_token)
|
21
|
-
cb(null, ctx.access_token);
|
22
|
-
else
|
23
|
-
utils
|
24
|
-
.get(url + 'content_management', ctx.jar, null, ctx.globalOptions, null, {
|
25
|
-
noRef: true,
|
26
|
-
Origin: url
|
27
|
-
})
|
28
|
-
.then(function (res) {
|
29
|
-
var html = res.body;
|
30
|
-
var lsd = utils.getFrom(html, "[\"LSD\",[],{\"token\":\"", "\"}");
|
31
|
-
return lsd;
|
32
|
-
})
|
33
|
-
.then(function (lsd) {
|
34
|
-
function submitCode(code) {
|
35
|
-
var pCb;
|
36
|
-
var rtPromise = new Promise(function (resolve) {
|
37
|
-
pCb = (error, token) => resolve(cb(error, token));
|
38
|
-
});
|
39
|
-
if (typeof code != 'string')
|
40
|
-
pCb({
|
41
|
-
error: 'submitCode',
|
42
|
-
lerror: 'code must be string',
|
43
|
-
continue: submitCode
|
44
|
-
});
|
45
|
-
else
|
46
|
-
http
|
47
|
-
.post(url + 'security/twofactor/reauth/enter/', ctx.jar, {
|
48
|
-
approvals_code: code,
|
49
|
-
save_device: true,
|
50
|
-
lsd
|
51
|
-
}, ctx.globalOptions, null, {
|
52
|
-
Referer,
|
53
|
-
Origin: url
|
54
|
-
})
|
55
|
-
.then(function (res) {
|
56
|
-
var { payload } = JSON.parse(res.body.split(';').pop() || '{}');
|
57
|
-
if (payload && !payload.codeConfirmed)
|
58
|
-
throw {
|
59
|
-
error: 'submitCode',
|
60
|
-
lerror: payload.message,
|
61
|
-
continue: submitCode
|
62
|
-
}
|
63
|
-
|
64
|
-
return;
|
65
|
-
})
|
66
|
-
.then(function () {
|
67
|
-
return utils
|
68
|
-
.get(url + 'content_management', ctx.jar, null, ctx.globalOptions, null, { noRef: true })
|
69
|
-
.then(function (res) {
|
70
|
-
var html = res.body;
|
71
|
-
var token = /"accessToken":"(\S+)","clientID":/g.exec(html);
|
72
|
-
|
73
|
-
return [html, token];
|
74
|
-
});
|
75
|
-
})
|
76
|
-
.then(function (res) {
|
77
|
-
if (!res[1])
|
78
|
-
throw {
|
79
|
-
error: 'token-undefined',
|
80
|
-
htmlData: res[0]
|
81
|
-
}
|
82
|
-
ctx.access_token = res[1][1];
|
83
|
-
return pCb(null, res[1][1]);
|
84
|
-
})
|
85
|
-
.catch(function (err) {
|
86
|
-
log.error('getAccess', err.error || err);
|
87
|
-
return pCb(err);
|
88
|
-
});
|
89
|
-
|
90
|
-
return rtPromise;
|
91
|
-
}
|
92
|
-
|
93
|
-
if (authCode.length == 6 && !isNaN(authCode))
|
94
|
-
submitCode(authCode.toString());
|
95
|
-
else if (typeof callback == 'function')
|
96
|
-
throw {
|
97
|
-
error: 'submitCode',
|
98
|
-
continue: submitCode
|
99
|
-
}
|
100
|
-
else
|
101
|
-
throw {
|
102
|
-
error: 'authentication code must be string or number or callback must be a function to continue'
|
103
|
-
}
|
104
|
-
})
|
105
|
-
.catch(function (err) {
|
106
|
-
log.error('getAccess', typeof callback == 'function' ? (err.error || err) : err);
|
107
|
-
return cb(err);
|
108
|
-
});
|
109
|
-
|
110
|
-
return rt;
|
111
|
-
}
|
112
|
-
}
|