homebridge-xbox-tv 2.8.19-beta.21 → 2.8.19-beta.23

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "2.8.19-beta.21",
4
+ "version": "2.8.19-beta.23",
5
5
  "description": "Homebridge plugin (https://github.com/homebridge/homebridge) to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -74,12 +74,7 @@ class AUTHENTICATION {
74
74
  switch (tokenExpired) {
75
75
  case true:
76
76
  try {
77
- this.tokens.xsts = {};
78
- await this.saveTokens(this.tokens);
79
-
80
- const userToken = await this.getXstsToken(this.tokens.user.Token);
81
- this.tokens.xsts = userToken;
82
- await this.saveTokens(this.tokens);
77
+ await this.getXstsToken(this.tokens.user.Token);
83
78
  await this.refreshTokens('xsts');
84
79
  resolve();
85
80
  } catch (error) {
@@ -99,17 +94,14 @@ class AUTHENTICATION {
99
94
  }
100
95
  } else {
101
96
  try {
102
- const userToken = await this.getXstsToken(this.tokens.user.Token);
103
- this.tokens.xsts = userToken;
104
- await this.saveTokens(this.tokens);
105
-
106
- this.user.gtg = userToken.DisplayClaims.xui[0].gtg;
107
- this.user.xid = userToken.DisplayClaims.xui[0].xid;
108
- this.user.uhs = userToken.DisplayClaims.xui[0].uhs;
109
- this.user.usr = userToken.DisplayClaims.xui[0].usr;
110
- this.user.utr = userToken.DisplayClaims.xui[0].utr;
111
- this.user.prv = userToken.DisplayClaims.xui[0].prv;
112
- this.user.agg = userToken.DisplayClaims.xui[0].agg;
97
+ const xstsToken = await this.getXstsToken(this.tokens.user.Token);
98
+ this.user.gtg = xstsToken.DisplayClaims.xui[0].gtg;
99
+ this.user.xid = xstsToken.DisplayClaims.xui[0].xid;
100
+ this.user.uhs = xstsToken.DisplayClaims.xui[0].uhs;
101
+ this.user.usr = xstsToken.DisplayClaims.xui[0].usr;
102
+ this.user.utr = xstsToken.DisplayClaims.xui[0].utr;
103
+ this.user.prv = xstsToken.DisplayClaims.xui[0].prv;
104
+ this.user.agg = xstsToken.DisplayClaims.xui[0].agg;
113
105
  resolve();
114
106
  } catch (error) {
115
107
  reject(error);
@@ -122,28 +114,28 @@ class AUTHENTICATION {
122
114
 
123
115
  checkAuthorization() {
124
116
  return new Promise(async (resolve, reject) => {
125
- try {
126
- if (fs.existsSync(this.tokensFile) && fs.readFileSync(this.tokensFile).length > 30) {
127
- const tokens = fs.readFileSync(this.tokensFile).toString();
128
- this.tokens = JSON.parse(tokens);
129
- }
117
+ if (fs.existsSync(this.tokensFile) && fs.readFileSync(this.tokensFile).length > 30) {
118
+ const tokens = fs.readFileSync(this.tokensFile).toString();
119
+ this.tokens = JSON.parse(tokens);
120
+ }
130
121
 
131
- if (this.clientId) {
132
- if (!this.tokens.oauth.refresh_token) {
133
- reject('No oauth token found. Use authorization manager first.')
134
- return;
135
- };
122
+ if (this.clientId) {
123
+ if (!this.tokens.oauth.refresh_token) {
124
+ reject('No oauth token found. Use authorization manager first.')
125
+ return;
126
+ };
136
127
 
128
+ try {
137
129
  await this.refreshTokens('user');
138
130
  resolve();
139
- } else if (this.userToken && this.userHash) {
140
- resolve();
141
- } else {
142
- reject('Not authorized, check client id in settings.');
143
- }
144
- } catch (error) {
145
- reject(error);
146
- };
131
+ } catch (error) {
132
+ reject(error);
133
+ };
134
+ } else if (this.userToken && this.userHash) {
135
+ resolve();
136
+ } else {
137
+ reject('Not authorized, check client id in settings.');
138
+ }
147
139
  })
148
140
  }
149
141
 
@@ -240,8 +232,10 @@ class AUTHENTICATION {
240
232
  const postData = JSON.stringify(payload);
241
233
  const headers = { 'Content-Type': 'application/json', 'x-xbl-contract-version': '1' };
242
234
  const data = await this.httpClient.post(CONSTANS.Url.XtsxToken, headers, postData);
243
- const token = JSON.parse(data);
244
- resolve(token);
235
+ const xstsToken = JSON.parse(data);
236
+ this.tokens.xsts = xstsToken;
237
+ await this.saveTokens(this.tokens);
238
+ resolve(xstsToken);
245
239
  } catch (error) {
246
240
  reject(error);
247
241
  };