@omni-co/embed 0.1.3 → 0.1.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/lib/cjs/embed.d.ts +1 -0
- package/lib/cjs/embed.js +20 -27
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/signature.d.ts +39 -0
- package/lib/cjs/signature.js +27 -0
- package/lib/esm/embed.d.ts +1 -0
- package/lib/esm/embed.js +20 -24
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/signature.d.ts +39 -0
- package/lib/esm/signature.js +19 -0
- package/package.json +1 -1
package/lib/cjs/embed.d.ts
CHANGED
package/lib/cjs/embed.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.embedSsoDashboard = void 0;
|
|
7
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
8
4
|
const random_str_1 = require("./random-str");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
hmac.update(data);
|
|
12
|
-
return hmac.digest("base64url");
|
|
13
|
-
};
|
|
5
|
+
const signature_1 = require("./signature");
|
|
6
|
+
const defaultEmbedDomain = "embed-omniapp.co";
|
|
14
7
|
const embedLoginRoute = "/embed/login";
|
|
15
8
|
const embedDashboardPath = "/embed/dashboards";
|
|
16
9
|
const validateProps = (props) => {
|
|
@@ -41,32 +34,32 @@ const validateProps = (props) => {
|
|
|
41
34
|
};
|
|
42
35
|
const embedSsoDashboard = (props) => {
|
|
43
36
|
validateProps(props);
|
|
44
|
-
let { contentId, domain, externalId, name, nonce, organizationName, secret, userAttributes, } = props;
|
|
37
|
+
let { contentId, domain, externalId, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, } = props;
|
|
45
38
|
// Handle defaults
|
|
46
39
|
nonce = nonce ?? (0, random_str_1.random32ByteString)();
|
|
47
|
-
domain = domain ??
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
domain = domain ?? defaultEmbedDomain;
|
|
41
|
+
const userAttributes = rawUserAttributes && JSON.stringify(rawUserAttributes);
|
|
42
|
+
// Generate the url for the embed login route
|
|
43
|
+
const url = new URL(embedLoginRoute, `https://${organizationName.toLocaleLowerCase()}.${domain}${port ? `:${port}` : ""}`);
|
|
44
|
+
// Generate the content path
|
|
52
45
|
const contentPath = `${embedDashboardPath}/${contentId}`;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
46
|
+
// Get a signature for the request
|
|
47
|
+
const signature = (0, signature_1.getSignature)({
|
|
48
|
+
loginUrl: url.toString(),
|
|
49
|
+
contentPath,
|
|
50
|
+
externalId,
|
|
51
|
+
name,
|
|
52
|
+
nonce,
|
|
53
|
+
secret,
|
|
54
|
+
userAttributes,
|
|
55
|
+
});
|
|
56
|
+
// Build and return the signed url
|
|
64
57
|
url.searchParams.append("contentPath", contentPath);
|
|
65
58
|
url.searchParams.append("externalId", externalId);
|
|
66
59
|
url.searchParams.append("name", name);
|
|
67
60
|
url.searchParams.append("nonce", nonce);
|
|
68
61
|
url.searchParams.append("signature", signature);
|
|
69
|
-
url.searchParams.append("userAttributes",
|
|
62
|
+
userAttributes && url.searchParams.append("userAttributes", userAttributes);
|
|
70
63
|
return url.toString();
|
|
71
64
|
};
|
|
72
65
|
exports.embedSsoDashboard = embedSsoDashboard;
|
package/lib/cjs/index.d.ts
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const hmacSign: (data: string, secret: string) => string;
|
|
2
|
+
type SignatureProps = {
|
|
3
|
+
/**
|
|
4
|
+
* The protocol, domain, optional port and /embed/login route of the request.
|
|
5
|
+
*
|
|
6
|
+
* Example: `https://example.embed-omniapp.com/embed/login`
|
|
7
|
+
*/
|
|
8
|
+
loginUrl: string;
|
|
9
|
+
/**
|
|
10
|
+
* The path to the content being embedded.
|
|
11
|
+
*
|
|
12
|
+
* Example: /embed/dashboards/123abc
|
|
13
|
+
*/
|
|
14
|
+
contentPath: string;
|
|
15
|
+
/**
|
|
16
|
+
* The external id of the user.
|
|
17
|
+
*/
|
|
18
|
+
externalId: string;
|
|
19
|
+
/**
|
|
20
|
+
* The name of the user.
|
|
21
|
+
*/
|
|
22
|
+
name: string;
|
|
23
|
+
/**
|
|
24
|
+
* The nonce of the request.
|
|
25
|
+
*/
|
|
26
|
+
nonce: string;
|
|
27
|
+
/**
|
|
28
|
+
* The secret used to sign the request
|
|
29
|
+
*/
|
|
30
|
+
secret: string;
|
|
31
|
+
/**
|
|
32
|
+
* The user attributes to be sent with the request. Expected to be a stringified JSON object.
|
|
33
|
+
*
|
|
34
|
+
* Example: '{ "team": "Lakers" }'
|
|
35
|
+
*/
|
|
36
|
+
userAttributes?: string;
|
|
37
|
+
};
|
|
38
|
+
export declare const getSignature: ({ loginUrl, contentPath, externalId, name, nonce, secret, userAttributes, }: SignatureProps) => string;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getSignature = exports.hmacSign = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const hmacSign = (data, secret) => {
|
|
9
|
+
const hmac = crypto_1.default.createHmac("sha256", secret);
|
|
10
|
+
hmac.update(data);
|
|
11
|
+
return hmac.digest("base64url");
|
|
12
|
+
};
|
|
13
|
+
exports.hmacSign = hmacSign;
|
|
14
|
+
const getSignature = ({ loginUrl, contentPath, externalId, name, nonce, secret, userAttributes, }) => {
|
|
15
|
+
const validationStr = `
|
|
16
|
+
${loginUrl}
|
|
17
|
+
${contentPath}
|
|
18
|
+
${externalId}
|
|
19
|
+
${name}
|
|
20
|
+
${nonce}
|
|
21
|
+
${userAttributes}
|
|
22
|
+
`
|
|
23
|
+
.trim()
|
|
24
|
+
.replace(/\n\s+/g, "\n");
|
|
25
|
+
return (0, exports.hmacSign)(validationStr, secret);
|
|
26
|
+
};
|
|
27
|
+
exports.getSignature = getSignature;
|
package/lib/esm/embed.d.ts
CHANGED
package/lib/esm/embed.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import crypto from "crypto";
|
|
2
1
|
import { random32ByteString } from "./random-str";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
hmac.update(data);
|
|
6
|
-
return hmac.digest("base64url");
|
|
7
|
-
};
|
|
2
|
+
import { getSignature } from "./signature";
|
|
3
|
+
const defaultEmbedDomain = "embed-omniapp.co";
|
|
8
4
|
const embedLoginRoute = "/embed/login";
|
|
9
5
|
const embedDashboardPath = "/embed/dashboards";
|
|
10
6
|
const validateProps = (props) => {
|
|
@@ -35,31 +31,31 @@ const validateProps = (props) => {
|
|
|
35
31
|
};
|
|
36
32
|
export const embedSsoDashboard = (props) => {
|
|
37
33
|
validateProps(props);
|
|
38
|
-
let { contentId, domain, externalId, name, nonce, organizationName, secret, userAttributes, } = props;
|
|
34
|
+
let { contentId, domain, externalId, name, nonce, organizationName, port, secret, userAttributes: rawUserAttributes, } = props;
|
|
39
35
|
// Handle defaults
|
|
40
36
|
nonce = nonce ?? random32ByteString();
|
|
41
|
-
domain = domain ??
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
domain = domain ?? defaultEmbedDomain;
|
|
38
|
+
const userAttributes = rawUserAttributes && JSON.stringify(rawUserAttributes);
|
|
39
|
+
// Generate the url for the embed login route
|
|
40
|
+
const url = new URL(embedLoginRoute, `https://${organizationName.toLocaleLowerCase()}.${domain}${port ? `:${port}` : ""}`);
|
|
41
|
+
// Generate the content path
|
|
46
42
|
const contentPath = `${embedDashboardPath}/${contentId}`;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
// Get a signature for the request
|
|
44
|
+
const signature = getSignature({
|
|
45
|
+
loginUrl: url.toString(),
|
|
46
|
+
contentPath,
|
|
47
|
+
externalId,
|
|
48
|
+
name,
|
|
49
|
+
nonce,
|
|
50
|
+
secret,
|
|
51
|
+
userAttributes,
|
|
52
|
+
});
|
|
53
|
+
// Build and return the signed url
|
|
58
54
|
url.searchParams.append("contentPath", contentPath);
|
|
59
55
|
url.searchParams.append("externalId", externalId);
|
|
60
56
|
url.searchParams.append("name", name);
|
|
61
57
|
url.searchParams.append("nonce", nonce);
|
|
62
58
|
url.searchParams.append("signature", signature);
|
|
63
|
-
url.searchParams.append("userAttributes",
|
|
59
|
+
userAttributes && url.searchParams.append("userAttributes", userAttributes);
|
|
64
60
|
return url.toString();
|
|
65
61
|
};
|
package/lib/esm/index.d.ts
CHANGED
package/lib/esm/index.js
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const hmacSign: (data: string, secret: string) => string;
|
|
2
|
+
type SignatureProps = {
|
|
3
|
+
/**
|
|
4
|
+
* The protocol, domain, optional port and /embed/login route of the request.
|
|
5
|
+
*
|
|
6
|
+
* Example: `https://example.embed-omniapp.com/embed/login`
|
|
7
|
+
*/
|
|
8
|
+
loginUrl: string;
|
|
9
|
+
/**
|
|
10
|
+
* The path to the content being embedded.
|
|
11
|
+
*
|
|
12
|
+
* Example: /embed/dashboards/123abc
|
|
13
|
+
*/
|
|
14
|
+
contentPath: string;
|
|
15
|
+
/**
|
|
16
|
+
* The external id of the user.
|
|
17
|
+
*/
|
|
18
|
+
externalId: string;
|
|
19
|
+
/**
|
|
20
|
+
* The name of the user.
|
|
21
|
+
*/
|
|
22
|
+
name: string;
|
|
23
|
+
/**
|
|
24
|
+
* The nonce of the request.
|
|
25
|
+
*/
|
|
26
|
+
nonce: string;
|
|
27
|
+
/**
|
|
28
|
+
* The secret used to sign the request
|
|
29
|
+
*/
|
|
30
|
+
secret: string;
|
|
31
|
+
/**
|
|
32
|
+
* The user attributes to be sent with the request. Expected to be a stringified JSON object.
|
|
33
|
+
*
|
|
34
|
+
* Example: '{ "team": "Lakers" }'
|
|
35
|
+
*/
|
|
36
|
+
userAttributes?: string;
|
|
37
|
+
};
|
|
38
|
+
export declare const getSignature: ({ loginUrl, contentPath, externalId, name, nonce, secret, userAttributes, }: SignatureProps) => string;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
export const hmacSign = (data, secret) => {
|
|
3
|
+
const hmac = crypto.createHmac("sha256", secret);
|
|
4
|
+
hmac.update(data);
|
|
5
|
+
return hmac.digest("base64url");
|
|
6
|
+
};
|
|
7
|
+
export const getSignature = ({ loginUrl, contentPath, externalId, name, nonce, secret, userAttributes, }) => {
|
|
8
|
+
const validationStr = `
|
|
9
|
+
${loginUrl}
|
|
10
|
+
${contentPath}
|
|
11
|
+
${externalId}
|
|
12
|
+
${name}
|
|
13
|
+
${nonce}
|
|
14
|
+
${userAttributes}
|
|
15
|
+
`
|
|
16
|
+
.trim()
|
|
17
|
+
.replace(/\n\s+/g, "\n");
|
|
18
|
+
return hmacSign(validationStr, secret);
|
|
19
|
+
};
|
package/package.json
CHANGED