omni-notify-mcp 1.3.308 → 1.3.310
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/dist/gateway/sessionDriver.js +2 -2
- package/dist/shared/agentSession.js +1 -1
- package/dist/shared/webhost/bullseyeWebHost.js +44 -11
- package/dist/shared/webhost/webviewShim.js +63 -4
- package/package.json +1 -1
- package/dist/googlehome/foyer-client.js +0 -210
- package/dist/googlehome/foyer-codec.js +0 -318
- package/dist/googlehome/gpsoauth.js +0 -119
- package/dist/googlehome/index.js +0 -267
- package/scripts/shared/ownerGuard.cs +0 -665
- package/scripts/shared/ownerGuard.ps1 +0 -31
- /package/scripts/shared/{ownerGuard.js → ownerGuard.cjs} +0 -0
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
// Builds and parses the foyer-pa `application/json+protobuf` wire format.
|
|
2
|
-
//
|
|
3
|
-
// The service does NOT use JSON objects — every request/response body is a *positional* JSON array
|
|
4
|
-
// where protobuf field numbers map to array indices (1-based, with `null` holes for absent fields).
|
|
5
|
-
// Ported from coredevices/pebble-plugins `googlehome/src/foyer-codec.ts` (which names the Kotlin
|
|
6
|
-
// `FoyerCodec` as its origin); the field indices were derived from live captures.
|
|
7
|
-
//
|
|
8
|
-
// Value encoding (the scalar wrapper `[i0,i1,i2,i3,…]`): a value sits at a type-specific index:
|
|
9
|
-
// - int / float -> index 1: [null, <num>]
|
|
10
|
-
// - string / enum-> index 2: [null, null, "<str>"]
|
|
11
|
-
// - bool -> index 3: [null, null, null, <0|1>]
|
|
12
|
-
/** The type used for matching: user-assigned type when set, else hardware type. */
|
|
13
|
-
export function effectiveType(d) {
|
|
14
|
-
return d.assignedType && d.assignedType.trim() !== '' ? d.assignedType : d.type;
|
|
15
|
-
}
|
|
16
|
-
// -------------------------------------------------------------------------------------------------
|
|
17
|
-
// Null-safe positional-array accessors (out-of-range / wrong-typed slot -> null)
|
|
18
|
-
// -------------------------------------------------------------------------------------------------
|
|
19
|
-
function arr(x) {
|
|
20
|
-
return Array.isArray(x) ? x : null;
|
|
21
|
-
}
|
|
22
|
-
function at(a, i) {
|
|
23
|
-
return a != null && i >= 0 && i < a.length ? a[i] : null;
|
|
24
|
-
}
|
|
25
|
-
function str(x) {
|
|
26
|
-
return typeof x === 'string' ? x : null;
|
|
27
|
-
}
|
|
28
|
-
function boolAt(a, i) {
|
|
29
|
-
const e = at(a, i);
|
|
30
|
-
if (typeof e === 'boolean')
|
|
31
|
-
return e;
|
|
32
|
-
return e === 1;
|
|
33
|
-
}
|
|
34
|
-
function numAt(a, i) {
|
|
35
|
-
const e = at(a, i);
|
|
36
|
-
return typeof e === 'number' ? e : null;
|
|
37
|
-
}
|
|
38
|
-
function strAt(a, i) {
|
|
39
|
-
return str(at(a, i));
|
|
40
|
-
}
|
|
41
|
-
function arrAt(a, i) {
|
|
42
|
-
return arr(at(a, i));
|
|
43
|
-
}
|
|
44
|
-
// -------------------------------------------------------------------------------------------------
|
|
45
|
-
// Scalar wrappers. In JS there is no int/float distinction, so intWrapper is just [null, n].
|
|
46
|
-
// -------------------------------------------------------------------------------------------------
|
|
47
|
-
function intWrapper(n) {
|
|
48
|
-
return [null, n];
|
|
49
|
-
}
|
|
50
|
-
function boolWrapper(b) {
|
|
51
|
-
return [null, null, null, b ? 1 : 0];
|
|
52
|
-
}
|
|
53
|
-
/** Flattens a trait body `[[fieldName,<wrapper>],…]` into a `fieldName -> wrapper` map. */
|
|
54
|
-
function fieldWrappers(body) {
|
|
55
|
-
const out = new Map();
|
|
56
|
-
if (body == null)
|
|
57
|
-
return out;
|
|
58
|
-
for (const fieldEl of body) {
|
|
59
|
-
const field = arr(fieldEl);
|
|
60
|
-
const name = strAt(field, 0);
|
|
61
|
-
if (name == null)
|
|
62
|
-
continue;
|
|
63
|
-
out.set(name, arrAt(field, 1));
|
|
64
|
-
}
|
|
65
|
-
return out;
|
|
66
|
-
}
|
|
67
|
-
// -------------------------------------------------------------------------------------------------
|
|
68
|
-
// GetTraits
|
|
69
|
-
// -------------------------------------------------------------------------------------------------
|
|
70
|
-
/** Request body for `HomeControlService/GetTraits`: `[[["id1"],["id2"],…]]`. */
|
|
71
|
-
export function buildGetTraitsRequest(ids) {
|
|
72
|
-
return [ids.map((id) => [id])];
|
|
73
|
-
}
|
|
74
|
-
export function parseGetTraits(json) {
|
|
75
|
-
const results = arrAt(arr(json), 0);
|
|
76
|
-
if (results == null)
|
|
77
|
-
return [];
|
|
78
|
-
const out = [];
|
|
79
|
-
for (const result of results) {
|
|
80
|
-
const r = arr(result);
|
|
81
|
-
const id = strAt(arrAt(r, 0), 0);
|
|
82
|
-
if (id == null)
|
|
83
|
-
continue;
|
|
84
|
-
const traits = arrAt(r, 1);
|
|
85
|
-
const s = {
|
|
86
|
-
id,
|
|
87
|
-
online: false,
|
|
88
|
-
onOff: null,
|
|
89
|
-
brightnessPct: null,
|
|
90
|
-
colorTemperatureK: null,
|
|
91
|
-
volumePct: null,
|
|
92
|
-
muted: null,
|
|
93
|
-
locked: null,
|
|
94
|
-
jammed: null,
|
|
95
|
-
thermostatMode: null,
|
|
96
|
-
setpointC: null,
|
|
97
|
-
setpointF: null,
|
|
98
|
-
ambientC: null,
|
|
99
|
-
temperatureUnit: null,
|
|
100
|
-
};
|
|
101
|
-
if (traits != null) {
|
|
102
|
-
for (const entry of traits) {
|
|
103
|
-
const e = arr(entry);
|
|
104
|
-
const fields = fieldWrappers(arrAt(e, 1));
|
|
105
|
-
switch (strAt(e, 0)) {
|
|
106
|
-
case 'deviceStatus':
|
|
107
|
-
if (fields.has('online'))
|
|
108
|
-
s.online = boolAt(fields.get('online') ?? null, 3);
|
|
109
|
-
break;
|
|
110
|
-
case 'onOff':
|
|
111
|
-
if (fields.has('onOff'))
|
|
112
|
-
s.onOff = boolAt(fields.get('onOff') ?? null, 3);
|
|
113
|
-
break;
|
|
114
|
-
case 'brightness':
|
|
115
|
-
s.brightnessPct = numAt(fields.get('brightness') ?? null, 1);
|
|
116
|
-
break;
|
|
117
|
-
case 'color':
|
|
118
|
-
s.colorTemperatureK = numAt(fields.get('colorTemperature') ?? null, 1);
|
|
119
|
-
break;
|
|
120
|
-
case 'volume':
|
|
121
|
-
s.volumePct = numAt(fields.get('currentVolume') ?? null, 1);
|
|
122
|
-
if (fields.has('isMuted'))
|
|
123
|
-
s.muted = boolAt(fields.get('isMuted') ?? null, 3);
|
|
124
|
-
break;
|
|
125
|
-
case 'lockUnlock':
|
|
126
|
-
if (fields.has('isLocked'))
|
|
127
|
-
s.locked = boolAt(fields.get('isLocked') ?? null, 3);
|
|
128
|
-
if (fields.has('isJammed'))
|
|
129
|
-
s.jammed = boolAt(fields.get('isJammed') ?? null, 3);
|
|
130
|
-
break;
|
|
131
|
-
case 'temperatureSetting':
|
|
132
|
-
s.thermostatMode = strAt(fields.get('mode') ?? null, 2);
|
|
133
|
-
s.setpointC = numAt(fields.get('thermostatTemperatureSetpointC') ?? null, 1);
|
|
134
|
-
s.setpointF = numAt(fields.get('thermostatTemperatureSetpointF') ?? null, 1);
|
|
135
|
-
s.ambientC = numAt(fields.get('ambientAirTemperatureC') ?? null, 1);
|
|
136
|
-
// temperatureUnit lives in the trait's params block (index 2), one array deeper.
|
|
137
|
-
s.temperatureUnit = strAt(fieldWrappers(arrAt(arrAt(e, 2), 0)).get('temperatureUnit') ?? null, 2);
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
out.push(s);
|
|
143
|
-
}
|
|
144
|
-
return out;
|
|
145
|
-
}
|
|
146
|
-
// -------------------------------------------------------------------------------------------------
|
|
147
|
-
// UpdateTraits (control)
|
|
148
|
-
// -------------------------------------------------------------------------------------------------
|
|
149
|
-
export function buildUpdate(deviceId, agentId, partnerDeviceId, traitName, fieldName, wrapper) {
|
|
150
|
-
const trait = [traitName, [[fieldName, wrapper]]];
|
|
151
|
-
const deviceKey = [deviceId, [agentId, partnerDeviceId]];
|
|
152
|
-
const command = [deviceKey, [trait]];
|
|
153
|
-
return [[command]];
|
|
154
|
-
}
|
|
155
|
-
export function buildOnOff(deviceId, agentId, partnerDeviceId, on) {
|
|
156
|
-
return buildUpdate(deviceId, agentId, partnerDeviceId, 'onOff', 'onOff', boolWrapper(on));
|
|
157
|
-
}
|
|
158
|
-
export function buildBrightness(deviceId, agentId, partnerDeviceId, pct) {
|
|
159
|
-
return buildUpdate(deviceId, agentId, partnerDeviceId, 'brightness', 'brightness', intWrapper(pct));
|
|
160
|
-
}
|
|
161
|
-
export function buildColorTemperature(deviceId, agentId, partnerDeviceId, kelvin) {
|
|
162
|
-
return buildUpdate(deviceId, agentId, partnerDeviceId, 'color', 'colorTemperature', intWrapper(kelvin));
|
|
163
|
-
}
|
|
164
|
-
export function buildVolume(deviceId, agentId, partnerDeviceId, pct) {
|
|
165
|
-
return buildUpdate(deviceId, agentId, partnerDeviceId, 'volume', 'currentVolume', intWrapper(pct));
|
|
166
|
-
}
|
|
167
|
-
export function buildMuted(deviceId, agentId, partnerDeviceId, muted) {
|
|
168
|
-
return buildUpdate(deviceId, agentId, partnerDeviceId, 'volume', 'isMuted', boolWrapper(muted));
|
|
169
|
-
}
|
|
170
|
-
// -------------------------------------------------------------------------------------------------
|
|
171
|
-
// AutomationService (routines)
|
|
172
|
-
// -------------------------------------------------------------------------------------------------
|
|
173
|
-
/** `ListAutomations` request body: `[<structureId>]`. */
|
|
174
|
-
export function buildListAutomationsRequest(structureId) {
|
|
175
|
-
return [structureId];
|
|
176
|
-
}
|
|
177
|
-
/** `ExecuteAutomation` request body: `[<structureId>, <automationId>, null, 2]`. */
|
|
178
|
-
export function buildExecuteAutomationRequest(structureId, automationId) {
|
|
179
|
-
return [structureId, automationId, null, 2];
|
|
180
|
-
}
|
|
181
|
-
export function parseListAutomations(json) {
|
|
182
|
-
const list = arrAt(arr(json), 0);
|
|
183
|
-
if (list == null)
|
|
184
|
-
return [];
|
|
185
|
-
const out = [];
|
|
186
|
-
for (const recEl of list) {
|
|
187
|
-
const rec = arr(recEl);
|
|
188
|
-
const id = strAt(rec, 0);
|
|
189
|
-
const name = strAt(rec, 3);
|
|
190
|
-
if (id == null || name == null)
|
|
191
|
-
continue;
|
|
192
|
-
out.push({
|
|
193
|
-
id,
|
|
194
|
-
name,
|
|
195
|
-
manuallyRunnable: numAt(rec, 2) === 1,
|
|
196
|
-
starters: strAt(rec, 4),
|
|
197
|
-
actions: strAt(rec, 5),
|
|
198
|
-
triggerInput: strAt(rec, 10),
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
return out;
|
|
202
|
-
}
|
|
203
|
-
// -------------------------------------------------------------------------------------------------
|
|
204
|
-
// Capability derivation
|
|
205
|
-
// -------------------------------------------------------------------------------------------------
|
|
206
|
-
export function deriveCapabilities(traits) {
|
|
207
|
-
const caps = new Set();
|
|
208
|
-
for (const raw of traits) {
|
|
209
|
-
const suffix = raw.split('.').pop()?.toLowerCase() ?? '';
|
|
210
|
-
switch (suffix) {
|
|
211
|
-
case 'onoff':
|
|
212
|
-
caps.add('on_off');
|
|
213
|
-
break;
|
|
214
|
-
case 'brightness':
|
|
215
|
-
caps.add('brightness');
|
|
216
|
-
break;
|
|
217
|
-
case 'colorsetting':
|
|
218
|
-
caps.add('color_temperature');
|
|
219
|
-
caps.add('color');
|
|
220
|
-
break;
|
|
221
|
-
case 'volume':
|
|
222
|
-
caps.add('volume');
|
|
223
|
-
break;
|
|
224
|
-
case 'lockunlock':
|
|
225
|
-
caps.add('lock');
|
|
226
|
-
break;
|
|
227
|
-
case 'temperaturesetting':
|
|
228
|
-
case 'temperaturecontrol':
|
|
229
|
-
caps.add('thermostat');
|
|
230
|
-
break;
|
|
231
|
-
case 'transportcontrol':
|
|
232
|
-
case 'mediastate':
|
|
233
|
-
caps.add('media_transport');
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return caps;
|
|
238
|
-
}
|
|
239
|
-
// -------------------------------------------------------------------------------------------------
|
|
240
|
-
// GetHomeGraph (enumeration)
|
|
241
|
-
// -------------------------------------------------------------------------------------------------
|
|
242
|
-
export function parseGetHomeGraph(json) {
|
|
243
|
-
const homesArr = arrAt(arr(json), 1);
|
|
244
|
-
if (homesArr == null)
|
|
245
|
-
return { homes: [], devices: [], rooms: [] };
|
|
246
|
-
const homes = [];
|
|
247
|
-
const rooms = [];
|
|
248
|
-
const devices = [];
|
|
249
|
-
const deviceRoom = new Map();
|
|
250
|
-
for (const homeEl of homesArr) {
|
|
251
|
-
const home = arr(homeEl);
|
|
252
|
-
const homeId = strAt(home, 0);
|
|
253
|
-
if (homeId == null)
|
|
254
|
-
continue;
|
|
255
|
-
homes.push({ id: homeId, name: strAt(home, 1) ?? '' });
|
|
256
|
-
// Rooms: [5]
|
|
257
|
-
const roomsArr = arrAt(home, 5);
|
|
258
|
-
if (roomsArr != null) {
|
|
259
|
-
for (const roomEl of roomsArr) {
|
|
260
|
-
const room = arr(roomEl);
|
|
261
|
-
const roomId = strAt(room, 0);
|
|
262
|
-
if (roomId == null)
|
|
263
|
-
continue;
|
|
264
|
-
const roomName = strAt(room, 2) ?? '';
|
|
265
|
-
const roomType = strAt(arrAt(room, 3), 0) ?? '';
|
|
266
|
-
const memberIds = [];
|
|
267
|
-
const members = arrAt(room, 4);
|
|
268
|
-
if (members != null) {
|
|
269
|
-
for (const memberEl of members) {
|
|
270
|
-
// member = [[deviceId,[agentId,partnerId]]]
|
|
271
|
-
const devId = strAt(arrAt(arr(memberEl), 0), 0);
|
|
272
|
-
if (devId == null)
|
|
273
|
-
continue;
|
|
274
|
-
memberIds.push(devId);
|
|
275
|
-
deviceRoom.set(devId, roomName);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
rooms.push({ id: roomId, name: roomName, type: roomType, deviceIds: memberIds });
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
// Devices: [6]
|
|
282
|
-
const devsArr = arrAt(home, 6);
|
|
283
|
-
if (devsArr != null) {
|
|
284
|
-
for (const devEl of devsArr) {
|
|
285
|
-
const rec = arr(devEl);
|
|
286
|
-
const key = arrAt(rec, 0); // [deviceId,[agentId,partnerId]]
|
|
287
|
-
if (key == null)
|
|
288
|
-
continue;
|
|
289
|
-
const devId = strAt(key, 0);
|
|
290
|
-
if (devId == null)
|
|
291
|
-
continue;
|
|
292
|
-
const agentPair = arrAt(key, 1);
|
|
293
|
-
const agentId = strAt(agentPair, 0);
|
|
294
|
-
const partnerDeviceId = strAt(agentPair, 1);
|
|
295
|
-
const name = strAt(rec, 3) ?? '';
|
|
296
|
-
const type = strAt(rec, 5) ?? '';
|
|
297
|
-
// Field [20] is the USER-ASSIGNED device type; it overrides hardware type [5] for intent.
|
|
298
|
-
const assignedType = strAt(arrAt(rec, 20), 0);
|
|
299
|
-
const traitsArr = arrAt(rec, 6);
|
|
300
|
-
const traits = traitsArr == null ? [] : traitsArr.map((t) => str(t)).filter((t) => t != null);
|
|
301
|
-
devices.push({
|
|
302
|
-
id: devId,
|
|
303
|
-
name,
|
|
304
|
-
type,
|
|
305
|
-
assignedType,
|
|
306
|
-
traits,
|
|
307
|
-
roomName: deviceRoom.get(devId) ?? null,
|
|
308
|
-
agentId,
|
|
309
|
-
partnerDeviceId,
|
|
310
|
-
capabilities: deriveCapabilities(traits),
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
// Room membership can appear after a device record within the same home; stamp again.
|
|
316
|
-
const stamped = devices.map((d) => d.roomName == null ? { ...d, roomName: deviceRoom.get(d.id) ?? null } : d);
|
|
317
|
-
return { homes, devices: stamped, rooms };
|
|
318
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// gpsoauth against `https://android.clients.google.com/auth` — the sign-in the Google Home Android
|
|
2
|
-
// app itself uses. Ported from coredevices/pebble-plugins `googlehome/src/gpsoauth.ts` (which names
|
|
3
|
-
// the Kotlin `GpsOAuthCodec`/`GpsOAuthClient` as its origin); the foyer Home Assistant integration
|
|
4
|
-
// carries the same protocol in `custom_components/googlehome_foyer/api.py`.
|
|
5
|
-
//
|
|
6
|
-
// The endpoint speaks a picky, non-JSON protocol:
|
|
7
|
-
// - Request body is `application/x-www-form-urlencoded`.
|
|
8
|
-
// - Response is newline-delimited `Key=Value` text (parsed by parseAuthResponse).
|
|
9
|
-
// `EncryptedPasswd` carries the master token verbatim (nothing is encrypted).
|
|
10
|
-
export const AUTH_URL = 'https://android.clients.google.com/auth';
|
|
11
|
-
export const DEFAULT_ANDROID_ID = '0123456789abcdef';
|
|
12
|
-
// The master token identifies the account, so any syntactically-valid Email works.
|
|
13
|
-
export const PLACEHOLDER_EMAIL = 'owner@example.com';
|
|
14
|
-
export const PLAY_SERVICES_VERSION = '240913000';
|
|
15
|
-
export const AC2DM_SERVICE = 'ac2dm';
|
|
16
|
-
// GMS core signing cert used for the ac2dm master-token exchange (not the per-app chromecast sig).
|
|
17
|
-
export const GMS_CLIENT_SIG = '38918a453d07199354f8b19af05ec6562ced5788';
|
|
18
|
-
export class FoyerAuthError extends Error {
|
|
19
|
-
}
|
|
20
|
-
/** ac2dm oauth_token -> master token exchange form. androidId must match the later getAuthToken. */
|
|
21
|
-
export function buildExchangeForm(oauthToken, androidId, email = PLACEHOLDER_EMAIL) {
|
|
22
|
-
return {
|
|
23
|
-
accountType: 'HOSTED_OR_GOOGLE',
|
|
24
|
-
Email: email,
|
|
25
|
-
has_permission: '1',
|
|
26
|
-
add_account: '1',
|
|
27
|
-
ACCESS_TOKEN: '1',
|
|
28
|
-
Token: oauthToken,
|
|
29
|
-
service: AC2DM_SERVICE,
|
|
30
|
-
source: 'android',
|
|
31
|
-
androidId,
|
|
32
|
-
device_country: 'us',
|
|
33
|
-
operatorCountry: 'us',
|
|
34
|
-
lang: 'en',
|
|
35
|
-
sdk_version: '17',
|
|
36
|
-
google_play_services_version: PLAY_SERVICES_VERSION,
|
|
37
|
-
client_sig: GMS_CLIENT_SIG,
|
|
38
|
-
callerSig: GMS_CLIENT_SIG,
|
|
39
|
-
droidguard_results: 'dummy123',
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
/** getAuthToken form: masterToken -> a short-lived bearer scoped to `service`. */
|
|
43
|
-
export function buildAuthTokenForm(masterToken, androidId, service, app, clientSig, email = PLACEHOLDER_EMAIL) {
|
|
44
|
-
return {
|
|
45
|
-
accountType: 'HOSTED_OR_GOOGLE',
|
|
46
|
-
Email: email,
|
|
47
|
-
has_permission: '1',
|
|
48
|
-
// Despite the name, this carries the master token verbatim (no encryption).
|
|
49
|
-
EncryptedPasswd: masterToken,
|
|
50
|
-
service,
|
|
51
|
-
source: 'android',
|
|
52
|
-
androidId,
|
|
53
|
-
app,
|
|
54
|
-
client_sig: clientSig,
|
|
55
|
-
device_country: 'us',
|
|
56
|
-
operatorCountry: 'us',
|
|
57
|
-
lang: 'en',
|
|
58
|
-
sdk_version: '17',
|
|
59
|
-
google_play_services_version: PLAY_SERVICES_VERSION,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
/** Parses the `Key=Value` newline-delimited auth response. Values may themselves contain `=`. */
|
|
63
|
-
export function parseAuthResponse(body) {
|
|
64
|
-
const out = {};
|
|
65
|
-
for (const rawLine of body.split('\n')) {
|
|
66
|
-
const line = rawLine.trim();
|
|
67
|
-
if (line === '')
|
|
68
|
-
continue;
|
|
69
|
-
const idx = line.indexOf('=');
|
|
70
|
-
if (idx < 0)
|
|
71
|
-
continue;
|
|
72
|
-
out[line.substring(0, idx)] = line.substring(idx + 1);
|
|
73
|
-
}
|
|
74
|
-
return out;
|
|
75
|
-
}
|
|
76
|
-
/** `application/x-www-form-urlencoded` body. */
|
|
77
|
-
export function formEncode(form) {
|
|
78
|
-
return Object.entries(form)
|
|
79
|
-
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
80
|
-
.join('&');
|
|
81
|
-
}
|
|
82
|
-
/** The two gpsoauth exchanges. Both carry credential material in the body and never log it. */
|
|
83
|
-
export class GpsOAuth {
|
|
84
|
-
async exchangeOAuthToken(oauthToken, androidId = DEFAULT_ANDROID_ID) {
|
|
85
|
-
const parsed = await this.post(buildExchangeForm(oauthToken, androidId));
|
|
86
|
-
const token = parsed['Token'];
|
|
87
|
-
if (token == null) {
|
|
88
|
-
throw new FoyerAuthError(`google sign-in rejected the one-time token: ${parsed['Error'] ?? 'no Token in response'}`);
|
|
89
|
-
}
|
|
90
|
-
const email = parsed['Email'];
|
|
91
|
-
return { masterToken: token, email: email != null && email !== '' ? email : null };
|
|
92
|
-
}
|
|
93
|
-
async getAuthToken(masterToken, androidId, service, app, clientSig, email = PLACEHOLDER_EMAIL) {
|
|
94
|
-
const parsed = await this.post(buildAuthTokenForm(masterToken, androidId, service, app, clientSig, email));
|
|
95
|
-
const auth = parsed['Auth'];
|
|
96
|
-
if (auth == null) {
|
|
97
|
-
throw new FoyerAuthError(`google sign-in could not mint a bearer: ${parsed['Error'] ?? 'unknown'}`);
|
|
98
|
-
}
|
|
99
|
-
const expiry = parsed['Expiry'] != null ? Number.parseInt(parsed['Expiry'], 10) : NaN;
|
|
100
|
-
return { auth, expiryEpochSeconds: Number.isFinite(expiry) ? expiry : null };
|
|
101
|
-
}
|
|
102
|
-
async post(form) {
|
|
103
|
-
const resp = await fetch(AUTH_URL, {
|
|
104
|
-
method: 'POST',
|
|
105
|
-
headers: {
|
|
106
|
-
'User-Agent': 'GoogleAuth/1.4',
|
|
107
|
-
'Accept-Encoding': 'identity',
|
|
108
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
109
|
-
},
|
|
110
|
-
body: formEncode(form),
|
|
111
|
-
});
|
|
112
|
-
// A parsed reply is returned for 2xx AND for 4xx, where Google reports rejected credentials
|
|
113
|
-
// (e.g. Error=BadAuthentication); only a server-side failure (429/5xx) is retried upstream.
|
|
114
|
-
if (resp.status === 429 || resp.status >= 500) {
|
|
115
|
-
throw new FoyerAuthError(`google sign-in: HTTP ${resp.status}`);
|
|
116
|
-
}
|
|
117
|
-
return parseAuthResponse(await resp.text());
|
|
118
|
-
}
|
|
119
|
-
}
|