@streamlayer/sdk-web-anonymous-auth 0.2.4 → 0.3.0
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 +7 -3
- package/src/index.d.ts +5 -3
- package/src/index.js +13 -21
- package/src/index.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/sdk-web-anonymous-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"typings": "./src/index.d.ts",
|
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
"src/"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@streamlayer/sdk-web": "workspace:^",
|
|
12
11
|
"@streamlayer/sdk-web-api": "workspace:^",
|
|
13
|
-
"jose": "^4.14.6"
|
|
12
|
+
"jose": "^4.14.6",
|
|
13
|
+
"@streamlayer/sdk-web": "workspace:^",
|
|
14
|
+
"url": "0.11.3",
|
|
15
|
+
"@streamlayer/sdk-web-interfaces": "workspace:^",
|
|
16
|
+
"@streamlayer/sdk-web-core": "*",
|
|
17
|
+
"tslib": "^2.6.2"
|
|
14
18
|
},
|
|
15
19
|
"devDependencies": {
|
|
16
20
|
"@nx/devkit": "^16.9.1",
|
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { StreamLayerContext } from '@streamlayer/sdk-web';
|
|
2
|
-
declare module '@streamlayer/sdk-web' {
|
|
1
|
+
import { StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
declare module '@streamlayer/sdk-web-interfaces' {
|
|
3
3
|
interface StreamLayerSDK {
|
|
4
4
|
anonymousAuthorization: () => Promise<void>;
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
type DoneFn = Function;
|
|
8
|
+
export declare const anonymous: (instance: StreamLayerContext, opts: unknown, done: DoneFn) => void;
|
|
9
|
+
export {};
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { queries } from '@streamlayer/sdk-web-api';
|
|
2
2
|
import { importJWK, EncryptJWT } from 'jose';
|
|
3
|
-
const anonymousAuth = async (instance, opts)=>{
|
|
3
|
+
const anonymousAuth = async (instance, opts) => {
|
|
4
4
|
const { schemaName, issuer } = {
|
|
5
5
|
schemaName: 'slra',
|
|
6
|
-
issuer: 'sdk-web'
|
|
6
|
+
issuer: 'sdk-web',
|
|
7
7
|
} || opts;
|
|
8
8
|
const organization = await instance.stores.organizationSettings.getValue();
|
|
9
9
|
if (!organization) {
|
|
@@ -11,32 +11,24 @@ const anonymousAuth = async (instance, opts)=>{
|
|
|
11
11
|
}
|
|
12
12
|
const userKey = `${organization.pub?.kid}`;
|
|
13
13
|
const schema = `${schemaName}:${organization.id}`;
|
|
14
|
-
const anonymous = await queries.bypassAuth(instance.transport, {
|
|
15
|
-
userKey,
|
|
16
|
-
schema,
|
|
17
|
-
init: true
|
|
18
|
-
});
|
|
14
|
+
const anonymous = await queries.bypassAuth(instance.transport, { userKey, schema, init: true });
|
|
19
15
|
const token = anonymous.meta?.token;
|
|
20
16
|
const pubKey = organization.pub;
|
|
21
|
-
const pub = await importJWK({
|
|
22
|
-
...pubKey
|
|
23
|
-
});
|
|
17
|
+
const pub = await importJWK({ ...pubKey });
|
|
24
18
|
const deviceId = window.crypto.randomUUID();
|
|
25
|
-
const jwe = await new EncryptJWT({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}).setIssuedAt().setIssuer(issuer).setAudience(organization.id).setExpirationTime('2m').encrypt(pub);
|
|
19
|
+
const jwe = await new EncryptJWT({ ['device-id']: deviceId, totp: token })
|
|
20
|
+
.setProtectedHeader({ alg: pubKey.alg || '', enc: 'A256CBC-HS512', kid: pubKey.kid })
|
|
21
|
+
.setIssuedAt()
|
|
22
|
+
.setIssuer(issuer)
|
|
23
|
+
.setAudience(organization.id)
|
|
24
|
+
.setExpirationTime('2m')
|
|
25
|
+
.encrypt(pub);
|
|
33
26
|
return instance.sdk.authorizationBypass(schema, jwe);
|
|
34
27
|
};
|
|
35
|
-
export const anonymous = (instance, opts, done)=>{
|
|
36
|
-
instance.sdk.anonymousAuthorization = async ()=>{
|
|
28
|
+
export const anonymous = (instance, opts, done) => {
|
|
29
|
+
instance.sdk.anonymousAuthorization = async () => {
|
|
37
30
|
await anonymousAuth(instance, opts);
|
|
38
31
|
};
|
|
39
32
|
done();
|
|
40
33
|
};
|
|
41
|
-
|
|
42
34
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/sdk-web-anonymous-auth/src/index.ts"],"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/sdk-web-anonymous-auth/src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAIlD,OAAO,EAAE,SAAS,EAAO,UAAU,EAAE,MAAM,MAAM,CAAA;AAQjD,MAAM,aAAa,GAAG,KAAK,EAAE,QAA4B,EAAE,IAAa,EAAE,EAAE;IAC1E,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAC1B;QACE,UAAU,EAAE,MAAM;QAClB,MAAM,EAAE,SAAS;KAClB,IAAI,IAAI,CAAA;IAEX,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CAAA;IAE1E,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;KACxC;IAED,MAAM,OAAO,GAAG,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,CAAA;IAC1C,MAAM,MAAM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