@simpleview/sv-auth-client 5.0.2 → 5.0.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/Dockerfile +1 -0
- package/package.json +1 -1
- package/readme.md +1 -1
- package/src/oauth2.js +3 -2
- package/src/prefixes/AuthPrefix.js +90 -1
package/Dockerfile
CHANGED
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -284,7 +284,7 @@ This is a library of functions to enable a product application to authenticate a
|
|
|
284
284
|
* `client_id` - The `client_id` of the application. e.g. `admin` or `cms`. This id should be registered with auth as an `oauth_client`.
|
|
285
285
|
* `redirect_uri` - The url which auth will redirect to upon successful login or if already logged in. This should match the `redirect_uri` registered with auth as an `oauth_client`. e.g. `https://test-account.admin.simpleviewinc.com/oauth2/callback/`.
|
|
286
286
|
* `state` - Generated above
|
|
287
|
-
* `code_challenge` - `
|
|
287
|
+
* `code_challenge` - `Base64URLEncode(SHA256(code_verifier))`
|
|
288
288
|
* `sv_auth_params` - JSON string containing an object. The properties of this object are added to the auth login url as extra parameters. This can be used to add e.g. the `account_name` or the `product`.
|
|
289
289
|
* If not logged in then redirects to auth login with redirectUrl of `/oauth2/login/`
|
|
290
290
|
* If logged in:
|
package/src/oauth2.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
//@ts-check
|
|
2
2
|
const { request : axios } = require("axios");
|
|
3
3
|
const { createHash, randomBytes } = require("crypto");
|
|
4
|
+
const base64urlEncode = require("/app/shared/base64urlEncode");
|
|
4
5
|
|
|
5
6
|
const liveAuthUrl = "https://auth.simpleviewinc.com/";
|
|
6
7
|
|
|
7
8
|
function oauth2CreateKeyHash(key) {
|
|
8
|
-
return createHash("sha256").update(key).digest("base64");
|
|
9
|
+
return base64urlEncode(createHash("sha256").update(key).digest("base64"));
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -33,7 +34,7 @@ function oauth2CreateLoginUrl({
|
|
|
33
34
|
client_id,
|
|
34
35
|
redirect_uri,
|
|
35
36
|
state,
|
|
36
|
-
code_challenge: oauth2CreateKeyHash(code_verifier)
|
|
37
|
+
code_challenge: base64urlEncode(oauth2CreateKeyHash(code_verifier))
|
|
37
38
|
});
|
|
38
39
|
|
|
39
40
|
if (sv_auth_params) {
|
|
@@ -28,15 +28,19 @@ class AuthPrefix {
|
|
|
28
28
|
graphServer
|
|
29
29
|
})
|
|
30
30
|
}
|
|
31
|
+
|
|
31
32
|
async accounts(...args) {
|
|
32
33
|
return this._accounts.find(...args);
|
|
33
34
|
}
|
|
35
|
+
|
|
34
36
|
async accounts_upsert(...args) {
|
|
35
37
|
return this._accounts.upsert(...args);
|
|
36
38
|
}
|
|
39
|
+
|
|
37
40
|
async accounts_remove(...args) {
|
|
38
41
|
return this._accounts.remove(...args);
|
|
39
42
|
}
|
|
43
|
+
|
|
40
44
|
async account_public({ filter, fields, context }) {
|
|
41
45
|
context = context || this._graphServer.context;
|
|
42
46
|
|
|
@@ -62,6 +66,7 @@ class AuthPrefix {
|
|
|
62
66
|
|
|
63
67
|
return returnData;
|
|
64
68
|
}
|
|
69
|
+
|
|
65
70
|
async accounts_sync({ fields, context }) {
|
|
66
71
|
context = context || this._graphServer.context;
|
|
67
72
|
|
|
@@ -85,6 +90,7 @@ class AuthPrefix {
|
|
|
85
90
|
|
|
86
91
|
return returnData;
|
|
87
92
|
}
|
|
93
|
+
|
|
88
94
|
async accounts_email_setup({ fields, context = this._graphServer.context }) {
|
|
89
95
|
return query({
|
|
90
96
|
query : `
|
|
@@ -102,15 +108,19 @@ class AuthPrefix {
|
|
|
102
108
|
clean : true
|
|
103
109
|
});
|
|
104
110
|
}
|
|
111
|
+
|
|
105
112
|
async oauth_clients(...args) {
|
|
106
113
|
return this._oauthClients.find(...args);
|
|
107
114
|
}
|
|
115
|
+
|
|
108
116
|
async oauth_clients_upsert(...args) {
|
|
109
117
|
return this._oauthClients.upsert(...args);
|
|
110
118
|
}
|
|
119
|
+
|
|
111
120
|
async oauth_clients_remove(...args) {
|
|
112
121
|
return this._oauthClients.remove(...args);
|
|
113
122
|
}
|
|
123
|
+
|
|
114
124
|
async current({ acct_id, fields, context }) {
|
|
115
125
|
context = context || this._graphServer.context;
|
|
116
126
|
|
|
@@ -137,6 +147,7 @@ class AuthPrefix {
|
|
|
137
147
|
|
|
138
148
|
return returnData;
|
|
139
149
|
}
|
|
150
|
+
|
|
140
151
|
async reset_password_start({ input, fields }) {
|
|
141
152
|
const result = await query({
|
|
142
153
|
query : `
|
|
@@ -160,6 +171,7 @@ class AuthPrefix {
|
|
|
160
171
|
|
|
161
172
|
return returnData;
|
|
162
173
|
}
|
|
174
|
+
|
|
163
175
|
async update_password({ token, new_pass, fields }) {
|
|
164
176
|
const result = await query({
|
|
165
177
|
query : `
|
|
@@ -180,6 +192,7 @@ class AuthPrefix {
|
|
|
180
192
|
|
|
181
193
|
return result.auth.update_password;
|
|
182
194
|
}
|
|
195
|
+
|
|
183
196
|
async refresh_token({ refresh_token, fields }) {
|
|
184
197
|
const result = await query({
|
|
185
198
|
query : `
|
|
@@ -200,6 +213,7 @@ class AuthPrefix {
|
|
|
200
213
|
|
|
201
214
|
return result.auth.refresh_token;
|
|
202
215
|
}
|
|
216
|
+
|
|
203
217
|
async login({ input, fields }) {
|
|
204
218
|
const result = await query({
|
|
205
219
|
query : `
|
|
@@ -220,6 +234,7 @@ class AuthPrefix {
|
|
|
220
234
|
|
|
221
235
|
return result.auth.login;
|
|
222
236
|
}
|
|
237
|
+
|
|
223
238
|
async login_google({ token, fields }) {
|
|
224
239
|
const result = await query({
|
|
225
240
|
query : `
|
|
@@ -239,6 +254,7 @@ class AuthPrefix {
|
|
|
239
254
|
|
|
240
255
|
return result.auth.login_google;
|
|
241
256
|
}
|
|
257
|
+
|
|
242
258
|
async login_service_account({ input, fields }) {
|
|
243
259
|
const result = await query({
|
|
244
260
|
query : `
|
|
@@ -258,6 +274,7 @@ class AuthPrefix {
|
|
|
258
274
|
|
|
259
275
|
return result.auth.login_service_account;
|
|
260
276
|
}
|
|
277
|
+
|
|
261
278
|
async login_sso_token({ input, fields }) {
|
|
262
279
|
const result = await query({
|
|
263
280
|
query : `
|
|
@@ -277,6 +294,7 @@ class AuthPrefix {
|
|
|
277
294
|
|
|
278
295
|
return result.auth.login_sso_token;
|
|
279
296
|
}
|
|
297
|
+
|
|
280
298
|
async check_token_cache({ date, acct_id, fields, context }) {
|
|
281
299
|
context = context || this._graphServer.context;
|
|
282
300
|
|
|
@@ -300,6 +318,74 @@ class AuthPrefix {
|
|
|
300
318
|
|
|
301
319
|
return result.auth.check_token_cache;
|
|
302
320
|
}
|
|
321
|
+
|
|
322
|
+
async verify_mfa_code({ input, fields }) {
|
|
323
|
+
const result = await query({
|
|
324
|
+
query : `
|
|
325
|
+
query($input: auth_verify_mfa_code_input!) {
|
|
326
|
+
auth {
|
|
327
|
+
verify_mfa_code(input: $input) {
|
|
328
|
+
${fields}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
`,
|
|
333
|
+
variables : {
|
|
334
|
+
input
|
|
335
|
+
},
|
|
336
|
+
url : this._graphUrl
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
return result.auth.verify_mfa_code;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async send_email_mfa_code({ input, fields }) {
|
|
343
|
+
const result = await query({
|
|
344
|
+
query : `
|
|
345
|
+
mutation($input: auth_send_email_mfa_code_input!) {
|
|
346
|
+
auth {
|
|
347
|
+
send_email_mfa_code(input: $input) {
|
|
348
|
+
${fields}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
`,
|
|
353
|
+
variables : {
|
|
354
|
+
input
|
|
355
|
+
},
|
|
356
|
+
url : this._graphUrl
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
return result.auth.send_email_mfa_code;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async update_root_user({ input, fields, context}) {
|
|
363
|
+
context = context || this._graphServer.context;
|
|
364
|
+
|
|
365
|
+
const result = await query({
|
|
366
|
+
query: `
|
|
367
|
+
mutation($input: auth_update_root_user_input!) {
|
|
368
|
+
auth {
|
|
369
|
+
update_root_user(input: $input) {
|
|
370
|
+
${fields}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
`,
|
|
375
|
+
variables: {
|
|
376
|
+
input
|
|
377
|
+
},
|
|
378
|
+
url: this._graphUrl,
|
|
379
|
+
token: context.token
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
const returnData = result.auth.update_root_user;
|
|
383
|
+
|
|
384
|
+
nullToUndefined(returnData)
|
|
385
|
+
|
|
386
|
+
return returnData;
|
|
387
|
+
}
|
|
388
|
+
|
|
303
389
|
async test_reset_data({ fields, context }) {
|
|
304
390
|
context = context || this._graphServer.context;
|
|
305
391
|
|
|
@@ -323,6 +409,7 @@ class AuthPrefix {
|
|
|
323
409
|
|
|
324
410
|
return returnData;
|
|
325
411
|
}
|
|
412
|
+
|
|
326
413
|
async test_clear_data({ fields, context }) {
|
|
327
414
|
context = context || this._graphServer.context;
|
|
328
415
|
|
|
@@ -346,9 +433,11 @@ class AuthPrefix {
|
|
|
346
433
|
|
|
347
434
|
return returnData;
|
|
348
435
|
}
|
|
436
|
+
|
|
349
437
|
async test_items(...args) {
|
|
350
438
|
return this._testItems.find(...args);
|
|
351
439
|
}
|
|
440
|
+
|
|
352
441
|
async setup({ context, fields }) {
|
|
353
442
|
context = context || this._graphServer.context;
|
|
354
443
|
|
|
@@ -374,4 +463,4 @@ class AuthPrefix {
|
|
|
374
463
|
}
|
|
375
464
|
}
|
|
376
465
|
|
|
377
|
-
module.exports = AuthPrefix;
|
|
466
|
+
module.exports = AuthPrefix;
|