1 |
office |
1 |
#!/usr/bin/env node |
|
|
2 |
|
|
|
3 |
'use strict'; |
|
|
4 |
|
|
|
5 |
const request = require('request'); |
|
|
6 |
|
|
|
7 |
if (!process.argv[2] || !process.argv[3]) { |
|
|
8 |
console.log('Usage: npm run get-password-cloud [Gigya API Key]'); |
|
|
9 |
process.exit(); |
|
|
10 |
} |
|
|
11 |
|
|
|
12 |
const username = process.argv[2]; |
|
|
13 |
const password = process.argv[3]; |
|
|
14 |
const apiKey = process.argv[4] || process.env.GIGYA_API_KEY || '3_rWtvxmUKwgOzu3AUPTMLnM46lj-LxURGflmu5PcE_sGptTbD-wMeshVbLvYpq01K'; |
|
|
15 |
|
|
|
16 |
const gigyaLoginOptions = { |
|
|
17 |
'method': 'POST', |
|
|
18 |
'uri': 'https://accounts.us1.gigya.com/accounts.login', |
|
|
19 |
'json': true, |
|
|
20 |
'qs': { |
|
|
21 |
'apiKey': apiKey, |
|
|
22 |
'targetenv': 'mobile', |
|
|
23 |
'loginID': username, |
|
|
24 |
'password': password, |
|
|
25 |
'format': 'json', |
|
|
26 |
'targetEnv': 'mobile' |
|
|
27 |
}, |
|
|
28 |
'headers': { |
|
|
29 |
'Connection': 'close' |
|
|
30 |
} |
|
|
31 |
}; |
|
|
32 |
|
|
|
33 |
request(gigyaLoginOptions, loginGigyaResponseHandler); |
|
|
34 |
|
|
|
35 |
function loginGigyaResponseHandler (error, response, body) { |
|
|
36 |
if (error) { |
|
|
37 |
console.log('Fatal error login into Gigya API. Please check your credentials or Gigya API Key.'); |
|
|
38 |
console.log(error); |
|
|
39 |
process.exit(1); |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
if (response.statusCode === 401 || response.statusCode === 403) { |
|
|
43 |
console.log('Authentication error. Check your credentials.'); |
|
|
44 |
console.log(response); |
|
|
45 |
process.exit(1); |
|
|
46 |
} else if (response.statusCode === 400) { |
|
|
47 |
console.log(response); |
|
|
48 |
process.exit(1); |
|
|
49 |
} else if (response.statusCode === 200) { |
|
|
50 |
if (body && body.statusCode && body.statusCode === 403) { |
|
|
51 |
console.log('Authentication error. Please check your credentials.'); |
|
|
52 |
console.log(body); |
|
|
53 |
process.exit(1); |
|
|
54 |
} |
|
|
55 |
if (body && body.statusCode && body.statusCode === 400) { |
|
|
56 |
console.log('Error login into Gigya API.'); |
|
|
57 |
console.log(body); |
|
|
58 |
process.exit(1); |
|
|
59 |
} |
|
|
60 |
if (body && body.statusCode && body.statusCode === 200 && body.errorCode === 0 && body.UID && body.UIDSignature && body.signatureTimestamp && body.sessionInfo && body.sessionInfo.sessionToken) { |
|
|
61 |
const iRobotLoginOptions = { |
|
|
62 |
'method': 'POST', |
|
|
63 |
'uri': 'https://unauth2.prod.iot.irobotapi.com/v2/login', |
|
|
64 |
'json': true, |
|
|
65 |
'body': { |
|
|
66 |
'app_id': 'ANDROID-C7FB240E-DF34-42D7-AE4E-A8C17079A294', |
|
|
67 |
'assume_robot_ownership': 0, |
|
|
68 |
'gigya': { |
|
|
69 |
'signature': body.UIDSignature, |
|
|
70 |
'timestamp': body.signatureTimestamp, |
|
|
71 |
'uid': body.UID |
|
|
72 |
} |
|
|
73 |
}, |
|
|
74 |
'headers': { |
|
|
75 |
'Connection': 'close' |
|
|
76 |
} |
|
|
77 |
}; |
|
|
78 |
request(iRobotLoginOptions, loginIrobotResponseHandler); |
|
|
79 |
} else { |
|
|
80 |
console.log('Error login into iRobot account. Missing fields in login response.'); |
|
|
81 |
console.log(body); |
|
|
82 |
process.exit(1); |
|
|
83 |
} |
|
|
84 |
} else { |
|
|
85 |
console.log('Unespected response. Checking again...'); |
|
|
86 |
} |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
function loginIrobotResponseHandler (error, response, body) { |
|
|
90 |
if (error) { |
|
|
91 |
console.log('Fatal error login into iRobot account. Please check your credentials or API Key.'); |
|
|
92 |
console.log(error); |
|
|
93 |
process.exit(1); |
|
|
94 |
} |
|
|
95 |
if (body && body.robots) { |
|
|
96 |
const robotCount = Object.keys(body.robots).length; |
|
|
97 |
console.log('Found ' + robotCount + ' robot(s)!'); |
|
|
98 |
Object.keys(body.robots).map(function (r) { |
|
|
99 |
console.log('Robot "' + body.robots[r].name + '" (sku: ' + body.robots[r].sku + ' SoftwareVer: ' + body.robots[r].softwareVer + '):'); |
|
|
100 |
console.log('BLID=> ' + r); |
|
|
101 |
console.log('Password=> ' + body.robots[r].password + ' <= Yes, all this string.'); |
|
|
102 |
console.log(''); |
|
|
103 |
}); |
|
|
104 |
console.log('Use this credentials in dorita980 lib :)'); |
|
|
105 |
} else { |
|
|
106 |
console.log('Fatal error login into iRobot account. Please check your credentials or API Key.'); |
|
|
107 |
console.log(body); |
|
|
108 |
process.exit(1); |
|
|
109 |
} |
|
|
110 |
} |
|
|
111 |
|