homebridge-xbox-tv 3.0.2-beta.2 → 3.0.2-beta.4
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 +1 -1
- package/src/webApi/authentication.js +17 -18
package/package.json
CHANGED
|
@@ -3,10 +3,9 @@ const QueryString = require('querystring');
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const fsPromises = fs.promises;
|
|
5
5
|
const axios = require('axios');
|
|
6
|
-
const EventEmitter = require('events');
|
|
7
6
|
const CONSTANTS = require('../constants.json');
|
|
8
7
|
|
|
9
|
-
class Authentication
|
|
8
|
+
class Authentication{
|
|
10
9
|
constructor(config) {
|
|
11
10
|
super();
|
|
12
11
|
this.webApiClientId = config.webApiClientId || CONSTANTS.WebApi.ClientId;
|
|
@@ -32,7 +31,7 @@ class Authentication extends EventEmitter{
|
|
|
32
31
|
await this.refreshTokens('xsts');
|
|
33
32
|
return true;
|
|
34
33
|
} catch (error) {
|
|
35
|
-
|
|
34
|
+
throw new Error(error);
|
|
36
35
|
};
|
|
37
36
|
break;
|
|
38
37
|
case false:
|
|
@@ -40,7 +39,7 @@ class Authentication extends EventEmitter{
|
|
|
40
39
|
await this.refreshTokens('xsts');
|
|
41
40
|
return true;
|
|
42
41
|
} catch (error) {
|
|
43
|
-
|
|
42
|
+
throw new Error(error);
|
|
44
43
|
};
|
|
45
44
|
break;
|
|
46
45
|
}
|
|
@@ -50,7 +49,7 @@ class Authentication extends EventEmitter{
|
|
|
50
49
|
await this.refreshTokens('xsts');
|
|
51
50
|
return true;
|
|
52
51
|
} catch (error) {
|
|
53
|
-
|
|
52
|
+
throw new Error(error);
|
|
54
53
|
};
|
|
55
54
|
}
|
|
56
55
|
break;
|
|
@@ -64,7 +63,7 @@ class Authentication extends EventEmitter{
|
|
|
64
63
|
await this.refreshTokens('xsts');
|
|
65
64
|
return true;
|
|
66
65
|
} catch (error) {
|
|
67
|
-
|
|
66
|
+
throw new Error(error);
|
|
68
67
|
};
|
|
69
68
|
break;
|
|
70
69
|
case false:
|
|
@@ -76,12 +75,12 @@ class Authentication extends EventEmitter{
|
|
|
76
75
|
await this.getXstsToken(this.tokens.user.Token);
|
|
77
76
|
return true;
|
|
78
77
|
} catch (error) {
|
|
79
|
-
|
|
78
|
+
throw new Error(error);
|
|
80
79
|
};
|
|
81
80
|
}
|
|
82
81
|
break;
|
|
83
82
|
default:
|
|
84
|
-
|
|
83
|
+
throw new Error(`Unknow refresh token type: ${type}.`);
|
|
85
84
|
break;
|
|
86
85
|
}
|
|
87
86
|
}
|
|
@@ -104,7 +103,7 @@ class Authentication extends EventEmitter{
|
|
|
104
103
|
this.tokens.oauth = refreshToken;
|
|
105
104
|
return true;
|
|
106
105
|
} catch (error) {
|
|
107
|
-
|
|
106
|
+
throw new Error(error);
|
|
108
107
|
};
|
|
109
108
|
}
|
|
110
109
|
|
|
@@ -128,7 +127,7 @@ class Authentication extends EventEmitter{
|
|
|
128
127
|
this.tokens.xsts = {};
|
|
129
128
|
return true;
|
|
130
129
|
} catch (error) {
|
|
131
|
-
|
|
130
|
+
throw new Error(error);
|
|
132
131
|
};
|
|
133
132
|
}
|
|
134
133
|
|
|
@@ -150,7 +149,7 @@ class Authentication extends EventEmitter{
|
|
|
150
149
|
this.tokens.xsts = xstsToken;
|
|
151
150
|
return true;
|
|
152
151
|
} catch (error) {
|
|
153
|
-
|
|
152
|
+
throw new Error(error);
|
|
154
153
|
};
|
|
155
154
|
}
|
|
156
155
|
|
|
@@ -174,7 +173,7 @@ class Authentication extends EventEmitter{
|
|
|
174
173
|
await this.saveTokens(this.tokens);
|
|
175
174
|
return true;
|
|
176
175
|
} catch (error) {
|
|
177
|
-
|
|
176
|
+
throw new Error(error);
|
|
178
177
|
};
|
|
179
178
|
}
|
|
180
179
|
|
|
@@ -190,13 +189,13 @@ class Authentication extends EventEmitter{
|
|
|
190
189
|
await this.saveTokens(this.tokens);
|
|
191
190
|
return { headers: `XBL3.0 x=${this.tokens.xsts.DisplayClaims.xui[0].uhs};${this.tokens.xsts.Token}`, tokens: this.tokens };
|
|
192
191
|
} else {
|
|
193
|
-
|
|
192
|
+
throw new Error('No oauth token found. Use authorization manager first.')
|
|
194
193
|
}
|
|
195
194
|
} catch (error) {
|
|
196
195
|
throw new Error(error);
|
|
197
196
|
};
|
|
198
197
|
} else {
|
|
199
|
-
|
|
198
|
+
throw new Error(`Authorization not possible, check plugin settings - Client Id: ${this.webApiClientId}`);
|
|
200
199
|
}
|
|
201
200
|
}
|
|
202
201
|
|
|
@@ -213,7 +212,7 @@ class Authentication extends EventEmitter{
|
|
|
213
212
|
const oauth2URI = `${CONSTANTS.WebApi.Url.oauth2}?${params}`;
|
|
214
213
|
return oauth2URI;
|
|
215
214
|
} catch (error) {
|
|
216
|
-
|
|
215
|
+
throw new Error(error);
|
|
217
216
|
};
|
|
218
217
|
}
|
|
219
218
|
|
|
@@ -223,7 +222,7 @@ class Authentication extends EventEmitter{
|
|
|
223
222
|
const tokens = data.length > 0 ? JSON.parse(data) : false;
|
|
224
223
|
return tokens;
|
|
225
224
|
} catch (error) {
|
|
226
|
-
|
|
225
|
+
throw new Error(error);
|
|
227
226
|
};
|
|
228
227
|
}
|
|
229
228
|
|
|
@@ -233,7 +232,7 @@ class Authentication extends EventEmitter{
|
|
|
233
232
|
await fsPromises.writeFile(this.tokensFile, tokens);
|
|
234
233
|
return true;
|
|
235
234
|
} catch (error) {
|
|
236
|
-
|
|
235
|
+
throw new Error(error);
|
|
237
236
|
};
|
|
238
237
|
}
|
|
239
238
|
|
|
@@ -247,7 +246,7 @@ class Authentication extends EventEmitter{
|
|
|
247
246
|
await fsPromises.writeFile(this.tokensFile, tokens);
|
|
248
247
|
return true;
|
|
249
248
|
} catch (error) {
|
|
250
|
-
|
|
249
|
+
throw new Error(error);
|
|
251
250
|
};
|
|
252
251
|
}
|
|
253
252
|
}
|