alexa-cookie2 4.0.2 → 4.1.1

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 CHANGED
@@ -49,6 +49,16 @@ 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.1 (2022-07-18)
53
+ * (Apollon77/bbindreiter) Update used User-Agent for some requests
54
+
55
+ ### 4.1.0 (2022-07-18)
56
+ * (Apollon77) Allow to overwrite the used App-Name for the Amazon App Registration.
57
+ * (Apollon77) Include the used app name also in the response
58
+
59
+ ### 4.0.3 (2022-07-06)
60
+ * (Apollon77) Update some request meta data to match current Alexa Apps
61
+
52
62
  ### 4.0.2 (2022-06-30)
53
63
  * (Apollon77) Prevent potential crash cases
54
64
 
package/alexa-cookie.js CHANGED
@@ -13,11 +13,15 @@ const cookieTools = require('cookie');
13
13
  const amazonProxy = require('./lib/proxy.js');
14
14
 
15
15
  const defaultAmazonPage = 'amazon.de';
16
- const defaultUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0';
17
- const defaultUserAgentLinux = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36';
16
+ const defaultUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36';
17
+ const defaultUserAgentLinux = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36';
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 in cookies) {
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': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
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': '2.2.443692.0',
444
+ 'app_version': apiCallVersion,
434
445
  'device_type': 'A2IVLV5VM2W81',
435
446
  'device_name': '%FIRST_NAME%\u0027s%DUPE_STRATEGY_1ST%ioBroker Alexa2',
436
- 'os_version': '14.8',
447
+ 'os_version': '15.5',
437
448
  'device_serial': deviceSerial,
438
449
  'device_model': 'iPhone',
439
- 'app_name': 'ioBroker Alexa2',
450
+ 'app_name': _options.deviceAppName,
440
451
  'software_version': '1'
441
452
  },
442
453
  'auth_data': {
@@ -464,8 +475,7 @@ function AlexaCookie() {
464
475
  'client_domain' : 'DeviceLegacy'
465
476
  };
466
477
  }
467
- for (const key in cookies) {
468
- if (!cookies.hasOwnProperty(key)) continue;
478
+ for (const key of Object.keys(cookies)) {
469
479
  registerData.cookies.website_cookies.push({
470
480
  'Value': cookies[key],
471
481
  'Name': key
@@ -477,7 +487,7 @@ function AlexaCookie() {
477
487
  path: '/auth/register',
478
488
  method: 'POST',
479
489
  headers: {
480
- 'User-Agent': 'AmazonWebView/Amazon Alexa/2.2.443692.0/iOS/14.8/iPhone',
490
+ 'User-Agent': apiCallUserAgent,
481
491
  'Accept-Language': _options.acceptLanguage,
482
492
  'Accept-Charset': 'utf-8',
483
493
  'Connection': 'keep-alive',
@@ -519,10 +529,10 @@ function AlexaCookie() {
519
529
 
520
530
  const options = {
521
531
  host: 'alexa.' + _options.baseAmazonPage,
522
- path: '/api/users/me?platform=ios&version=2.2.443692.0',
532
+ path: '/api/users/me?platform=ios&version=' + apiCallVersion,
523
533
  method: 'GET',
524
534
  headers: {
525
- 'User-Agent': 'AmazonWebView/Amazon Alexa/2.2.443692.0/iOS/14.8/iPhone',
535
+ 'User-Agent': apiCallUserAgent,
526
536
  'Accept-Language': _options.acceptLanguage,
527
537
  'Accept-Charset': 'utf-8',
528
538
  'Connection': 'keep-alive',
@@ -593,7 +603,7 @@ function AlexaCookie() {
593
603
 
594
604
  const exchangeParams = {
595
605
  'di.os.name': 'iOS',
596
- 'app_version': '2.2.443692.0',
606
+ 'app_version': apiCallVersion,
597
607
  'domain': '.' + amazonPage,
598
608
  'source_token': refreshToken,
599
609
  'requested_token_type': 'auth_cookies',
@@ -609,7 +619,7 @@ function AlexaCookie() {
609
619
  path: '/ap/exchangetoken',
610
620
  method: 'POST',
611
621
  headers: {
612
- 'User-Agent': 'AmazonWebView/Amazon Alexa/2.2.443692.0/iOS/14.8/iPhone',
622
+ 'User-Agent': apiCallUserAgent,
613
623
  'Accept-Language': _options.acceptLanguage,
614
624
  'Accept-Charset': 'utf-8',
615
625
  'Connection': 'keep-alive',
@@ -658,8 +668,7 @@ function AlexaCookie() {
658
668
 
659
669
  });
660
670
  let localCookie = '';
661
- for (const name in cookies) {
662
- if (!cookies.hasOwnProperty(name)) continue;
671
+ for (const name of Object.keys(cookies)) {
663
672
  localCookie += name + '=' + cookies[name] + '; ';
664
673
  }
665
674
  localCookie = localCookie.replace(/[; ]*$/, '');
@@ -687,7 +696,7 @@ function AlexaCookie() {
687
696
 
688
697
  const refreshData = {
689
698
  'app_name': 'ioBroker Alexa2',
690
- 'app_version': '2.2.443692.0',
699
+ 'app_version': apiCallVersion,
691
700
  'di.sdk.version': '6.10.0',
692
701
  'source_token': _options.formerRegistrationData.refreshToken,
693
702
  'package_name': 'com.amazon.echo',
@@ -705,7 +714,7 @@ function AlexaCookie() {
705
714
  path: '/auth/token',
706
715
  method: 'POST',
707
716
  headers: {
708
- 'User-Agent': 'AmazonWebView/Amazon Alexa/2.2.443692.0/iOS/14.8/iPhone',
717
+ 'User-Agent': apiCallUserAgent,
709
718
  'Accept-Language': _options.acceptLanguage,
710
719
  'Accept-Charset': 'utf-8',
711
720
  'Connection': 'keep-alive',
@@ -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', // optional: Loglevel of Proxy, default 'warn'
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 in cookies) {
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(_provider) {
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, _res) {
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 in initialCookies) {
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.2",
3
+ "version": "4.1.1",
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.18.0"
34
+ "eslint": "^8.20.0"
35
35
  },
36
36
  "repository": {
37
37
  "type": "git",