alexa-cookie2 4.1.0 → 4.1.3

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,17 @@ 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.3 (2022-08-03)
53
+ * (Apollon77) Fix device registration and token exchange in other regions
54
+ * (Apollon77) Use the chosen App name also for refreshing of tokens
55
+ * (Apollon77) General updates
56
+
57
+ ### 4.1.2 (2022-07-19)
58
+ * (Apollon77) Prevent crash case
59
+
60
+ ### 4.1.1 (2022-07-18)
61
+ * (Apollon77/bbindreiter) Update used User-Agent for some requests
62
+
52
63
  ### 4.1.0 (2022-07-18)
53
64
  * (Apollon77) Allow to overwrite the used App-Name for the Amazon App Registration.
54
65
  * (Apollon77) Include the used app name also in the response
package/alexa-cookie.js CHANGED
@@ -13,13 +13,13 @@ 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';
21
+ const apiCallVersion = '2.2.485407.0';
22
+ const apiCallUserAgent = 'AmazonWebView/Amazon Alexa/2.2.485407.0/iOS/15.5/iPhone';
23
23
  const defaultAppName = 'ioBroker Alexa2';
24
24
 
25
25
  const csrfOptions = [
@@ -46,23 +46,23 @@ function AlexaCookie() {
46
46
  if (cookie && cookie.length === 3) {
47
47
  if (cookie[1] === 'ap-fid' && cookie[2] === '""') continue;
48
48
  if (cookies[cookie[1]] && cookies[cookie[1]] !== cookie[2]) {
49
- _options.logger && _options.logger('Alexa-Cookie: Update Cookie ' + cookie[1] + ' = ' + cookie[2]);
49
+ _options.logger && _options.logger(`Alexa-Cookie: Update Cookie ${cookie[1]} = ${cookie[2]}`);
50
50
  } else if (!cookies[cookie[1]]) {
51
- _options.logger && _options.logger('Alexa-Cookie: Add Cookie ' + cookie[1] + ' = ' + cookie[2]);
51
+ _options.logger && _options.logger(`Alexa-Cookie: Add Cookie ${cookie[1]} = ${cookie[2]}`);
52
52
  }
53
53
  cookies[cookie[1]] = cookie[2];
54
54
  }
55
55
  }
56
56
  Cookie = '';
57
57
  for (const name of Object.keys(cookies)) {
58
- Cookie += name + '=' + cookies[name] + '; ';
58
+ Cookie += `${name}=${cookies[name]}; `;
59
59
  }
60
60
  Cookie = Cookie.replace(/[; ]*$/, '');
61
61
  return Cookie;
62
62
  };
63
63
 
64
64
  const request = (options, info, callback) => {
65
- _options.logger && _options.logger('Alexa-Cookie: Sending Request with ' + JSON.stringify(options));
65
+ _options.logger && _options.logger(`Alexa-Cookie: Sending Request with ${JSON.stringify(options)}`);
66
66
  if (typeof info === 'function') {
67
67
  callback = info;
68
68
  info = {
@@ -84,7 +84,7 @@ function AlexaCookie() {
84
84
  info.requests.push({options: options, response: res});
85
85
 
86
86
  if (options.followRedirects !== false && res.statusCode >= 300 && res.statusCode < 400) {
87
- _options.logger && _options.logger('Alexa-Cookie: Response (' + res.statusCode + ')' + (res.headers.location ? ' - Redirect to ' + res.headers.location : ''));
87
+ _options.logger && _options.logger(`Alexa-Cookie: Response (${res.statusCode})${res.headers.location ? ` - Redirect to ${res.headers.location}` : ''}`);
88
88
  //options.url = res.headers.location;
89
89
  const u = url.parse(res.headers.location);
90
90
  if (u.host) options.host = u.host;
@@ -96,7 +96,7 @@ function AlexaCookie() {
96
96
  res.socket && res.socket.end();
97
97
  return request(options, info, callback);
98
98
  } else {
99
- _options.logger && _options.logger('Alexa-Cookie: Response (' + res.statusCode + ')');
99
+ _options.logger && _options.logger(`Alexa-Cookie: Response (${res.statusCode})`);
100
100
  res.on('data', (chunk) => {
101
101
  body += chunk;
102
102
  });
@@ -140,18 +140,18 @@ function AlexaCookie() {
140
140
  _options.amazonPage = _options.amazonPage || defaultAmazonPage;
141
141
  if (_options.formerRegistrationData && _options.formerRegistrationData.amazonPage) _options.amazonPage = _options.formerRegistrationData.amazonPage;
142
142
 
143
- _options.logger && _options.logger('Alexa-Cookie: Use as Login-Amazon-URL: ' + _options.amazonPage);
143
+ _options.logger && _options.logger(`Alexa-Cookie: Use as Login-Amazon-URL: ${_options.amazonPage}`);
144
144
 
145
145
  _options.baseAmazonPage = _options.baseAmazonPage || 'amazon.com';
146
- _options.logger && _options.logger('Alexa-Cookie: Use as Base-Amazon-URL: ' + _options.baseAmazonPage);
146
+ _options.logger && _options.logger(`Alexa-Cookie: Use as Base-Amazon-URL: ${_options.baseAmazonPage}`);
147
147
 
148
148
  _options.deviceAppName = _options.deviceAppName || defaultAppName;
149
- _options.logger && _options.logger('Alexa-Cookie: Use as Device-App-Name: ' + _options.deviceAppName);
149
+ _options.logger && _options.logger(`Alexa-Cookie: Use as Device-App-Name: ${_options.deviceAppName}`);
150
150
 
151
151
  if (!_options.baseAmazonPageHandle && _options.baseAmazonPageHandle !== '') {
152
152
  const amazonDomain = _options.baseAmazonPage.substr(_options.baseAmazonPage.lastIndexOf('.') + 1);
153
153
  if (amazonDomain === 'jp') {
154
- _options.baseAmazonPageHandle = '_' + amazonDomain;
154
+ _options.baseAmazonPageHandle = `_${amazonDomain}`;
155
155
  }
156
156
  else if (amazonDomain !== 'com') {
157
157
  //_options.baseAmazonPageHandle = '_' + amazonDomain;
@@ -174,10 +174,10 @@ function AlexaCookie() {
174
174
  _options.userAgent = defaultUserAgentLinux;
175
175
  }
176
176
  }
177
- _options.logger && _options.logger('Alexa-Cookie: Use as User-Agent: ' + _options.userAgent);
177
+ _options.logger && _options.logger(`Alexa-Cookie: Use as User-Agent: ${_options.userAgent}`);
178
178
 
179
179
  _options.acceptLanguage = _options.acceptLanguage || defaultAcceptLanguage;
180
- _options.logger && _options.logger('Alexa-Cookie: Use as Accept-Language: ' + _options.acceptLanguage);
180
+ _options.logger && _options.logger(`Alexa-Cookie: Use as Accept-Language: ${_options.acceptLanguage}`);
181
181
 
182
182
  if (_options.setupProxy && !_options.proxyOwnIp) {
183
183
  _options.logger && _options.logger('Alexa-Cookie: Own-IP Setting missing for Proxy. Disabling!');
@@ -187,7 +187,7 @@ function AlexaCookie() {
187
187
  _options.setupProxy = true;
188
188
  _options.proxyPort = _options.proxyPort || 0;
189
189
  _options.proxyListenBind = _options.proxyListenBind || '0.0.0.0';
190
- _options.logger && _options.logger('Alexa-Cookie: Proxy-Mode enabled if needed: ' + _options.proxyOwnIp + ':' + _options.proxyPort + ' to listen on ' + _options.proxyListenBind);
190
+ _options.logger && _options.logger(`Alexa-Cookie: Proxy-Mode enabled if needed: ${_options.proxyOwnIp}:${_options.proxyPort} to listen on ${_options.proxyListenBind}`);
191
191
  } else {
192
192
  _options.setupProxy = false;
193
193
  _options.logger && _options.logger('Alexa-Cookie: Proxy mode disabled');
@@ -205,26 +205,26 @@ function AlexaCookie() {
205
205
  function csrfTry() {
206
206
  const path = csrfUrls.shift();
207
207
  const options = {
208
- 'host': 'alexa.' + _options.amazonPage,
208
+ 'host': `alexa.${_options.amazonPage}`,
209
209
  'path': path,
210
210
  'method': 'GET',
211
211
  'headers': {
212
212
  'DNT': '1',
213
213
  'User-Agent': _options.userAgent,
214
214
  'Connection': 'keep-alive',
215
- 'Referer': 'https://alexa.' + _options.amazonPage + '/spa/index.html',
215
+ 'Referer': `https://alexa.${_options.amazonPage}/spa/index.html`,
216
216
  'Cookie': cookie,
217
217
  'Accept': '*/*',
218
- 'Origin': 'https://alexa.' + _options.amazonPage
218
+ 'Origin': `https://alexa.${_options.amazonPage}`
219
219
  }
220
220
  };
221
221
 
222
- _options.logger && _options.logger('Alexa-Cookie: Step 4: get CSRF via ' + path);
222
+ _options.logger && _options.logger(`Alexa-Cookie: Step 4: get CSRF via ${path}`);
223
223
  request(options, (error, response) => {
224
224
  cookie = addCookies(cookie, response ? response.headers : null);
225
225
  const ar = /csrf=([^;]+)/.exec(cookie);
226
226
  const csrf = ar ? ar[1] : undefined;
227
- _options.logger && _options.logger('Alexa-Cookie: Result: csrf=' + csrf + ', Cookie=' + cookie);
227
+ _options.logger && _options.logger(`Alexa-Cookie: Result: csrf=${csrf}, Cookie=${cookie}`);
228
228
  if (!csrf && csrfUrls.length) {
229
229
  csrfTry();
230
230
  return;
@@ -268,7 +268,7 @@ function AlexaCookie() {
268
268
  if (!_options.proxyOnly) {
269
269
  // get first cookie and write redirection target into referer
270
270
  const options = {
271
- host: 'alexa.' + _options.amazonPage,
271
+ host: `alexa.${_options.amazonPage}`,
272
272
  path: '',
273
273
  method: 'GET',
274
274
  headers: {
@@ -291,7 +291,7 @@ function AlexaCookie() {
291
291
  // login empty to generate session
292
292
  Cookie = addCookies(Cookie, response.headers);
293
293
  const options = {
294
- host: 'www.' + _options.amazonPage,
294
+ host: `www.${_options.amazonPage}`,
295
295
  path: '/ap/signin',
296
296
  method: 'POST',
297
297
  headers: {
@@ -301,7 +301,7 @@ function AlexaCookie() {
301
301
  'Accept-Language': _options.acceptLanguage,
302
302
  'Connection': 'keep-alive',
303
303
  'Content-Type': 'application/x-www-form-urlencoded',
304
- 'Referer': 'https://' + lastRequestOptions.host + lastRequestOptions.path,
304
+ 'Referer': `https://${lastRequestOptions.host}${lastRequestOptions.path}`,
305
305
  'Cookie': Cookie,
306
306
  'Accept': '*/*'
307
307
  },
@@ -317,7 +317,7 @@ function AlexaCookie() {
317
317
 
318
318
  // login with filled out form
319
319
  // !!! referer now contains session in URL
320
- options.host = 'www.' + _options.amazonPage;
320
+ options.host = `www.${_options.amazonPage}`;
321
321
  options.path = '/ap/signin';
322
322
  options.method = 'POST';
323
323
  options.headers.Cookie = Cookie = addCookies(Cookie, response.headers);
@@ -397,11 +397,11 @@ function AlexaCookie() {
397
397
  };
398
398
 
399
399
  this.getDeviceAppName = () => {
400
- return _options.deviceAppName || defaultAppName;
400
+ return (_options && _options.deviceAppName) || defaultAppName;
401
401
  };
402
402
 
403
403
  const handleTokenRegistration = (_options, loginData, callback) => {
404
- _options.logger && _options.logger('Handle token registration Start: ' + JSON.stringify(loginData));
404
+ _options.logger && _options.logger(`Handle token registration Start: ${JSON.stringify(loginData)}`);
405
405
 
406
406
  loginData.deviceAppName = _options.deviceAppName;
407
407
 
@@ -437,7 +437,7 @@ function AlexaCookie() {
437
437
  "Name": "session-id-time"
438
438
  }*/
439
439
  ],
440
- 'domain': '.' + _options.baseAmazonPage
440
+ 'domain': `.${_options.baseAmazonPage}`
441
441
  },
442
442
  'registration_data': {
443
443
  'domain': 'Device',
@@ -483,7 +483,7 @@ function AlexaCookie() {
483
483
  }
484
484
 
485
485
  const options = {
486
- host: 'api.' + _options.baseAmazonPage,
486
+ host: `api.${_options.baseAmazonPage}`,
487
487
  path: '/auth/register',
488
488
  method: 'POST',
489
489
  headers: {
@@ -494,7 +494,7 @@ function AlexaCookie() {
494
494
  'Content-Type': 'application/json',
495
495
  'Cookie': loginData.loginCookie,
496
496
  'Accept': 'application/json',
497
- 'x-amzn-identity-auth-domain': 'api.' + _options.baseAmazonPage
497
+ 'x-amzn-identity-auth-domain': `api.${_options.baseAmazonPage}`
498
498
  },
499
499
  body: JSON.stringify(registerData)
500
500
  };
@@ -508,11 +508,11 @@ function AlexaCookie() {
508
508
  try {
509
509
  if (typeof body !== 'object') body = JSON.parse(body);
510
510
  } catch (err) {
511
- _options.logger && _options.logger('Register App Response: ' + JSON.stringify(body));
511
+ _options.logger && _options.logger(`Register App Response: ${JSON.stringify(body)}`);
512
512
  callback && callback(err, null);
513
513
  return;
514
514
  }
515
- _options.logger && _options.logger('Register App Response: ' + JSON.stringify(body));
515
+ _options.logger && _options.logger(`Register App Response: ${JSON.stringify(body)}`);
516
516
 
517
517
  if (!body.response || !body.response.success || !body.response.success.tokens || !body.response.success.tokens.bearer) {
518
518
  callback && callback(new Error('No tokens in Register response'), null);
@@ -523,13 +523,21 @@ function AlexaCookie() {
523
523
  loginData.tokenDate = Date.now();
524
524
  loginData.macDms = body.response.success.tokens.mac_dms;
525
525
 
526
+ if (body.response.success.tokens.website_cookies && Array.isArray(body.response.success.tokens.website_cookies)) {
527
+ const newCookies = [];
528
+ body.response.success.tokens.website_cookies.forEach(cookie => {
529
+ newCookies.push(`${cookie.Name}=${cookie.Value};`);
530
+ });
531
+ Cookie = addCookies(Cookie, {'set-cookie': newCookies});
532
+ }
533
+
526
534
  /*
527
535
  Get Amazon Marketplace Country
528
536
  */
529
537
 
530
538
  const options = {
531
- host: 'alexa.' + _options.baseAmazonPage,
532
- path: '/api/users/me?platform=ios&version=' + apiCallVersion,
539
+ host: `alexa.${_options.baseAmazonPage}`,
540
+ path: `/api/users/me?platform=ios&version=${apiCallVersion}`,
533
541
  method: 'GET',
534
542
  headers: {
535
543
  'User-Agent': apiCallUserAgent,
@@ -547,11 +555,11 @@ function AlexaCookie() {
547
555
  try {
548
556
  if (typeof body !== 'object') body = JSON.parse(body);
549
557
  } catch (err) {
550
- _options.logger && _options.logger('Get User data Response: ' + JSON.stringify(body));
558
+ _options.logger && _options.logger(`Get User data Response: ${JSON.stringify(body)}`);
551
559
  callback && callback(err, null);
552
560
  return;
553
561
  }
554
- _options.logger && _options.logger('Get User data Response: ' + JSON.stringify(body));
562
+ _options.logger && _options.logger(`Get User data Response: ${JSON.stringify(body)}`);
555
563
 
556
564
  Cookie = addCookies(Cookie, response.headers);
557
565
 
@@ -564,7 +572,7 @@ function AlexaCookie() {
564
572
  callback && callback(error, null);
565
573
  return;
566
574
  } else if (error && (!_options.formerRegistrationData || !_options.formerRegistrationData.amazonPage) && _options.amazonPage) {
567
- _options.logger && _options.logger('Continue with externally set amazonPage: ' + _options.amazonPage);
575
+ _options.logger && _options.logger(`Continue with externally set amazonPage: ${_options.amazonPage}`);
568
576
  } else if (error) {
569
577
  _options.logger && _options.logger('Ignore error while getting user data and amazonPage because previously set amazonPage is available');
570
578
  }
@@ -579,7 +587,7 @@ function AlexaCookie() {
579
587
  loginData.localCookie = localCookie;
580
588
  getCSRFFromCookies(loginData.localCookie, _options, (err, resData) => {
581
589
  if (err) {
582
- callback && callback(new Error('Error getting csrf for ' + loginData.amazonPage), null);
590
+ callback && callback(new Error(`Error getting csrf for ${loginData.amazonPage}`), null);
583
591
  return;
584
592
  }
585
593
  loginData.localCookie = resData.cookie;
@@ -587,7 +595,7 @@ function AlexaCookie() {
587
595
  delete loginData.accessToken;
588
596
  delete loginData.authorization_code;
589
597
  delete loginData.verifier;
590
- _options.logger && _options.logger('Final Registration Result: ' + JSON.stringify(loginData));
598
+ _options.logger && _options.logger(`Final Registration Result: ${JSON.stringify(loginData)}`);
591
599
  callback && callback(null, loginData);
592
600
  });
593
601
  });
@@ -604,19 +612,19 @@ function AlexaCookie() {
604
612
  const exchangeParams = {
605
613
  'di.os.name': 'iOS',
606
614
  'app_version': apiCallVersion,
607
- 'domain': '.' + amazonPage,
615
+ 'domain': `.${amazonPage}`,
608
616
  'source_token': refreshToken,
609
617
  'requested_token_type': 'auth_cookies',
610
618
  'source_token_type': 'refresh_token',
611
619
  'di.hw.version': 'iPhone',
612
- 'di.sdk.version': '6.10.0',
613
- 'cookies': Buffer.from('{„cookies“:{".' + amazonPage + '":[]}}').toString('base64'),
614
- 'app_name': 'Amazon Alexa',
615
- 'di.os.version': '11.4.1'
620
+ 'di.sdk.version': '6.12.3',
621
+ 'cookies': Buffer.from(`{„cookies“:{".${amazonPage}":[]}}`).toString('base64'),
622
+ 'app_name': _options.deviceAppName || defaultAppName,
623
+ 'di.os.version': '15.5'
616
624
  };
617
625
  const options = {
618
- host: 'www.' + amazonPage,
619
- path: '/ap/exchangetoken',
626
+ host: `www.${amazonPage}`,
627
+ path: '/ap/exchangetoken/cookies',
620
628
  method: 'POST',
621
629
  headers: {
622
630
  'User-Agent': apiCallUserAgent,
@@ -630,7 +638,7 @@ function AlexaCookie() {
630
638
  encodeURIComponent: encodeURIComponent
631
639
  })
632
640
  };
633
- _options.logger && _options.logger('Alexa-Cookie: Exchange tokens for ' + amazonPage);
641
+ _options.logger && _options.logger(`Alexa-Cookie: Exchange tokens for ${amazonPage}`);
634
642
  _options.logger && _options.logger(JSON.stringify(options));
635
643
 
636
644
  request(options, (error, response, body) => {
@@ -641,35 +649,35 @@ function AlexaCookie() {
641
649
  try {
642
650
  if (typeof body !== 'object') body = JSON.parse(body);
643
651
  } catch (err) {
644
- _options.logger && _options.logger('Exchange Token Response: ' + JSON.stringify(body));
652
+ _options.logger && _options.logger(`Exchange Token Response: ${JSON.stringify(body)}`);
645
653
  callback && callback(err, null);
646
654
  return;
647
655
  }
648
- _options.logger && _options.logger('Exchange Token Response: ' + JSON.stringify(body));
656
+ _options.logger && _options.logger(`Exchange Token Response: ${JSON.stringify(body)}`);
649
657
 
650
658
  if (!body.response || !body.response.tokens || !body.response.tokens.cookies) {
651
659
  callback && callback(new Error('No cookies in Exchange response'), null);
652
660
  return;
653
661
  }
654
- if (!body.response.tokens.cookies['.' + amazonPage]) {
655
- callback && callback(new Error('No cookies for ' + amazonPage + ' in Exchange response'), null);
662
+ if (!body.response.tokens.cookies[`.${amazonPage}`]) {
663
+ callback && callback(new Error(`No cookies for ${amazonPage} in Exchange response`), null);
656
664
  return;
657
665
  }
658
666
 
659
667
  Cookie = addCookies(Cookie, response.headers);
660
668
  const cookies = cookieTools.parse(Cookie);
661
- body.response.tokens.cookies['.' + amazonPage].forEach((cookie) => {
669
+ body.response.tokens.cookies[`.${amazonPage}`].forEach((cookie) => {
662
670
  if (cookies[cookie.Name] && cookies[cookie.Name] !== cookie.Value) {
663
- _options.logger && _options.logger('Alexa-Cookie: Update Cookie ' + cookie.Name + ' = ' + cookie.Value);
671
+ _options.logger && _options.logger(`Alexa-Cookie: Update Cookie ${cookie.Name} = ${cookie.Value}`);
664
672
  } else if (!cookies[cookie.Name]) {
665
- _options.logger && _options.logger('Alexa-Cookie: Add Cookie ' + cookie.Name + ' = ' + cookie.Value);
673
+ _options.logger && _options.logger(`Alexa-Cookie: Add Cookie ${cookie.Name} = ${cookie.Value}`);
666
674
  }
667
675
  cookies[cookie.Name] = cookie.Value;
668
676
 
669
677
  });
670
678
  let localCookie = '';
671
679
  for (const name of Object.keys(cookies)) {
672
- localCookie += name + '=' + cookies[name] + '; ';
680
+ localCookie += `${name}=${cookies[name]}; `;
673
681
  }
674
682
  localCookie = localCookie.replace(/[; ]*$/, '');
675
683
 
@@ -695,9 +703,9 @@ function AlexaCookie() {
695
703
  initConfig();
696
704
 
697
705
  const refreshData = {
698
- 'app_name': 'ioBroker Alexa2',
706
+ 'app_name': _options.deviceAppName || defaultAppName,
699
707
  'app_version': apiCallVersion,
700
- 'di.sdk.version': '6.10.0',
708
+ 'di.sdk.version': '6.12.3',
701
709
  'source_token': _options.formerRegistrationData.refreshToken,
702
710
  'package_name': 'com.amazon.echo',
703
711
  'di.hw.version': 'iPhone',
@@ -705,12 +713,12 @@ function AlexaCookie() {
705
713
  'requested_token_type': 'access_token',
706
714
  'source_token_type': 'refresh_token',
707
715
  'di.os.name': 'iOS',
708
- 'di.os.version': '14.8',
709
- 'current_version': '6.10.0'
716
+ 'di.os.version': '15.5',
717
+ 'current_version': '6.12.3'
710
718
  };
711
719
 
712
720
  const options = {
713
- host: 'api.' + _options.baseAmazonPage,
721
+ host: `api.${_options.baseAmazonPage}`,
714
722
  path: '/auth/token',
715
723
  method: 'POST',
716
724
  headers: {
@@ -721,7 +729,7 @@ function AlexaCookie() {
721
729
  'Content-Type': 'application/x-www-form-urlencoded',
722
730
  'Cookie': _options.formerRegistrationData.loginCookie,
723
731
  'Accept': 'application/json',
724
- 'x-amzn-identity-auth-domain': 'api.' + _options.baseAmazonPage
732
+ 'x-amzn-identity-auth-domain': `api.${_options.baseAmazonPage}`
725
733
  },
726
734
  body: querystring.stringify(refreshData)
727
735
  };
@@ -736,11 +744,11 @@ function AlexaCookie() {
736
744
  try {
737
745
  if (typeof body !== 'object') body = JSON.parse(body);
738
746
  } catch (err) {
739
- _options.logger && _options.logger('Refresh Token Response: ' + JSON.stringify(body));
747
+ _options.logger && _options.logger(`Refresh Token Response: ${JSON.stringify(body)}`);
740
748
  callback && callback(err, null);
741
749
  return;
742
750
  }
743
- _options.logger && _options.logger('Refresh Token Response: ' + JSON.stringify(body));
751
+ _options.logger && _options.logger(`Refresh Token Response: ${JSON.stringify(body)}`);
744
752
 
745
753
  _options.formerRegistrationData.loginCookie = addCookies(_options.formerRegistrationData.loginCookie, response.headers);
746
754
 
@@ -758,8 +766,8 @@ function AlexaCookie() {
758
766
 
759
767
  // Restore frc and map-md
760
768
  const initCookies = cookieTools.parse(_options.formerRegistrationData.loginCookie);
761
- let newCookie = 'frc=' + initCookies.frc + '; ';
762
- newCookie += 'map-md=' + initCookies['map-md'] + '; ';
769
+ let newCookie = `frc=${initCookies.frc}; `;
770
+ newCookie += `map-md=${initCookies['map-md']}; `;
763
771
  newCookie += comCookie;
764
772
 
765
773
  _options.formerRegistrationData.loginCookie = newCookie;
@@ -17,7 +17,7 @@ const config = {
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
19
  proxyLogLevel: 'info', // optional: Loglevel of Proxy, default 'warn'
20
- baseAmazonPage: 'amazon.com', // optional: Change the Proxy Amazon Page - all "western countries" directly use amazon.com! Change to amazon.co.jp for Japan
20
+ baseAmazonPage: 'amazon.com', // optional: Change the Proxy Amazon Page - all "western countries" directly use amazon.com including australia! 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
22
  deviceAppName: '...', // optional: name of the device app name which will be registered with Amazon, leave empty to use a default one
23
23
  formerDataStorePath: '...', // optional: overwrite path where some of the formerRegistrationData are persisted to optimize against Amazon security measures
package/lib/proxy.js CHANGED
@@ -90,7 +90,7 @@ function initAmazonProxy(_options, callbackCookie, callbackListening) {
90
90
  }
91
91
 
92
92
  if (!_options.formerRegistrationData || !_options.formerRegistrationData['map-md']) {
93
- initialCookies['map-md'] = Buffer.from('{"device_user_dictionary":[],"device_registration_data":{"software_version":"1"},"app_identifier":{"app_version":"2.2.223830","bundle_id":"com.amazon.echo"}}').toString('base64');
93
+ initialCookies['map-md'] = Buffer.from('{"device_user_dictionary":[],"device_registration_data":{"software_version":"1"},"app_identifier":{"app_version":"2.2.485407","bundle_id":"com.amazon.echo"}}').toString('base64');
94
94
  }
95
95
  else {
96
96
  _options.logger && _options.logger('Proxy Init: reuse map-md from former data');
@@ -150,7 +150,7 @@ function initAmazonProxy(_options, callbackCookie, callbackListening) {
150
150
  onProxyRes: onProxyRes,
151
151
  onProxyReq: onProxyReq,
152
152
  headers: {
153
- 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 PitanguiBridge/2.2.345247.0-[HARDWARE=iPhone10_4][SOFTWARE=13.5.1]',
153
+ 'user-agent': 'AppleWebKit PitanguiBridge/2.2.485407.0-[HARDWARE=iPhone10_4][SOFTWARE=15.5][DEVICE=iPhone]',
154
154
  'accept-language': _options.acceptLanguage,
155
155
  'authority': `www.${_options.baseAmazonPage}`
156
156
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alexa-cookie2",
3
- "version": "4.1.0",
3
+ "version": "4.1.3",
4
4
  "description": "Generate Cookie and CSRF for Alexa Remote",
5
5
  "author": {
6
6
  "name": "Apollon77",