@fluidframework/azure-service-utils 1.0.2 → 1.1.0-101037
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/.eslintrc.js +5 -8
- package/dist/generateToken.d.ts +26 -6
- package/dist/generateToken.d.ts.map +1 -1
- package/dist/generateToken.js +36 -6
- package/dist/generateToken.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/generateToken.d.ts +26 -6
- package/lib/generateToken.d.ts.map +1 -1
- package/lib/generateToken.js +34 -4
- package/lib/generateToken.js.map +1 -1
- package/lib/index.d.ts +7 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -1
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +16 -11
- package/src/generateToken.ts +44 -8
- package/src/index.ts +7 -2
- package/src/packageVersion.ts +1 -1
- package/tsconfig.esnext.json +5 -5
- package/tsconfig.json +10 -16
package/.eslintrc.js
CHANGED
|
@@ -4,12 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"parserOptions": {
|
|
11
|
-
"project": ["./tsconfig.json", "./src/test/tsconfig.json"]
|
|
7
|
+
extends: [require.resolve("@fluidframework/eslint-config-fluid/recommended"), "prettier"],
|
|
8
|
+
parserOptions: {
|
|
9
|
+
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
|
|
12
10
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
11
|
+
rules: {},
|
|
12
|
+
};
|
package/dist/generateToken.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
1
|
import type { IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
6
2
|
/**
|
|
7
3
|
* IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no
|
|
@@ -20,9 +16,33 @@ import type { IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
|
20
16
|
* interdependencies between service and client packages.
|
|
21
17
|
*/
|
|
22
18
|
/**
|
|
23
|
-
* Generates a
|
|
24
|
-
*
|
|
19
|
+
* Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)
|
|
20
|
+
* to authorize access to a Routerlicious-based Fluid service.
|
|
21
|
+
*
|
|
22
|
+
* @remarks Note: this function uses a browser friendly auth library
|
|
23
|
+
* ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.
|
|
24
|
+
* It is **not** Node.js-compatible.
|
|
25
|
+
*
|
|
26
|
+
* @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}
|
|
27
|
+
* @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.
|
|
28
|
+
* @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}
|
|
29
|
+
* @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.
|
|
30
|
+
* If not specified, the token will not be associated with a document, and an empty string will be used.
|
|
31
|
+
* @param user - User with whom generated tokens will be associated.
|
|
32
|
+
* If not specified, the token will not be associated with a user, and a randomly generated mock user will be
|
|
33
|
+
* used instead.
|
|
34
|
+
* See {@link @fluidframework/protocol-definitions#ITokenClaims.user}
|
|
35
|
+
* @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.
|
|
36
|
+
* Expiration = now + lifetime.
|
|
37
|
+
* Expressed in seconds.
|
|
38
|
+
* Default: 3600 (1 hour).
|
|
39
|
+
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
40
|
+
* Default: `1.0`.
|
|
25
41
|
*/
|
|
26
42
|
export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Generates an arbitrary ("random") {@link @fluidframework/protocol-definitions#IUser} by generating a
|
|
45
|
+
* random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.
|
|
46
|
+
*/
|
|
27
47
|
export declare function generateUser(): IUser;
|
|
28
48
|
//# sourceMappingURL=generateToken.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateToken.d.ts","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateToken.d.ts","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAgB,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAE3F;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CACzB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EAAE,EACnB,UAAU,CAAC,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,KAAK,EACZ,QAAQ,GAAE,MAAgB,EAC1B,GAAG,GAAE,MAAc,GACpB,MAAM,CAgCR;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,KAAK,CASpC"}
|
package/dist/generateToken.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateUser = exports.generateToken = void 0;
|
|
2
4
|
/*!
|
|
3
5
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
6
|
* Licensed under the MIT License.
|
|
5
7
|
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.generateUser = exports.generateToken = void 0;
|
|
8
8
|
const jsrsasign_1 = require("jsrsasign");
|
|
9
9
|
const uuid_1 = require("uuid");
|
|
10
10
|
/**
|
|
@@ -24,11 +24,31 @@ const uuid_1 = require("uuid");
|
|
|
24
24
|
* interdependencies between service and client packages.
|
|
25
25
|
*/
|
|
26
26
|
/**
|
|
27
|
-
* Generates a
|
|
28
|
-
*
|
|
27
|
+
* Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)
|
|
28
|
+
* to authorize access to a Routerlicious-based Fluid service.
|
|
29
|
+
*
|
|
30
|
+
* @remarks Note: this function uses a browser friendly auth library
|
|
31
|
+
* ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.
|
|
32
|
+
* It is **not** Node.js-compatible.
|
|
33
|
+
*
|
|
34
|
+
* @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}
|
|
35
|
+
* @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.
|
|
36
|
+
* @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}
|
|
37
|
+
* @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.
|
|
38
|
+
* If not specified, the token will not be associated with a document, and an empty string will be used.
|
|
39
|
+
* @param user - User with whom generated tokens will be associated.
|
|
40
|
+
* If not specified, the token will not be associated with a user, and a randomly generated mock user will be
|
|
41
|
+
* used instead.
|
|
42
|
+
* See {@link @fluidframework/protocol-definitions#ITokenClaims.user}
|
|
43
|
+
* @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.
|
|
44
|
+
* Expiration = now + lifetime.
|
|
45
|
+
* Expressed in seconds.
|
|
46
|
+
* Default: 3600 (1 hour).
|
|
47
|
+
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
48
|
+
* Default: `1.0`.
|
|
29
49
|
*/
|
|
30
50
|
function generateToken(tenantId, key, scopes, documentId, user, lifetime = 60 * 60, ver = "1.0") {
|
|
31
|
-
let userClaim =
|
|
51
|
+
let userClaim = user ? user : generateUser();
|
|
32
52
|
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
33
53
|
userClaim = generateUser();
|
|
34
54
|
}
|
|
@@ -43,15 +63,25 @@ function generateToken(tenantId, key, scopes, documentId, user, lifetime = 60 *
|
|
|
43
63
|
iat: now,
|
|
44
64
|
exp: now + lifetime,
|
|
45
65
|
ver,
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
46
67
|
jti: (0, uuid_1.v4)(),
|
|
47
68
|
};
|
|
48
69
|
const utf8Key = { utf8: key };
|
|
49
|
-
return jsrsasign_1.KJUR.jws.JWS.sign(
|
|
70
|
+
return jsrsasign_1.KJUR.jws.JWS.sign(
|
|
71
|
+
// External API uses null
|
|
72
|
+
// eslint-disable-next-line unicorn/no-null
|
|
73
|
+
null, JSON.stringify({ alg: "HS256", typ: "JWT" }), claims, utf8Key);
|
|
50
74
|
}
|
|
51
75
|
exports.generateToken = generateToken;
|
|
76
|
+
/**
|
|
77
|
+
* Generates an arbitrary ("random") {@link @fluidframework/protocol-definitions#IUser} by generating a
|
|
78
|
+
* random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.
|
|
79
|
+
*/
|
|
52
80
|
function generateUser() {
|
|
53
81
|
const randomUser = {
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
54
83
|
id: (0, uuid_1.v4)(),
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
55
85
|
name: (0, uuid_1.v4)(),
|
|
56
86
|
};
|
|
57
87
|
return randomUser;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,yCAA8C;AAC9C,+BAAkC;AAIlC;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,aAAa,CACzB,QAAgB,EAChB,GAAW,EACX,MAAmB,EACnB,UAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE,EAC1B,MAAc,KAAK;IAEnB,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;IAC7C,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,SAAS,CAAC,EAAE,KAAK,SAAS,EAAE;QACnD,SAAS,GAAG,YAAY,EAAE,CAAC;KAC9B;IAED,0BAA0B;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,EAAE,CAAC;IAE/B,MAAM,MAAM,GAAmC;QAC3C,UAAU,EAAE,KAAK;QACjB,MAAM;QACN,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,QAAQ;QACnB,GAAG;QACH,sGAAsG;QACtG,GAAG,EAAE,IAAA,SAAI,GAAE;KACd,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAE9B,OAAO,gBAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;IACzB,yBAAyB;IACzB,2CAA2C;IAC3C,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAC5C,MAAM,EACN,OAAO,CACV,CAAC;AACN,CAAC;AAxCD,sCAwCC;AAED;;;GAGG;AACH,SAAgB,YAAY;IACxB,MAAM,UAAU,GAAG;QACf,sGAAsG;QACtG,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,sGAAsG;QACtG,IAAI,EAAE,IAAA,SAAI,GAAE;KACf,CAAC;IAEF,OAAO,UAAU,CAAC;AACtB,CAAC;AATD,oCASC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\n\n/**\n * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no\n * need for different implementations, so they should be kept in sync if changes are needed.\n *\n * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries\n * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which\n * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function\n * exported, so it needs to be sourced from either the package itself or a non-dev dependency.\n *\n * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that\n * no longer works because the azure packages are in a separate release group.\n *\n * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token\n * generation, you should use the function available in the server-services-client package in order to avoid\n * interdependencies between service and client packages.\n */\n\n/**\n * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)\n * to authorize access to a Routerlicious-based Fluid service.\n *\n * @remarks Note: this function uses a browser friendly auth library\n * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.\n * It is **not** Node.js-compatible.\n *\n * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}\n * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.\n * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}\n * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.\n * If not specified, the token will not be associated with a document, and an empty string will be used.\n * @param user - User with whom generated tokens will be associated.\n * If not specified, the token will not be associated with a user, and a randomly generated mock user will be\n * used instead.\n * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}\n * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.\n * Expiration = now + lifetime.\n * Expressed in seconds.\n * Default: 3600 (1 hour).\n * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.\n * Default: `1.0`.\n */\nexport function generateToken(\n tenantId: string,\n key: string,\n scopes: ScopeType[],\n documentId?: string,\n user?: IUser,\n lifetime: number = 60 * 60,\n ver: string = \"1.0\",\n): string {\n let userClaim = user ? user : generateUser();\n if (userClaim.id === \"\" || userClaim.id === undefined) {\n userClaim = generateUser();\n }\n\n // Current time in seconds\n const now = Math.round(Date.now() / 1000);\n const docId = documentId ?? \"\";\n\n const claims: ITokenClaims & { jti: string } = {\n documentId: docId,\n scopes,\n tenantId,\n user: userClaim,\n iat: now,\n exp: now + lifetime,\n ver,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n jti: uuid(),\n };\n\n const utf8Key = { utf8: key };\n\n return jsrsasign.jws.JWS.sign(\n // External API uses null\n // eslint-disable-next-line unicorn/no-null\n null,\n JSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n claims,\n utf8Key,\n );\n}\n\n/**\n * Generates an arbitrary (\"random\") {@link @fluidframework/protocol-definitions#IUser} by generating a\n * random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.\n */\nexport function generateUser(): IUser {\n const randomUser = {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n id: uuid(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n name: uuid(),\n };\n\n return randomUser;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* A set of helper utilities for building backend APIs for use with
|
|
6
|
+
* A set of helper utilities for building backend APIs for use with
|
|
7
|
+
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
8
|
+
*
|
|
9
|
+
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
10
|
+
* to be run in a browser context.
|
|
11
|
+
* It is **not** Node.js-compatible.
|
|
7
12
|
*
|
|
8
13
|
* @packageDocumentation
|
|
9
14
|
*/
|
|
10
|
-
export { ScopeType } from "@fluidframework/protocol-definitions";
|
|
15
|
+
export { IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
11
16
|
export { generateToken } from "./generateToken";
|
|
12
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.generateToken = exports.ScopeType = void 0;
|
|
8
8
|
/**
|
|
9
|
-
* A set of helper utilities for building backend APIs for use with
|
|
9
|
+
* A set of helper utilities for building backend APIs for use with
|
|
10
|
+
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
11
|
+
*
|
|
12
|
+
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
13
|
+
* to be run in a browser context.
|
|
14
|
+
* It is **not** Node.js-compatible.
|
|
10
15
|
*
|
|
11
16
|
* @packageDocumentation
|
|
12
17
|
*/
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;GASG;AAEH,6EAAwE;AAAxD,iHAAA,SAAS,OAAA;AACzB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A set of helper utilities for building backend APIs for use with\n * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.\n *\n * Note that this library's primary entry-point ({@link generateToken}) is only intended\n * to be run in a browser context.\n * It is **not** Node.js-compatible.\n *\n * @packageDocumentation\n */\n\nexport { IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/azure-service-utils";
|
|
8
|
-
export declare const pkgVersion = "1.0
|
|
8
|
+
export declare const pkgVersion = "1.1.0-101037";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,wCAAwC,CAAC;AAC7D,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,wCAAwC,CAAC;AAC7D,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/azure-service-utils";
|
|
11
|
-
exports.pkgVersion = "1.0
|
|
11
|
+
exports.pkgVersion = "1.1.0-101037";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,qCAAqC,CAAC;AAChD,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,qCAAqC,CAAC;AAChD,QAAA,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/azure-service-utils\";\nexport const pkgVersion = \"1.1.0-101037\";\n"]}
|
package/lib/generateToken.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
1
|
import type { IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
6
2
|
/**
|
|
7
3
|
* IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no
|
|
@@ -20,9 +16,33 @@ import type { IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
|
20
16
|
* interdependencies between service and client packages.
|
|
21
17
|
*/
|
|
22
18
|
/**
|
|
23
|
-
* Generates a
|
|
24
|
-
*
|
|
19
|
+
* Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)
|
|
20
|
+
* to authorize access to a Routerlicious-based Fluid service.
|
|
21
|
+
*
|
|
22
|
+
* @remarks Note: this function uses a browser friendly auth library
|
|
23
|
+
* ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.
|
|
24
|
+
* It is **not** Node.js-compatible.
|
|
25
|
+
*
|
|
26
|
+
* @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}
|
|
27
|
+
* @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.
|
|
28
|
+
* @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}
|
|
29
|
+
* @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.
|
|
30
|
+
* If not specified, the token will not be associated with a document, and an empty string will be used.
|
|
31
|
+
* @param user - User with whom generated tokens will be associated.
|
|
32
|
+
* If not specified, the token will not be associated with a user, and a randomly generated mock user will be
|
|
33
|
+
* used instead.
|
|
34
|
+
* See {@link @fluidframework/protocol-definitions#ITokenClaims.user}
|
|
35
|
+
* @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.
|
|
36
|
+
* Expiration = now + lifetime.
|
|
37
|
+
* Expressed in seconds.
|
|
38
|
+
* Default: 3600 (1 hour).
|
|
39
|
+
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
40
|
+
* Default: `1.0`.
|
|
25
41
|
*/
|
|
26
42
|
export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Generates an arbitrary ("random") {@link @fluidframework/protocol-definitions#IUser} by generating a
|
|
45
|
+
* random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.
|
|
46
|
+
*/
|
|
27
47
|
export declare function generateUser(): IUser;
|
|
28
48
|
//# sourceMappingURL=generateToken.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateToken.d.ts","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateToken.d.ts","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAgB,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAE3F;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CACzB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EAAE,EACnB,UAAU,CAAC,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,KAAK,EACZ,QAAQ,GAAE,MAAgB,EAC1B,GAAG,GAAE,MAAc,GACpB,MAAM,CAgCR;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,KAAK,CASpC"}
|
package/lib/generateToken.js
CHANGED
|
@@ -21,11 +21,31 @@ import { v4 as uuid } from "uuid";
|
|
|
21
21
|
* interdependencies between service and client packages.
|
|
22
22
|
*/
|
|
23
23
|
/**
|
|
24
|
-
* Generates a
|
|
25
|
-
*
|
|
24
|
+
* Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)
|
|
25
|
+
* to authorize access to a Routerlicious-based Fluid service.
|
|
26
|
+
*
|
|
27
|
+
* @remarks Note: this function uses a browser friendly auth library
|
|
28
|
+
* ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.
|
|
29
|
+
* It is **not** Node.js-compatible.
|
|
30
|
+
*
|
|
31
|
+
* @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}
|
|
32
|
+
* @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.
|
|
33
|
+
* @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}
|
|
34
|
+
* @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.
|
|
35
|
+
* If not specified, the token will not be associated with a document, and an empty string will be used.
|
|
36
|
+
* @param user - User with whom generated tokens will be associated.
|
|
37
|
+
* If not specified, the token will not be associated with a user, and a randomly generated mock user will be
|
|
38
|
+
* used instead.
|
|
39
|
+
* See {@link @fluidframework/protocol-definitions#ITokenClaims.user}
|
|
40
|
+
* @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.
|
|
41
|
+
* Expiration = now + lifetime.
|
|
42
|
+
* Expressed in seconds.
|
|
43
|
+
* Default: 3600 (1 hour).
|
|
44
|
+
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
45
|
+
* Default: `1.0`.
|
|
26
46
|
*/
|
|
27
47
|
export function generateToken(tenantId, key, scopes, documentId, user, lifetime = 60 * 60, ver = "1.0") {
|
|
28
|
-
let userClaim =
|
|
48
|
+
let userClaim = user ? user : generateUser();
|
|
29
49
|
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
30
50
|
userClaim = generateUser();
|
|
31
51
|
}
|
|
@@ -40,14 +60,24 @@ export function generateToken(tenantId, key, scopes, documentId, user, lifetime
|
|
|
40
60
|
iat: now,
|
|
41
61
|
exp: now + lifetime,
|
|
42
62
|
ver,
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
43
64
|
jti: uuid(),
|
|
44
65
|
};
|
|
45
66
|
const utf8Key = { utf8: key };
|
|
46
|
-
return jsrsasign.jws.JWS.sign(
|
|
67
|
+
return jsrsasign.jws.JWS.sign(
|
|
68
|
+
// External API uses null
|
|
69
|
+
// eslint-disable-next-line unicorn/no-null
|
|
70
|
+
null, JSON.stringify({ alg: "HS256", typ: "JWT" }), claims, utf8Key);
|
|
47
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Generates an arbitrary ("random") {@link @fluidframework/protocol-definitions#IUser} by generating a
|
|
74
|
+
* random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.
|
|
75
|
+
*/
|
|
48
76
|
export function generateUser() {
|
|
49
77
|
const randomUser = {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
50
79
|
id: uuid(),
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
51
81
|
name: uuid(),
|
|
52
82
|
};
|
|
53
83
|
return randomUser;
|
package/lib/generateToken.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAIlC;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,aAAa,CACzB,QAAgB,EAChB,GAAW,EACX,MAAmB,EACnB,UAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE,EAC1B,MAAc,KAAK;IAEnB,IAAI,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;IAC7C,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,SAAS,CAAC,EAAE,KAAK,SAAS,EAAE;QACnD,SAAS,GAAG,YAAY,EAAE,CAAC;KAC9B;IAED,0BAA0B;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,EAAE,CAAC;IAE/B,MAAM,MAAM,GAAmC;QAC3C,UAAU,EAAE,KAAK;QACjB,MAAM;QACN,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,QAAQ;QACnB,GAAG;QACH,sGAAsG;QACtG,GAAG,EAAE,IAAI,EAAE;KACd,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAE9B,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;IACzB,yBAAyB;IACzB,2CAA2C;IAC3C,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAC5C,MAAM,EACN,OAAO,CACV,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY;IACxB,MAAM,UAAU,GAAG;QACf,sGAAsG;QACtG,EAAE,EAAE,IAAI,EAAE;QACV,sGAAsG;QACtG,IAAI,EAAE,IAAI,EAAE;KACf,CAAC;IAEF,OAAO,UAAU,CAAC;AACtB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\n\n/**\n * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no\n * need for different implementations, so they should be kept in sync if changes are needed.\n *\n * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries\n * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which\n * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function\n * exported, so it needs to be sourced from either the package itself or a non-dev dependency.\n *\n * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that\n * no longer works because the azure packages are in a separate release group.\n *\n * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token\n * generation, you should use the function available in the server-services-client package in order to avoid\n * interdependencies between service and client packages.\n */\n\n/**\n * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)\n * to authorize access to a Routerlicious-based Fluid service.\n *\n * @remarks Note: this function uses a browser friendly auth library\n * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.\n * It is **not** Node.js-compatible.\n *\n * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}\n * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.\n * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}\n * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.\n * If not specified, the token will not be associated with a document, and an empty string will be used.\n * @param user - User with whom generated tokens will be associated.\n * If not specified, the token will not be associated with a user, and a randomly generated mock user will be\n * used instead.\n * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}\n * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.\n * Expiration = now + lifetime.\n * Expressed in seconds.\n * Default: 3600 (1 hour).\n * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.\n * Default: `1.0`.\n */\nexport function generateToken(\n tenantId: string,\n key: string,\n scopes: ScopeType[],\n documentId?: string,\n user?: IUser,\n lifetime: number = 60 * 60,\n ver: string = \"1.0\",\n): string {\n let userClaim = user ? user : generateUser();\n if (userClaim.id === \"\" || userClaim.id === undefined) {\n userClaim = generateUser();\n }\n\n // Current time in seconds\n const now = Math.round(Date.now() / 1000);\n const docId = documentId ?? \"\";\n\n const claims: ITokenClaims & { jti: string } = {\n documentId: docId,\n scopes,\n tenantId,\n user: userClaim,\n iat: now,\n exp: now + lifetime,\n ver,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n jti: uuid(),\n };\n\n const utf8Key = { utf8: key };\n\n return jsrsasign.jws.JWS.sign(\n // External API uses null\n // eslint-disable-next-line unicorn/no-null\n null,\n JSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n claims,\n utf8Key,\n );\n}\n\n/**\n * Generates an arbitrary (\"random\") {@link @fluidframework/protocol-definitions#IUser} by generating a\n * random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.\n */\nexport function generateUser(): IUser {\n const randomUser = {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n id: uuid(),\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n name: uuid(),\n };\n\n return randomUser;\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* A set of helper utilities for building backend APIs for use with
|
|
6
|
+
* A set of helper utilities for building backend APIs for use with
|
|
7
|
+
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
8
|
+
*
|
|
9
|
+
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
10
|
+
* to be run in a browser context.
|
|
11
|
+
* It is **not** Node.js-compatible.
|
|
7
12
|
*
|
|
8
13
|
* @packageDocumentation
|
|
9
14
|
*/
|
|
10
|
-
export { ScopeType } from "@fluidframework/protocol-definitions";
|
|
15
|
+
export { IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
11
16
|
export { generateToken } from "./generateToken";
|
|
12
17
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* A set of helper utilities for building backend APIs for use with
|
|
6
|
+
* A set of helper utilities for building backend APIs for use with
|
|
7
|
+
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
8
|
+
*
|
|
9
|
+
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
10
|
+
* to be run in a browser context.
|
|
11
|
+
* It is **not** Node.js-compatible.
|
|
7
12
|
*
|
|
8
13
|
* @packageDocumentation
|
|
9
14
|
*/
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH,OAAO,EAAS,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A set of helper utilities for building backend APIs for use with\n * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.\n *\n * Note that this library's primary entry-point ({@link generateToken}) is only intended\n * to be run in a browser context.\n * It is **not** Node.js-compatible.\n *\n * @packageDocumentation\n */\n\nexport { IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/azure-service-utils";
|
|
8
|
-
export declare const pkgVersion = "1.0
|
|
8
|
+
export declare const pkgVersion = "1.1.0-101037";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,wCAAwC,CAAC;AAC7D,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,wCAAwC,CAAC;AAC7D,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,qCAAqC,CAAC;AAC7D,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,qCAAqC,CAAC;AAC7D,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/azure-service-utils\";\nexport const pkgVersion = \"1.1.0-101037\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/azure-service-utils",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0-101037",
|
|
4
4
|
"description": "Helper service-side utilities for connecting to Azure Fluid Relay service",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -28,8 +28,11 @@
|
|
|
28
28
|
"clean": "rimraf dist *.tsbuildinfo *.build.log",
|
|
29
29
|
"eslint": "eslint --format stylish src",
|
|
30
30
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
31
|
-
"
|
|
32
|
-
"lint
|
|
31
|
+
"format": "npm run prettier:fix",
|
|
32
|
+
"lint": "npm run prettier && npm run eslint",
|
|
33
|
+
"lint:fix": "npm run prettier:fix && npm run eslint:fix",
|
|
34
|
+
"prettier": "prettier --check . --ignore-path ../../../.prettierignore",
|
|
35
|
+
"prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
|
|
33
36
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
34
37
|
"tsc": "tsc",
|
|
35
38
|
"tsfmt": "tsfmt --verify",
|
|
@@ -37,27 +40,29 @@
|
|
|
37
40
|
"typetests:gen": "fluid-type-validator -g -d ."
|
|
38
41
|
},
|
|
39
42
|
"dependencies": {
|
|
40
|
-
"@fluidframework/protocol-definitions": "^0.
|
|
41
|
-
"jsrsasign": "^10.
|
|
43
|
+
"@fluidframework/protocol-definitions": "^1.0.0",
|
|
44
|
+
"jsrsasign": "^10.5.25",
|
|
42
45
|
"uuid": "^8.3.1"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
45
|
-
"@fluidframework/azure-service-utils-previous": "npm:@fluidframework/azure-service-utils
|
|
46
|
-
"@fluidframework/build-common": "^0.
|
|
47
|
-
"@fluidframework/build-tools": "^0.
|
|
48
|
-
"@fluidframework/eslint-config-fluid": "^0.
|
|
48
|
+
"@fluidframework/azure-service-utils-previous": "npm:@fluidframework/azure-service-utils@1.0.0-73930",
|
|
49
|
+
"@fluidframework/build-common": "^1.0.0",
|
|
50
|
+
"@fluidframework/build-tools": "^0.4.4000",
|
|
51
|
+
"@fluidframework/eslint-config-fluid": "^1.0.0",
|
|
49
52
|
"@microsoft/api-extractor": "^7.22.2",
|
|
50
53
|
"@rushstack/eslint-config": "^2.5.1",
|
|
51
54
|
"@types/jsrsasign": "^8.0.8",
|
|
52
55
|
"concurrently": "^6.2.0",
|
|
53
|
-
"copyfiles": "^2.1
|
|
56
|
+
"copyfiles": "^2.4.1",
|
|
54
57
|
"eslint": "~8.6.0",
|
|
58
|
+
"eslint-config-prettier": "~8.5.0",
|
|
59
|
+
"prettier": "~2.6.2",
|
|
55
60
|
"rimraf": "^2.6.2",
|
|
56
61
|
"typescript": "~4.5.5",
|
|
57
62
|
"typescript-formatter": "7.1.0"
|
|
58
63
|
},
|
|
59
64
|
"typeValidation": {
|
|
60
|
-
"version": "1.
|
|
65
|
+
"version": "1.1.0",
|
|
61
66
|
"broken": {}
|
|
62
67
|
}
|
|
63
68
|
}
|
package/src/generateToken.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
import type { ITokenClaims, IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
7
5
|
import { KJUR as jsrsasign } from "jsrsasign";
|
|
8
6
|
import { v4 as uuid } from "uuid";
|
|
9
7
|
|
|
8
|
+
import type { ITokenClaims, IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
9
|
+
|
|
10
10
|
/**
|
|
11
11
|
* IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no
|
|
12
12
|
* need for different implementations, so they should be kept in sync if changes are needed.
|
|
@@ -25,8 +25,28 @@ import { v4 as uuid } from "uuid";
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Generates a
|
|
29
|
-
*
|
|
28
|
+
* Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)
|
|
29
|
+
* to authorize access to a Routerlicious-based Fluid service.
|
|
30
|
+
*
|
|
31
|
+
* @remarks Note: this function uses a browser friendly auth library
|
|
32
|
+
* ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.
|
|
33
|
+
* It is **not** Node.js-compatible.
|
|
34
|
+
*
|
|
35
|
+
* @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}
|
|
36
|
+
* @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.
|
|
37
|
+
* @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}
|
|
38
|
+
* @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.
|
|
39
|
+
* If not specified, the token will not be associated with a document, and an empty string will be used.
|
|
40
|
+
* @param user - User with whom generated tokens will be associated.
|
|
41
|
+
* If not specified, the token will not be associated with a user, and a randomly generated mock user will be
|
|
42
|
+
* used instead.
|
|
43
|
+
* See {@link @fluidframework/protocol-definitions#ITokenClaims.user}
|
|
44
|
+
* @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.
|
|
45
|
+
* Expiration = now + lifetime.
|
|
46
|
+
* Expressed in seconds.
|
|
47
|
+
* Default: 3600 (1 hour).
|
|
48
|
+
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
49
|
+
* Default: `1.0`.
|
|
30
50
|
*/
|
|
31
51
|
export function generateToken(
|
|
32
52
|
tenantId: string,
|
|
@@ -35,8 +55,9 @@ export function generateToken(
|
|
|
35
55
|
documentId?: string,
|
|
36
56
|
user?: IUser,
|
|
37
57
|
lifetime: number = 60 * 60,
|
|
38
|
-
ver: string = "1.0"
|
|
39
|
-
|
|
58
|
+
ver: string = "1.0",
|
|
59
|
+
): string {
|
|
60
|
+
let userClaim = user ? user : generateUser();
|
|
40
61
|
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
41
62
|
userClaim = generateUser();
|
|
42
63
|
}
|
|
@@ -45,7 +66,7 @@ export function generateToken(
|
|
|
45
66
|
const now = Math.round(Date.now() / 1000);
|
|
46
67
|
const docId = documentId ?? "";
|
|
47
68
|
|
|
48
|
-
const claims: ITokenClaims & { jti: string
|
|
69
|
+
const claims: ITokenClaims & { jti: string } = {
|
|
49
70
|
documentId: docId,
|
|
50
71
|
scopes,
|
|
51
72
|
tenantId,
|
|
@@ -53,16 +74,31 @@ export function generateToken(
|
|
|
53
74
|
iat: now,
|
|
54
75
|
exp: now + lifetime,
|
|
55
76
|
ver,
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
56
78
|
jti: uuid(),
|
|
57
79
|
};
|
|
58
80
|
|
|
59
81
|
const utf8Key = { utf8: key };
|
|
60
|
-
|
|
82
|
+
|
|
83
|
+
return jsrsasign.jws.JWS.sign(
|
|
84
|
+
// External API uses null
|
|
85
|
+
// eslint-disable-next-line unicorn/no-null
|
|
86
|
+
null,
|
|
87
|
+
JSON.stringify({ alg: "HS256", typ: "JWT" }),
|
|
88
|
+
claims,
|
|
89
|
+
utf8Key,
|
|
90
|
+
);
|
|
61
91
|
}
|
|
62
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Generates an arbitrary ("random") {@link @fluidframework/protocol-definitions#IUser} by generating a
|
|
95
|
+
* random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.
|
|
96
|
+
*/
|
|
63
97
|
export function generateUser(): IUser {
|
|
64
98
|
const randomUser = {
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
65
100
|
id: uuid(),
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
66
102
|
name: uuid(),
|
|
67
103
|
};
|
|
68
104
|
|
package/src/index.ts
CHANGED
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* A set of helper utilities for building backend APIs for use with
|
|
7
|
+
* A set of helper utilities for building backend APIs for use with
|
|
8
|
+
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
9
|
+
*
|
|
10
|
+
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
11
|
+
* to be run in a browser context.
|
|
12
|
+
* It is **not** Node.js-compatible.
|
|
8
13
|
*
|
|
9
14
|
* @packageDocumentation
|
|
10
15
|
*/
|
|
11
16
|
|
|
12
|
-
export { ScopeType } from "@fluidframework/protocol-definitions";
|
|
17
|
+
export { IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
13
18
|
export { generateToken } from "./generateToken";
|
package/src/packageVersion.ts
CHANGED
package/tsconfig.esnext.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
],
|
|
13
|
-
"composite": true
|
|
14
|
-
},
|
|
15
|
-
"include": [
|
|
16
|
-
"src/**/*"
|
|
17
|
-
]
|
|
2
|
+
"extends": "@fluidframework/build-common/ts-common-config.json",
|
|
3
|
+
"exclude": ["src/test/**/*"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"strictNullChecks": true,
|
|
6
|
+
"rootDir": "./src",
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"types": ["node"],
|
|
9
|
+
"composite": true,
|
|
10
|
+
},
|
|
11
|
+
"include": ["src/**/*"],
|
|
18
12
|
}
|