@simpleview/sv-auth-client 5.0.3 → 5.0.5
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 +24 -0
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) {
|
|
@@ -359,6 +359,30 @@ class AuthPrefix {
|
|
|
359
359
|
return result.auth.send_email_mfa_code;
|
|
360
360
|
}
|
|
361
361
|
|
|
362
|
+
async root_user({ fields, context }) {
|
|
363
|
+
context = context || this._graphServer.context;
|
|
364
|
+
|
|
365
|
+
const result = await query({
|
|
366
|
+
query: `
|
|
367
|
+
query {
|
|
368
|
+
auth {
|
|
369
|
+
root_user {
|
|
370
|
+
${fields}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
`,
|
|
375
|
+
url: this._graphUrl,
|
|
376
|
+
token: context.token
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
const returnData = result.auth.root_user;
|
|
380
|
+
|
|
381
|
+
nullToUndefined(returnData)
|
|
382
|
+
|
|
383
|
+
return returnData;
|
|
384
|
+
}
|
|
385
|
+
|
|
362
386
|
async update_root_user({ input, fields, context}) {
|
|
363
387
|
context = context || this._graphServer.context;
|
|
364
388
|
|