alexa-cookie2 4.0.3 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/alexa-cookie.js +23 -12
- package/example/example.js +2 -1
- package/lib/proxy.js +4 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -49,6 +49,10 @@ Partly based on [Amazon Alexa Remote Control](http://blog.loetzimmer.de/2017/10/
|
|
|
49
49
|
Thank you for that work.
|
|
50
50
|
|
|
51
51
|
## Changelog:
|
|
52
|
+
### 4.1.0 (2022-07-18)
|
|
53
|
+
* (Apollon77) Allow to overwrite the used App-Name for the Amazon App Registration.
|
|
54
|
+
* (Apollon77) Include the used app name also in the response
|
|
55
|
+
|
|
52
56
|
### 4.0.3 (2022-07-06)
|
|
53
57
|
* (Apollon77) Update some request meta data to match current Alexa Apps
|
|
54
58
|
|
package/alexa-cookie.js
CHANGED
|
@@ -18,6 +18,10 @@ const defaultUserAgentLinux = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.3
|
|
|
18
18
|
//const defaultUserAgentMacOs = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
|
|
19
19
|
const defaultAcceptLanguage = 'de-DE';
|
|
20
20
|
|
|
21
|
+
const apiCallVersion = '2.2.483723.0';
|
|
22
|
+
const apiCallUserAgent = 'AmazonWebView/Amazon Alexa/2.2.483723.0/iOS/15.5/iPhone';
|
|
23
|
+
const defaultAppName = 'ioBroker Alexa2';
|
|
24
|
+
|
|
21
25
|
const csrfOptions = [
|
|
22
26
|
'/api/language',
|
|
23
27
|
'/spa/index.html',
|
|
@@ -50,8 +54,7 @@ function AlexaCookie() {
|
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
Cookie = '';
|
|
53
|
-
for (const name
|
|
54
|
-
if (!cookies.hasOwnProperty(name)) continue;
|
|
57
|
+
for (const name of Object.keys(cookies)) {
|
|
55
58
|
Cookie += name + '=' + cookies[name] + '; ';
|
|
56
59
|
}
|
|
57
60
|
Cookie = Cookie.replace(/[; ]*$/, '');
|
|
@@ -142,6 +145,9 @@ function AlexaCookie() {
|
|
|
142
145
|
_options.baseAmazonPage = _options.baseAmazonPage || 'amazon.com';
|
|
143
146
|
_options.logger && _options.logger('Alexa-Cookie: Use as Base-Amazon-URL: ' + _options.baseAmazonPage);
|
|
144
147
|
|
|
148
|
+
_options.deviceAppName = _options.deviceAppName || defaultAppName;
|
|
149
|
+
_options.logger && _options.logger('Alexa-Cookie: Use as Device-App-Name: ' + _options.deviceAppName);
|
|
150
|
+
|
|
145
151
|
if (!_options.baseAmazonPageHandle && _options.baseAmazonPageHandle !== '') {
|
|
146
152
|
const amazonDomain = _options.baseAmazonPage.substr(_options.baseAmazonPage.lastIndexOf('.') + 1);
|
|
147
153
|
if (amazonDomain === 'jp') {
|
|
@@ -204,7 +210,7 @@ function AlexaCookie() {
|
|
|
204
210
|
'method': 'GET',
|
|
205
211
|
'headers': {
|
|
206
212
|
'DNT': '1',
|
|
207
|
-
'User-Agent':
|
|
213
|
+
'User-Agent': _options.userAgent,
|
|
208
214
|
'Connection': 'keep-alive',
|
|
209
215
|
'Referer': 'https://alexa.' + _options.amazonPage + '/spa/index.html',
|
|
210
216
|
'Cookie': cookie,
|
|
@@ -390,10 +396,15 @@ function AlexaCookie() {
|
|
|
390
396
|
}
|
|
391
397
|
};
|
|
392
398
|
|
|
399
|
+
this.getDeviceAppName = () => {
|
|
400
|
+
return _options.deviceAppName || defaultAppName;
|
|
401
|
+
};
|
|
393
402
|
|
|
394
403
|
const handleTokenRegistration = (_options, loginData, callback) => {
|
|
395
404
|
_options.logger && _options.logger('Handle token registration Start: ' + JSON.stringify(loginData));
|
|
396
405
|
|
|
406
|
+
loginData.deviceAppName = _options.deviceAppName;
|
|
407
|
+
|
|
397
408
|
let deviceSerial;
|
|
398
409
|
if (!_options.formerRegistrationData || !_options.formerRegistrationData.deviceSerial) {
|
|
399
410
|
const deviceSerialBuffer = Buffer.alloc(16);
|
|
@@ -430,13 +441,13 @@ function AlexaCookie() {
|
|
|
430
441
|
},
|
|
431
442
|
'registration_data': {
|
|
432
443
|
'domain': 'Device',
|
|
433
|
-
'app_version':
|
|
444
|
+
'app_version': apiCallVersion,
|
|
434
445
|
'device_type': 'A2IVLV5VM2W81',
|
|
435
446
|
'device_name': '%FIRST_NAME%\u0027s%DUPE_STRATEGY_1ST%ioBroker Alexa2',
|
|
436
447
|
'os_version': '15.5',
|
|
437
448
|
'device_serial': deviceSerial,
|
|
438
449
|
'device_model': 'iPhone',
|
|
439
|
-
'app_name':
|
|
450
|
+
'app_name': _options.deviceAppName,
|
|
440
451
|
'software_version': '1'
|
|
441
452
|
},
|
|
442
453
|
'auth_data': {
|
|
@@ -476,7 +487,7 @@ function AlexaCookie() {
|
|
|
476
487
|
path: '/auth/register',
|
|
477
488
|
method: 'POST',
|
|
478
489
|
headers: {
|
|
479
|
-
'User-Agent':
|
|
490
|
+
'User-Agent': apiCallUserAgent,
|
|
480
491
|
'Accept-Language': _options.acceptLanguage,
|
|
481
492
|
'Accept-Charset': 'utf-8',
|
|
482
493
|
'Connection': 'keep-alive',
|
|
@@ -518,10 +529,10 @@ function AlexaCookie() {
|
|
|
518
529
|
|
|
519
530
|
const options = {
|
|
520
531
|
host: 'alexa.' + _options.baseAmazonPage,
|
|
521
|
-
path: '/api/users/me?platform=ios&version=
|
|
532
|
+
path: '/api/users/me?platform=ios&version=' + apiCallVersion,
|
|
522
533
|
method: 'GET',
|
|
523
534
|
headers: {
|
|
524
|
-
'User-Agent':
|
|
535
|
+
'User-Agent': apiCallUserAgent,
|
|
525
536
|
'Accept-Language': _options.acceptLanguage,
|
|
526
537
|
'Accept-Charset': 'utf-8',
|
|
527
538
|
'Connection': 'keep-alive',
|
|
@@ -592,7 +603,7 @@ function AlexaCookie() {
|
|
|
592
603
|
|
|
593
604
|
const exchangeParams = {
|
|
594
605
|
'di.os.name': 'iOS',
|
|
595
|
-
'app_version':
|
|
606
|
+
'app_version': apiCallVersion,
|
|
596
607
|
'domain': '.' + amazonPage,
|
|
597
608
|
'source_token': refreshToken,
|
|
598
609
|
'requested_token_type': 'auth_cookies',
|
|
@@ -608,7 +619,7 @@ function AlexaCookie() {
|
|
|
608
619
|
path: '/ap/exchangetoken',
|
|
609
620
|
method: 'POST',
|
|
610
621
|
headers: {
|
|
611
|
-
'User-Agent':
|
|
622
|
+
'User-Agent': apiCallUserAgent,
|
|
612
623
|
'Accept-Language': _options.acceptLanguage,
|
|
613
624
|
'Accept-Charset': 'utf-8',
|
|
614
625
|
'Connection': 'keep-alive',
|
|
@@ -685,7 +696,7 @@ function AlexaCookie() {
|
|
|
685
696
|
|
|
686
697
|
const refreshData = {
|
|
687
698
|
'app_name': 'ioBroker Alexa2',
|
|
688
|
-
'app_version':
|
|
699
|
+
'app_version': apiCallVersion,
|
|
689
700
|
'di.sdk.version': '6.10.0',
|
|
690
701
|
'source_token': _options.formerRegistrationData.refreshToken,
|
|
691
702
|
'package_name': 'com.amazon.echo',
|
|
@@ -703,7 +714,7 @@ function AlexaCookie() {
|
|
|
703
714
|
path: '/auth/token',
|
|
704
715
|
method: 'POST',
|
|
705
716
|
headers: {
|
|
706
|
-
'User-Agent':
|
|
717
|
+
'User-Agent': apiCallUserAgent,
|
|
707
718
|
'Accept-Language': _options.acceptLanguage,
|
|
708
719
|
'Accept-Charset': 'utf-8',
|
|
709
720
|
'Connection': 'keep-alive',
|
package/example/example.js
CHANGED
|
@@ -16,9 +16,10 @@ const config = {
|
|
|
16
16
|
proxyOwnIp: '...', // required if proxy enabled: provide own IP or hostname to later access the proxy. needed to setup all rewriting and proxy stuff internally
|
|
17
17
|
proxyPort: 3456, // optional: use this port for the proxy, default is 0 means random port is selected
|
|
18
18
|
proxyListenBind: '0.0.0.0',// optional: set this to bind the proxy to a special IP, default is '0.0.0.0'
|
|
19
|
-
proxyLogLevel: 'info',
|
|
19
|
+
proxyLogLevel: 'info', // optional: Loglevel of Proxy, default 'warn'
|
|
20
20
|
baseAmazonPage: 'amazon.com', // optional: Change the Proxy Amazon Page - all "western countries" directly use amazon.com! Change to amazon.co.jp for Japan
|
|
21
21
|
amazonPageProxyLanguage: 'de_DE', // optional: language to be used for the Amazon Sign-in page the proxy calls. default is "de_DE")
|
|
22
|
+
deviceAppName: '...', // optional: name of the device app name which will be registered with Amazon, leave empty to use a default one
|
|
22
23
|
formerDataStorePath: '...', // optional: overwrite path where some of the formerRegistrationData are persisted to optimize against Amazon security measures
|
|
23
24
|
formerRegistrationData: { ... } // optional/preferred: provide the result object from subsequent proxy usages here and some generated data will be reused for next proxy call too
|
|
24
25
|
};
|
package/lib/proxy.js
CHANGED
|
@@ -27,8 +27,7 @@ function addCookies(Cookie, headers) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
Cookie = '';
|
|
30
|
-
for (const name
|
|
31
|
-
if (!cookies.hasOwnProperty(name)) continue;
|
|
30
|
+
for (const name of Object.keys(cookies)) {
|
|
32
31
|
Cookie += name + '=' + cookies[name] + '; ';
|
|
33
32
|
}
|
|
34
33
|
Cookie = Cookie.replace(/[; ]*$/, '');
|
|
@@ -163,7 +162,7 @@ function initAmazonProxy(_options, callbackCookie, callbackListening) {
|
|
|
163
162
|
optionsAlexa.pathRewrite[`^/alexa.${_options.baseAmazonPage}`] = '';
|
|
164
163
|
optionsAlexa.cookieDomainRewrite[`.${_options.baseAmazonPage}`] = _options.proxyOwnIp;
|
|
165
164
|
optionsAlexa.cookieDomainRewrite[_options.baseAmazonPage] = _options.proxyOwnIp;
|
|
166
|
-
if (_options.logger) optionsAlexa.logProvider = function logProvider(
|
|
165
|
+
if (_options.logger) optionsAlexa.logProvider = function logProvider() {
|
|
167
166
|
return {
|
|
168
167
|
log: _options.logger.log || _options.logger,
|
|
169
168
|
debug: _options.logger.debug || _options.logger,
|
|
@@ -235,7 +234,7 @@ function initAmazonProxy(_options, callbackCookie, callbackListening) {
|
|
|
235
234
|
return data;
|
|
236
235
|
}
|
|
237
236
|
|
|
238
|
-
function onProxyReq(proxyReq, req
|
|
237
|
+
function onProxyReq(proxyReq, req/*, _res*/) {
|
|
239
238
|
const url = req.originalUrl || req.url;
|
|
240
239
|
if (url.endsWith('.ico') || url.endsWith('.js') || url.endsWith('.ttf') || url.endsWith('.svg') || url.endsWith('.png') || url.endsWith('.appcache')) return;
|
|
241
240
|
//if (url.startsWith('/ap/uedata')) return;
|
|
@@ -249,8 +248,7 @@ function initAmazonProxy(_options, callbackCookie, callbackListening) {
|
|
|
249
248
|
if (reqCookie === undefined) {
|
|
250
249
|
reqCookie = '';
|
|
251
250
|
}
|
|
252
|
-
for (const cookie
|
|
253
|
-
if (!initialCookies.hasOwnProperty(cookie)) continue;
|
|
251
|
+
for (const cookie of Object.keys(initialCookies)) {
|
|
254
252
|
if (!reqCookie.includes(cookie + '=')) {
|
|
255
253
|
reqCookie += '; ' + cookie + '=' + initialCookies[cookie];
|
|
256
254
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alexa-cookie2",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Generate Cookie and CSRF for Alexa Remote",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Apollon77",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@alcalzone/release-script": "^3.5.9",
|
|
33
33
|
"@alcalzone/release-script-plugin-license": "^3.5.9",
|
|
34
|
-
"eslint": "^8.
|
|
34
|
+
"eslint": "^8.20.0"
|
|
35
35
|
},
|
|
36
36
|
"repository": {
|
|
37
37
|
"type": "git",
|