backend-manager 3.2.172 → 3.2.173
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 +3 -3
- package/src/cli/cli.js +27 -11
- package/dist/cli/cli.js +0 -1534
- package/dist/manager/functions/core/actions/api/admin/backup.js +0 -338
- package/dist/manager/functions/core/actions/api/admin/create-post.js +0 -388
- package/dist/manager/functions/core/actions/api/admin/cron.js +0 -37
- package/dist/manager/functions/core/actions/api/admin/database-read.js +0 -35
- package/dist/manager/functions/core/actions/api/admin/database-write.js +0 -39
- package/dist/manager/functions/core/actions/api/admin/edit-post.js +0 -158
- package/dist/manager/functions/core/actions/api/admin/firestore-query.js +0 -165
- package/dist/manager/functions/core/actions/api/admin/firestore-read.js +0 -38
- package/dist/manager/functions/core/actions/api/admin/firestore-write.js +0 -54
- package/dist/manager/functions/core/actions/api/admin/get-stats.js +0 -269
- package/dist/manager/functions/core/actions/api/admin/payment-processor.js +0 -57
- package/dist/manager/functions/core/actions/api/admin/run-hook.js +0 -95
- package/dist/manager/functions/core/actions/api/admin/send-notification.js +0 -197
- package/dist/manager/functions/core/actions/api/admin/sync-users.js +0 -125
- package/dist/manager/functions/core/actions/api/admin/templates/post.html +0 -16
- package/dist/manager/functions/core/actions/api/firebase/get-providers.js +0 -102
- package/dist/manager/functions/core/actions/api/general/emails/general:download-app-link.js +0 -21
- package/dist/manager/functions/core/actions/api/general/fetch-post.js +0 -99
- package/dist/manager/functions/core/actions/api/general/generate-uuid.js +0 -41
- package/dist/manager/functions/core/actions/api/general/send-email.js +0 -112
- package/dist/manager/functions/core/actions/api/handler/create-post.js +0 -146
- package/dist/manager/functions/core/actions/api/special/setup-electron-manager-client.js +0 -103
- package/dist/manager/functions/core/actions/api/template.js +0 -33
- package/dist/manager/functions/core/actions/api/test/authenticate.js +0 -22
- package/dist/manager/functions/core/actions/api/test/create-test-accounts.js +0 -27
- package/dist/manager/functions/core/actions/api/test/lab.js +0 -55
- package/dist/manager/functions/core/actions/api/test/redirect.js +0 -26
- package/dist/manager/functions/core/actions/api/test/webhook.js +0 -30
- package/dist/manager/functions/core/actions/api/user/create-custom-token.js +0 -32
- package/dist/manager/functions/core/actions/api/user/delete.js +0 -68
- package/dist/manager/functions/core/actions/api/user/get-active-sessions.js +0 -45
- package/dist/manager/functions/core/actions/api/user/get-subscription-info.js +0 -49
- package/dist/manager/functions/core/actions/api/user/oauth2/discord.js +0 -114
- package/dist/manager/functions/core/actions/api/user/oauth2/google.js +0 -99
- package/dist/manager/functions/core/actions/api/user/oauth2.js +0 -476
- package/dist/manager/functions/core/actions/api/user/regenerate-api-keys.js +0 -54
- package/dist/manager/functions/core/actions/api/user/resolve.js +0 -32
- package/dist/manager/functions/core/actions/api/user/sign-out-all-sessions.js +0 -118
- package/dist/manager/functions/core/actions/api/user/sign-up copy.js +0 -544
- package/dist/manager/functions/core/actions/api/user/sign-up.js +0 -99
- package/dist/manager/functions/core/actions/api/user/submit-feedback.js +0 -96
- package/dist/manager/functions/core/actions/api/user/validate-settings.js +0 -86
- package/dist/manager/functions/core/actions/api.js +0 -354
- package/dist/manager/functions/core/actions/create-post-handler.js +0 -184
- package/dist/manager/functions/core/actions/generate-uuid.js +0 -62
- package/dist/manager/functions/core/actions/sign-up-handler.js +0 -205
- package/dist/manager/functions/core/admin/create-post.js +0 -206
- package/dist/manager/functions/core/admin/firestore-write.js +0 -72
- package/dist/manager/functions/core/admin/get-stats.js +0 -218
- package/dist/manager/functions/core/admin/query.js +0 -198
- package/dist/manager/functions/core/admin/send-notification.js +0 -206
- package/dist/manager/functions/core/cron/daily/ghostii-auto-publisher.js +0 -377
- package/dist/manager/functions/core/cron/daily/reset-usage.js +0 -197
- package/dist/manager/functions/core/cron/daily.js +0 -114
- package/dist/manager/functions/core/events/auth/before-create.js +0 -124
- package/dist/manager/functions/core/events/auth/before-signin.js +0 -62
- package/dist/manager/functions/core/events/auth/on-create copy.js +0 -121
- package/dist/manager/functions/core/events/auth/on-create.js +0 -564
- package/dist/manager/functions/core/events/auth/on-delete.js +0 -72
- package/dist/manager/functions/core/events/firestore/on-subscription.js +0 -107
- package/dist/manager/functions/test/authenticate.js +0 -38
- package/dist/manager/functions/test/create-test-accounts.js +0 -144
- package/dist/manager/functions/test/webhook.js +0 -37
- package/dist/manager/functions/wrappers/mailchimp/addToList.js +0 -25
- package/dist/manager/helpers/analytics copy.js +0 -217
- package/dist/manager/helpers/analytics.js +0 -467
- package/dist/manager/helpers/api-manager.js +0 -324
- package/dist/manager/helpers/assistant.js +0 -1043
- package/dist/manager/helpers/metadata.js +0 -32
- package/dist/manager/helpers/middleware.js +0 -154
- package/dist/manager/helpers/roles.js +0 -69
- package/dist/manager/helpers/settings.js +0 -158
- package/dist/manager/helpers/subscription-resolver-new.js +0 -828
- package/dist/manager/helpers/subscription-resolver.js +0 -842
- package/dist/manager/helpers/usage.js +0 -381
- package/dist/manager/helpers/user.js +0 -198
- package/dist/manager/helpers/utilities.js +0 -292
- package/dist/manager/index.js +0 -1076
- package/dist/manager/libraries/openai.js +0 -460
- package/dist/manager/routes/restart/index.js +0 -52
- package/dist/manager/routes/test/index.js +0 -43
- package/dist/manager/schemas/restart.js +0 -13
- package/dist/manager/schemas/test.js +0 -13
- package/dist/require.js +0 -3
|
@@ -1,476 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash')
|
|
2
|
-
const fetch = require('wonderful-fetch');
|
|
3
|
-
const { arrayify } = require('node-powertools');
|
|
4
|
-
|
|
5
|
-
function Module() {
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/*
|
|
10
|
-
authorize: redirect or send back the URL for authorization, which will go to UJ page that sends the data back to bm_api
|
|
11
|
-
- if no client_id is provided, fetch from ITW/APP
|
|
12
|
-
tokenize: save the credentials in firestore and redirect or respond with URL to the desired end page
|
|
13
|
-
deauthorize: delete from firestore
|
|
14
|
-
refresh: call refresh on token
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
Module.prototype.main = function () {
|
|
18
|
-
const self = this;
|
|
19
|
-
const Manager = self.Manager;
|
|
20
|
-
const Api = self.Api;
|
|
21
|
-
const assistant = self.assistant;
|
|
22
|
-
const payload = self.payload;
|
|
23
|
-
|
|
24
|
-
return new Promise(async function(resolve, reject) {
|
|
25
|
-
Api.resolveUser({adminRequired: true})
|
|
26
|
-
.then(async (user) => {
|
|
27
|
-
|
|
28
|
-
self.ultimateJekyllOAuth2Url = assistant.isDevelopment()
|
|
29
|
-
? `http://localhost:4000/oauth2`
|
|
30
|
-
: `${Manager.config.brand.url}/oauth2`
|
|
31
|
-
self.oauth2 = null;
|
|
32
|
-
self.omittedPayloadFields = ['redirect', 'referrer', 'provider', 'state'];
|
|
33
|
-
|
|
34
|
-
// self.ultimateJekyllOAuth2Url = `${Manager.config.brand.url}/oauth2`;
|
|
35
|
-
|
|
36
|
-
// Options
|
|
37
|
-
// payload.data.payload.uid = payload.data.payload.uid;
|
|
38
|
-
payload.data.payload.redirect = typeof payload.data.payload.redirect === 'undefined'
|
|
39
|
-
? true
|
|
40
|
-
: payload.data.payload.redirect
|
|
41
|
-
|
|
42
|
-
payload.data.payload.referrer = typeof payload.data.payload.referrer === 'undefined'
|
|
43
|
-
? (assistant.isDevelopment() ? `http://localhost:4000/account` : `${Manager.config.brand.url}/account`)
|
|
44
|
-
: payload.data.payload.referrer
|
|
45
|
-
|
|
46
|
-
payload.data.payload.serverUrl = typeof payload.data.payload.serverUrl === 'undefined'
|
|
47
|
-
? (assistant.isDevelopment() ? `${Manager.project.functionsUrl}/bm_api` : `${Manager.project.functionsUrl}/bm_api`)
|
|
48
|
-
: payload.data.payload.serverUrl
|
|
49
|
-
|
|
50
|
-
payload.data.payload.provider = payload.data.payload.provider || '';
|
|
51
|
-
payload.data.payload.state = payload.data.payload.state || 'authorize'; // authorize, tokenize, deauthorize, refresh, get
|
|
52
|
-
payload.data.payload.redirect_uri = payload.data.payload.redirect_uri
|
|
53
|
-
? payload.data.payload.redirect_uri
|
|
54
|
-
: payload.data.payload.referrer;
|
|
55
|
-
|
|
56
|
-
// payload.data.payload.parameters = payload.data.payload.parameters || {}
|
|
57
|
-
|
|
58
|
-
// payload.data.payload.client_id = payload.data.payload.client_id;
|
|
59
|
-
// payload.data.payload.scope = payload.data.payload.scope;
|
|
60
|
-
|
|
61
|
-
let newUrl;
|
|
62
|
-
const client_id = _.get(Manager.config, `oauth2.${payload.data.payload.provider}.client_id`);
|
|
63
|
-
const state = {
|
|
64
|
-
code: 'success',
|
|
65
|
-
provider: payload.data.payload.provider,
|
|
66
|
-
authenticationToken: payload.data.authenticationToken,
|
|
67
|
-
serverUrl: payload.data.payload.serverUrl,
|
|
68
|
-
referrer: payload.data.payload.referrer,
|
|
69
|
-
redirectUrl: payload.data.payload.redirect_uri,
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
assistant.log('OAuth2 payload', payload.data.payload);
|
|
73
|
-
|
|
74
|
-
if (!payload.data.payload.provider) {
|
|
75
|
-
return reject(new Error(`The provider parameter is required.`));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
self.oauth2 = new (require(`./oauth2/${payload.data.payload.provider}.js`))();
|
|
80
|
-
self.oauth2.parent = self;
|
|
81
|
-
self.oauth2.Manager = self.Manager;
|
|
82
|
-
self.oauth2.assistant = self.assistant;
|
|
83
|
-
|
|
84
|
-
newUrl = self.oauth2.urls[payload.data.payload.state]
|
|
85
|
-
|
|
86
|
-
// Set parameters
|
|
87
|
-
if (newUrl) {
|
|
88
|
-
newUrl = new URL(newUrl)
|
|
89
|
-
|
|
90
|
-
if (payload.data.payload.state === 'authorize') {
|
|
91
|
-
if (!client_id) {
|
|
92
|
-
throw new Error(`Missing client_id for ${payload.data.payload.provider} provider`)
|
|
93
|
-
}
|
|
94
|
-
newUrl.searchParams.set('state', JSON.stringify(state));
|
|
95
|
-
newUrl.searchParams.set('client_id', client_id);
|
|
96
|
-
newUrl.searchParams.set('scope', arrayify(payload.data.payload.scope).join(' '));
|
|
97
|
-
newUrl.searchParams.set('redirect_uri', self.ultimateJekyllOAuth2Url);
|
|
98
|
-
|
|
99
|
-
newUrl.searchParams.set('access_type', typeof payload.data.payload.access_type === 'undefined' ? 'offline' : payload.data.payload.access_type)
|
|
100
|
-
newUrl.searchParams.set('prompt', typeof payload.data.payload.prompt === 'undefined' ? 'consent' : payload.data.payload.prompt)
|
|
101
|
-
newUrl.searchParams.set('include_granted_scopes', typeof payload.data.payload.include_granted_scopes === 'undefined' ? 'true' : payload.data.payload.include_granted_scopes)
|
|
102
|
-
newUrl.searchParams.set('response_type', typeof payload.data.payload.response_type === 'undefined' ? 'code' : payload.data.payload.response_type)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
assistant.log('OAuth2 newUrl', newUrl);
|
|
106
|
-
|
|
107
|
-
await self.oauth2.buildUrl(payload.data.payload.state, newUrl)
|
|
108
|
-
.then(url => {
|
|
109
|
-
if (url) {
|
|
110
|
-
newUrl = url;
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
.catch(e => { throw e; });
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
} catch (e) {
|
|
117
|
-
return reject(e);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Process by state
|
|
121
|
-
if (payload.data.payload.state === 'authorize') {
|
|
122
|
-
self.processState_authorize(newUrl, user)
|
|
123
|
-
.then(r => {resolve(r)})
|
|
124
|
-
.catch(e => {reject(e)})
|
|
125
|
-
} else if (payload.data.payload.state === 'tokenize') {
|
|
126
|
-
self.processState_tokenize(newUrl, user)
|
|
127
|
-
.then(r => {resolve(r)})
|
|
128
|
-
.catch(e => {reject(e)})
|
|
129
|
-
} else if (payload.data.payload.state === 'refresh') {
|
|
130
|
-
self.processState_refresh(newUrl, user)
|
|
131
|
-
.then(r => {resolve(r)})
|
|
132
|
-
.catch(e => {reject(e)})
|
|
133
|
-
} else if (payload.data.payload.state === 'deauthorize') {
|
|
134
|
-
self.processState_deauthorize(newUrl, user)
|
|
135
|
-
.then(r => {resolve(r)})
|
|
136
|
-
.catch(e => {reject(e)})
|
|
137
|
-
} else if (payload.data.payload.state === 'status') {
|
|
138
|
-
self.processState_status(newUrl, user)
|
|
139
|
-
.then(r => {resolve(r)})
|
|
140
|
-
.catch(e => {reject(e)})
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
.catch(e => {
|
|
144
|
-
return reject(e);
|
|
145
|
-
})
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
Module.prototype.processState_authorize = function (newUrl, user) {
|
|
151
|
-
const self = this;
|
|
152
|
-
const Manager = self.Manager;
|
|
153
|
-
const Api = self.Api;
|
|
154
|
-
const assistant = self.assistant;
|
|
155
|
-
const payload = self.payload;
|
|
156
|
-
|
|
157
|
-
return new Promise(async function(resolve, reject) {
|
|
158
|
-
const finalUrl = newUrl.toString();
|
|
159
|
-
|
|
160
|
-
return resolve({
|
|
161
|
-
data: {
|
|
162
|
-
url: finalUrl,
|
|
163
|
-
},
|
|
164
|
-
redirect: payload.data.payload.redirect ? finalUrl : null
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
Module.prototype.processState_tokenize = function (newUrl, user) {
|
|
170
|
-
const self = this;
|
|
171
|
-
const Manager = self.Manager;
|
|
172
|
-
const Api = self.Api;
|
|
173
|
-
const assistant = self.assistant;
|
|
174
|
-
const payload = self.payload;
|
|
175
|
-
|
|
176
|
-
return new Promise(async function(resolve, reject) {
|
|
177
|
-
const finalUrl = newUrl.toString();
|
|
178
|
-
|
|
179
|
-
assistant.log('Running processState_tokenize()');
|
|
180
|
-
|
|
181
|
-
const body = {
|
|
182
|
-
client_id: _.get(Manager.config, `oauth2.${payload.data.payload.provider}.client_id`),
|
|
183
|
-
client_secret: _.get(Manager.config, `oauth2.${payload.data.payload.provider}.client_secret`),
|
|
184
|
-
grant_type: 'authorization_code',
|
|
185
|
-
redirect_uri: self.ultimateJekyllOAuth2Url,
|
|
186
|
-
code: payload.data.payload.code,
|
|
187
|
-
// scope: '',
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
assistant.log('body', body);
|
|
191
|
-
|
|
192
|
-
const tokenizeResponse = await fetch(finalUrl, {
|
|
193
|
-
method: 'POST',
|
|
194
|
-
timeout: 60000,
|
|
195
|
-
response: 'json',
|
|
196
|
-
tries: 1,
|
|
197
|
-
log: true,
|
|
198
|
-
body: new URLSearchParams(body),
|
|
199
|
-
cacheBreaker: false,
|
|
200
|
-
headers: {
|
|
201
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
202
|
-
},
|
|
203
|
-
})
|
|
204
|
-
.then(json => json)
|
|
205
|
-
.catch(e => e)
|
|
206
|
-
|
|
207
|
-
assistant.log('tokenizeResponse', tokenizeResponse);
|
|
208
|
-
|
|
209
|
-
if (tokenizeResponse instanceof Error) {
|
|
210
|
-
return reject(tokenizeResponse);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Determine identity
|
|
214
|
-
const verifiedIdentity = await self.oauth2.verifyIdentity(tokenizeResponse)
|
|
215
|
-
.then(identity => identity)
|
|
216
|
-
.catch(e => e);
|
|
217
|
-
|
|
218
|
-
assistant.log('verifiedIdentity', verifiedIdentity);
|
|
219
|
-
|
|
220
|
-
if (verifiedIdentity instanceof Error) {
|
|
221
|
-
return reject(verifiedIdentity);
|
|
222
|
-
} else if (tokenizeResponse && !tokenizeResponse.refresh_token) {
|
|
223
|
-
return reject(new Error(`Missing "refresh_token" in response. This is likely because you disconnected your account and tried to reconnect it. Visit ${self.oauth2.urls.removeAccess} and remove our app from your account and then try again or contact us if you need help!`));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const storeResponse = await self.libraries.admin.firestore().doc(`users/${user.auth.uid}`)
|
|
227
|
-
.set({
|
|
228
|
-
oauth2: {
|
|
229
|
-
[payload.data.payload.provider]: {
|
|
230
|
-
code: _.omit(
|
|
231
|
-
_.merge({}, payload.data.payload),
|
|
232
|
-
self.omittedPayloadFields,
|
|
233
|
-
),
|
|
234
|
-
token: tokenizeResponse,
|
|
235
|
-
identity: verifiedIdentity,
|
|
236
|
-
updated: {
|
|
237
|
-
timestamp: assistant.meta.startTime.timestamp,
|
|
238
|
-
timestampUNIX: assistant.meta.startTime.timestampUNIX,
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
metadata: Manager.Metadata().set({tag: 'user:oauth2'}),
|
|
243
|
-
}, { merge: true })
|
|
244
|
-
.then(r => r)
|
|
245
|
-
.catch(e => e)
|
|
246
|
-
|
|
247
|
-
assistant.log('storeResponse', user.auth.uid, storeResponse);
|
|
248
|
-
|
|
249
|
-
if (storeResponse instanceof Error) {
|
|
250
|
-
return reject(storeResponse);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return resolve({
|
|
254
|
-
data: {success: true}
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
});
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
Module.prototype.processState_refresh = function (newUrl, user) {
|
|
261
|
-
const self = this;
|
|
262
|
-
const Manager = self.Manager;
|
|
263
|
-
const Api = self.Api;
|
|
264
|
-
const assistant = self.assistant;
|
|
265
|
-
const payload = self.payload;
|
|
266
|
-
|
|
267
|
-
return new Promise(async function(resolve, reject) {
|
|
268
|
-
const finalUrl = newUrl.toString();
|
|
269
|
-
|
|
270
|
-
assistant.log('Running processState_refresh()');
|
|
271
|
-
|
|
272
|
-
const body = {
|
|
273
|
-
client_id: _.get(Manager.config, `oauth2.${payload.data.payload.provider}.client_id`),
|
|
274
|
-
client_secret: _.get(Manager.config, `oauth2.${payload.data.payload.provider}.client_secret`),
|
|
275
|
-
grant_type: 'refresh_token',
|
|
276
|
-
refresh_token: _.get(user, `oauth2.${payload.data.payload.provider}.token.refresh_token`),
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
assistant.log('body', body);
|
|
280
|
-
|
|
281
|
-
const refreshResponse = await fetch(finalUrl, {
|
|
282
|
-
method: 'POST',
|
|
283
|
-
timeout: 60000,
|
|
284
|
-
response: 'json',
|
|
285
|
-
tries: 1,
|
|
286
|
-
log: true,
|
|
287
|
-
body: new URLSearchParams(body),
|
|
288
|
-
cacheBreaker: false,
|
|
289
|
-
headers: {
|
|
290
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
291
|
-
},
|
|
292
|
-
})
|
|
293
|
-
.then(json => json)
|
|
294
|
-
.catch(e => e)
|
|
295
|
-
|
|
296
|
-
assistant.log('refreshResponse', refreshResponse);
|
|
297
|
-
|
|
298
|
-
if (refreshResponse instanceof Error) {
|
|
299
|
-
return reject(refreshResponse);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// DISABLED .verifyIdentity() BECAUSE IT WILL TRY TO CHECK IF IT EXISTS
|
|
303
|
-
// Determine identity
|
|
304
|
-
// const verifiedIdentity = await self.oauth2.verifyIdentity(refreshResponse)
|
|
305
|
-
// .then(identity => identity)
|
|
306
|
-
// .catch(e => e);
|
|
307
|
-
|
|
308
|
-
// assistant.log('verifiedIdentity', verifiedIdentity);
|
|
309
|
-
|
|
310
|
-
// if (verifiedIdentity instanceof Error) {
|
|
311
|
-
// return reject(verifiedIdentity);
|
|
312
|
-
// } else if (refreshResponse && !refreshResponse.refresh_token) {
|
|
313
|
-
// return reject(new Error(`Missing "refresh_token" in response. This is likely because you disconnected your account and tried to reconnect it. Visit ${self.oauth2.urls.removeAccess} and remove our app from your account and then try again or contact us if you need help!`));
|
|
314
|
-
// }
|
|
315
|
-
|
|
316
|
-
const storeResponse = await self.libraries.admin.firestore().doc(`users/${user.auth.uid}`)
|
|
317
|
-
.set({
|
|
318
|
-
oauth2: {
|
|
319
|
-
[payload.data.payload.provider]: {
|
|
320
|
-
token: refreshResponse,
|
|
321
|
-
// identity: verifiedIdentity,
|
|
322
|
-
updated: {
|
|
323
|
-
timestamp: assistant.meta.startTime.timestamp,
|
|
324
|
-
timestampUNIX: assistant.meta.startTime.timestampUNIX,
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
metadata: Manager.Metadata().set({tag: 'user:oauth2'}),
|
|
329
|
-
}, { merge: true })
|
|
330
|
-
.then(r => r)
|
|
331
|
-
.catch(e => e)
|
|
332
|
-
|
|
333
|
-
assistant.log('storeResponse', user.auth.uid, storeResponse);
|
|
334
|
-
|
|
335
|
-
if (storeResponse instanceof Error) {
|
|
336
|
-
return reject(storeResponse);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
return resolve({
|
|
340
|
-
data: {success: true}
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
});
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
Module.prototype.processState_deauthorize = function (newUrl, user) {
|
|
348
|
-
const self = this;
|
|
349
|
-
const Manager = self.Manager;
|
|
350
|
-
const Api = self.Api;
|
|
351
|
-
const assistant = self.assistant;
|
|
352
|
-
const payload = self.payload;
|
|
353
|
-
|
|
354
|
-
return new Promise(async function(resolve, reject) {
|
|
355
|
-
self.libraries.admin.firestore().doc(`users/${user.auth.uid}`)
|
|
356
|
-
.set({
|
|
357
|
-
oauth2: {
|
|
358
|
-
[payload.data.payload.provider]: {},
|
|
359
|
-
updated: {
|
|
360
|
-
timestamp: assistant.meta.startTime.timestamp,
|
|
361
|
-
timestampUNIX: assistant.meta.startTime.timestampUNIX,
|
|
362
|
-
}
|
|
363
|
-
},
|
|
364
|
-
metadata: Manager.Metadata().set({tag: 'user:oauth2'}),
|
|
365
|
-
}, { merge: true })
|
|
366
|
-
.then(function(data) {
|
|
367
|
-
return resolve({
|
|
368
|
-
data: {success: true},
|
|
369
|
-
});
|
|
370
|
-
})
|
|
371
|
-
.catch(function(e) {
|
|
372
|
-
return reject(e);
|
|
373
|
-
})
|
|
374
|
-
});
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
Module.prototype.processState_status = function (newUrl, user) {
|
|
378
|
-
const self = this;
|
|
379
|
-
const Manager = self.Manager;
|
|
380
|
-
const Api = self.Api;
|
|
381
|
-
const assistant = self.assistant;
|
|
382
|
-
const payload = self.payload;
|
|
383
|
-
|
|
384
|
-
return new Promise(async function(resolve, reject) {
|
|
385
|
-
const finalUrl = newUrl.toString();
|
|
386
|
-
|
|
387
|
-
payload.data.payload.removeInvalidTokens = typeof payload.data.payload.removeInvalidTokens === 'undefined'
|
|
388
|
-
? true
|
|
389
|
-
: payload.data.payload.removeInvalidTokens;
|
|
390
|
-
|
|
391
|
-
function _remove() {
|
|
392
|
-
return new Promise(function(resolve, reject) {
|
|
393
|
-
if (!payload.data.payload.removeInvalidTokens) {
|
|
394
|
-
return resolve();
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
Manager.libraries.admin.firestore().doc(`users/${user.auth.uid}`)
|
|
398
|
-
.set({
|
|
399
|
-
oauth2: {
|
|
400
|
-
[payload.data.payload.provider]: {},
|
|
401
|
-
updated: {
|
|
402
|
-
timestamp: assistant.meta.startTime.timestamp,
|
|
403
|
-
timestampUNIX: assistant.meta.startTime.timestampUNIX,
|
|
404
|
-
}
|
|
405
|
-
},
|
|
406
|
-
metadata: Manager.Metadata().set({tag: 'user:oauth2'}),
|
|
407
|
-
}, { merge: true })
|
|
408
|
-
.then(async () => {
|
|
409
|
-
assistant.log(`Removed disconnected token for user: ${user.auth.uid}`)
|
|
410
|
-
})
|
|
411
|
-
.catch((e) => e)
|
|
412
|
-
.finally(() => {
|
|
413
|
-
return resolve();
|
|
414
|
-
})
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
Manager.libraries.admin.firestore().doc(`users/${user.auth.uid}`)
|
|
419
|
-
.get()
|
|
420
|
-
.then(async (doc) => {
|
|
421
|
-
const data = doc.data();
|
|
422
|
-
const token = _.get(data, `oauth2.${payload.data.payload.provider}.token.refresh_token`, '');
|
|
423
|
-
// const token = _.get(data, `oauth2.${payload.data.payload.provider}.token.access_token`, '');
|
|
424
|
-
if (!token) {
|
|
425
|
-
return resolve({
|
|
426
|
-
data: {status: 'disconnected'}
|
|
427
|
-
});
|
|
428
|
-
} else if (!self.oauth2.verifyConnection) {
|
|
429
|
-
return resolve({
|
|
430
|
-
data: {status: 'connected'}
|
|
431
|
-
});
|
|
432
|
-
} else {
|
|
433
|
-
// self.oauth2.verifyConnection(finalUrl.replace(/{token}/ig, encodeURIComponent(token)), token)
|
|
434
|
-
self.oauth2.verifyConnection(finalUrl.replace(/{token}/ig, token), token)
|
|
435
|
-
.then(async (status) => {
|
|
436
|
-
if (status === 'disconnected') {
|
|
437
|
-
await _remove();
|
|
438
|
-
}
|
|
439
|
-
return resolve({
|
|
440
|
-
data: {status: status},
|
|
441
|
-
})
|
|
442
|
-
})
|
|
443
|
-
.catch(async (e) => {
|
|
444
|
-
await _remove();
|
|
445
|
-
return resolve({
|
|
446
|
-
data: {status: 'error', error: e.message},
|
|
447
|
-
})
|
|
448
|
-
})
|
|
449
|
-
}
|
|
450
|
-
})
|
|
451
|
-
});
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
Module.prototype.processState_template = function (newUrl) {
|
|
456
|
-
const self = this;
|
|
457
|
-
const Manager = self.Manager;
|
|
458
|
-
const Api = self.Api;
|
|
459
|
-
const assistant = self.assistant;
|
|
460
|
-
const payload = self.payload;
|
|
461
|
-
|
|
462
|
-
return new Promise(async function(resolve, reject) {
|
|
463
|
-
const finalUrl = newUrl.toString();
|
|
464
|
-
|
|
465
|
-
return resolve({
|
|
466
|
-
data: {
|
|
467
|
-
url: finalUrl,
|
|
468
|
-
},
|
|
469
|
-
redirect: payload.data.payload.redirect ? finalUrl : null
|
|
470
|
-
});
|
|
471
|
-
});
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
module.exports = Module;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const uuid4 = require('uuid').v4;
|
|
2
|
-
const UIDGenerator = require('uid-generator');
|
|
3
|
-
const _ = require('lodash')
|
|
4
|
-
const powertools = require('node-powertools')
|
|
5
|
-
const uidgen = new UIDGenerator(256);
|
|
6
|
-
|
|
7
|
-
function Module() {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
Module.prototype.main = function () {
|
|
12
|
-
const self = this;
|
|
13
|
-
const Manager = self.Manager;
|
|
14
|
-
const Api = self.Api;
|
|
15
|
-
const assistant = self.assistant;
|
|
16
|
-
const payload = self.payload;
|
|
17
|
-
|
|
18
|
-
return new Promise(async function(resolve, reject) {
|
|
19
|
-
Api.resolveUser({adminRequired: true})
|
|
20
|
-
.then(async (user) => {
|
|
21
|
-
const keys = powertools.arrayify(_.get(payload.data.payload, 'keys') || ['clientId', 'privateKey']);
|
|
22
|
-
const newKeys = {};
|
|
23
|
-
|
|
24
|
-
keys
|
|
25
|
-
.forEach(key => {
|
|
26
|
-
if (key.match(/client/ig)) {
|
|
27
|
-
newKeys.clientId = uuid4();
|
|
28
|
-
} else if (key.match(/private/ig)) {
|
|
29
|
-
newKeys.privateKey = uidgen.generateSync();
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
self.libraries.admin.firestore().doc(`users/${user.auth.uid}`)
|
|
34
|
-
.set({
|
|
35
|
-
api: newKeys,
|
|
36
|
-
metadata: Manager.Metadata().set({tag: 'user:regenerate-api-keys'}),
|
|
37
|
-
}, {merge: true})
|
|
38
|
-
.then(r => {
|
|
39
|
-
return resolve({data: newKeys});
|
|
40
|
-
})
|
|
41
|
-
.catch(e => {
|
|
42
|
-
return reject(assistant.errorify(`Failed to generate keys: ${e}`, {code: 500, sentry: true}));
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
})
|
|
46
|
-
.catch(e => {
|
|
47
|
-
return reject(e);
|
|
48
|
-
})
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
module.exports = Module;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash')
|
|
2
|
-
|
|
3
|
-
function Module() {
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
Module.prototype.main = function () {
|
|
8
|
-
const self = this;
|
|
9
|
-
const Manager = self.Manager;
|
|
10
|
-
const Api = self.Api;
|
|
11
|
-
const assistant = self.assistant;
|
|
12
|
-
const payload = self.payload;
|
|
13
|
-
|
|
14
|
-
return new Promise(async function(resolve, reject) {
|
|
15
|
-
Api.resolveUser({adminRequired: true})
|
|
16
|
-
.then(async (user) => {
|
|
17
|
-
// TODO: resolve the account and send back
|
|
18
|
-
// - Limits for the account
|
|
19
|
-
// - Usage for the account
|
|
20
|
-
// - Plan for the account
|
|
21
|
-
|
|
22
|
-
// used in EM, WM when signing in or running account().resolve()
|
|
23
|
-
// on WM, it should hide and show the auth-xxx-xxx things in WM
|
|
24
|
-
})
|
|
25
|
-
.catch(e => {
|
|
26
|
-
return reject(e);
|
|
27
|
-
})
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
module.exports = Module;
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash')
|
|
2
|
-
const powertools = require('node-powertools')
|
|
3
|
-
|
|
4
|
-
function Module() {
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
Module.prototype.main = function () {
|
|
9
|
-
const self = this;
|
|
10
|
-
const Manager = self.Manager;
|
|
11
|
-
const Api = self.Api;
|
|
12
|
-
const assistant = self.assistant;
|
|
13
|
-
const payload = self.payload;
|
|
14
|
-
|
|
15
|
-
return new Promise(async function(resolve, reject) {
|
|
16
|
-
|
|
17
|
-
Api.resolveUser({adminRequired: true})
|
|
18
|
-
.then(async (user) => {
|
|
19
|
-
const uid = _.get(user, 'auth.uid', null);
|
|
20
|
-
const id = _.get(payload.data.payload, 'id', 'app');
|
|
21
|
-
const session = `sessions/${id}`;
|
|
22
|
-
|
|
23
|
-
let count = 0;
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
await self.signOutOfSession(uid, session)
|
|
27
|
-
.then(r => count += r)
|
|
28
|
-
|
|
29
|
-
// Legacy for somiibo and old electron-manager
|
|
30
|
-
await self.signOutOfSession(uid, 'gatherings/online')
|
|
31
|
-
.then(r => count += r)
|
|
32
|
-
|
|
33
|
-
await self.libraries.admin
|
|
34
|
-
.auth()
|
|
35
|
-
.revokeRefreshTokens(uid)
|
|
36
|
-
.then(() => {
|
|
37
|
-
return resolve({data: {sessions: count, message: `Successfully signed ${uid} out of all sessions`}});
|
|
38
|
-
})
|
|
39
|
-
.catch(e => {
|
|
40
|
-
return reject(assistant.errorify(`Failed to sign out of all sessions: ${e}`, {code: 500}));
|
|
41
|
-
})
|
|
42
|
-
} catch (e) {
|
|
43
|
-
return reject(assistant.errorify(`Failed to sign out of all sessions: ${e}`, {code: 500}));
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
.catch(e => {
|
|
47
|
-
return reject(e);
|
|
48
|
-
})
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
Module.prototype.signOutOfSession = function (uid, session) {
|
|
54
|
-
const self = this;
|
|
55
|
-
const Manager = self.Manager;
|
|
56
|
-
const Api = self.Api;
|
|
57
|
-
const assistant = self.assistant;
|
|
58
|
-
const payload = self.payload;
|
|
59
|
-
|
|
60
|
-
return new Promise(async function(resolve, reject) {
|
|
61
|
-
let count = 0;
|
|
62
|
-
|
|
63
|
-
await self.libraries.admin.database().ref(session)
|
|
64
|
-
.orderByChild('uid')
|
|
65
|
-
.equalTo(uid)
|
|
66
|
-
.once('value')
|
|
67
|
-
.then(async (snap) => {
|
|
68
|
-
const data = snap.val() || {};
|
|
69
|
-
const keys = Object.keys(data);
|
|
70
|
-
|
|
71
|
-
const promises = [];
|
|
72
|
-
|
|
73
|
-
assistant.log(`Signing out of ${keys.length} active sessions for ${uid} @ ${session}`)
|
|
74
|
-
|
|
75
|
-
for (var i = 0; i < keys.length; i++) {
|
|
76
|
-
promises.push((async () => {
|
|
77
|
-
const key = keys[i];
|
|
78
|
-
|
|
79
|
-
assistant.log(`Signing out ${session}/${key}...`);
|
|
80
|
-
|
|
81
|
-
// Send signout command
|
|
82
|
-
await self.libraries.admin.database().ref(`${session}/${key}/command`)
|
|
83
|
-
.set('signout')
|
|
84
|
-
.catch(e => assistant.error(`Failed to signout of session ${key}`, e))
|
|
85
|
-
|
|
86
|
-
// Delay so the client has time to react to the command
|
|
87
|
-
await powertools.wait(5000);
|
|
88
|
-
|
|
89
|
-
// Delete session
|
|
90
|
-
await self.libraries.admin.database().ref(`${session}/${key}`)
|
|
91
|
-
.remove()
|
|
92
|
-
.catch(e => assistant.error(`Failed to delete session ${key}`, e))
|
|
93
|
-
|
|
94
|
-
assistant.log(`Signed out successfully: ${key}`);
|
|
95
|
-
|
|
96
|
-
count++;
|
|
97
|
-
})())
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Run all promises
|
|
101
|
-
await Promise.all(promises)
|
|
102
|
-
.then(() => {
|
|
103
|
-
return resolve(count);
|
|
104
|
-
})
|
|
105
|
-
.catch((e) => {
|
|
106
|
-
return reject(e);
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
})
|
|
110
|
-
.catch(e => {
|
|
111
|
-
assistant.errorify(`Session query error for session ${session}: ${e}`, {code: 500, sentry: true});
|
|
112
|
-
|
|
113
|
-
return reject(e);
|
|
114
|
-
})
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
module.exports = Module;
|