@fluidframework/azure-service-utils 1.2.0-106934 → 1.2.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/.eslintrc.js +9 -40
- package/.prettierignore +5 -0
- package/README.md +59 -0
- package/api-extractor.json +10 -10
- package/dist/generateToken.d.ts.map +1 -1
- package/dist/generateToken.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.map +1 -1
- package/lib/generateToken.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 +64 -67
- package/src/generateToken.ts +41 -41
- package/src/packageVersion.ts +1 -1
- package/tsconfig.esnext.json +5 -5
- package/tsconfig.json +9 -10
package/.eslintrc.js
CHANGED
|
@@ -4,44 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// Require jsdoc/tsdoc comments on public/exported API items.
|
|
17
|
-
"jsdoc/require-jsdoc": [
|
|
18
|
-
"error",
|
|
19
|
-
{
|
|
20
|
-
// Indicates that only module exports should be flagged for lacking jsdoc comments
|
|
21
|
-
publicOnly: true,
|
|
22
|
-
enableFixer: false, // Prevents eslint from adding empty comment blocks when run with `--fix`
|
|
23
|
-
require: {
|
|
24
|
-
ClassDeclaration: true,
|
|
25
|
-
FunctionDeclaration: true,
|
|
26
|
-
|
|
27
|
-
// Will report for *any* methods on exported classes, regardless of whether or not they are public
|
|
28
|
-
MethodDefinition: false,
|
|
29
|
-
},
|
|
30
|
-
contexts: ["TSEnumDeclaration", "TSInterfaceDeclaration", "TSTypeAliasDeclaration"],
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
|
|
34
|
-
// Ensure jsdoc/tsdoc comments contain a main description component
|
|
35
|
-
// (disallows empty comments / only tags).
|
|
36
|
-
"jsdoc/require-description": ["error", { checkConstructors: false }],
|
|
37
|
-
},
|
|
38
|
-
overrides: [
|
|
39
|
-
{
|
|
40
|
-
files: ["packageVersion.ts"],
|
|
41
|
-
rules: {
|
|
42
|
-
"jsdoc/require-jsdoc": "off",
|
|
43
|
-
"jsdoc/require-description": "off",
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
],
|
|
7
|
+
extends: [require.resolve("@fluidframework/eslint-config-fluid/strict"), "prettier"],
|
|
8
|
+
plugins: ["eslint-plugin-jsdoc"],
|
|
9
|
+
parserOptions: {
|
|
10
|
+
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
|
|
11
|
+
},
|
|
12
|
+
rules: {
|
|
13
|
+
"import/no-unassigned-import": "off",
|
|
14
|
+
"@typescript-eslint/strict-boolean-expressions": "off",
|
|
15
|
+
},
|
|
47
16
|
};
|
package/.prettierignore
ADDED
package/README.md
CHANGED
|
@@ -5,3 +5,62 @@ A set of helper utilities for building backend APIs for use with Azure Fluid Rel
|
|
|
5
5
|
## generateToken
|
|
6
6
|
|
|
7
7
|
This function will generate a JWT token that can be sent to an `ITokenProvider` instance that is being passed into the constructor of `AzureClient`. The `tenantId` and `key` map to the values provided to you as part of the onboarding process for the Azure Fluid Relay service. The `user` objects allows you to define the properties for the current user that this token will be used to authenticate for. The values passed in here represent the values that will be supplied as part of the `audience` in the `FluidContainer` that will be provided by the `AzureClient`.
|
|
8
|
+
|
|
9
|
+
<!-- AUTO-GENERATED-CONTENT:START (README_CONTRIBUTION_GUIDELINES_SECTION:includeHeading=TRUE) -->
|
|
10
|
+
|
|
11
|
+
<!-- prettier-ignore-start -->
|
|
12
|
+
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
13
|
+
|
|
14
|
+
## Contribution Guidelines
|
|
15
|
+
|
|
16
|
+
There are many ways to [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid.
|
|
17
|
+
|
|
18
|
+
- Participate in Q&A in our [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
|
|
19
|
+
- [Submit bugs](https://github.com/microsoft/FluidFramework/issues) and help us verify fixes as they are checked in.
|
|
20
|
+
- Review the [source code changes](https://github.com/microsoft/FluidFramework/pulls).
|
|
21
|
+
- [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
|
|
22
|
+
|
|
23
|
+
Detailed instructions for working in the repo can be found in the [Wiki](https://github.com/microsoft/FluidFramework/wiki).
|
|
24
|
+
|
|
25
|
+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
26
|
+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
|
27
|
+
|
|
28
|
+
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
29
|
+
Use of these trademarks or logos must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/trademarks).
|
|
30
|
+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
|
31
|
+
|
|
32
|
+
<!-- prettier-ignore-end -->
|
|
33
|
+
|
|
34
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
35
|
+
|
|
36
|
+
<!-- AUTO-GENERATED-CONTENT:START (README_HELP_SECTION:includeHeading=TRUE) -->
|
|
37
|
+
|
|
38
|
+
<!-- prettier-ignore-start -->
|
|
39
|
+
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
40
|
+
|
|
41
|
+
## Help
|
|
42
|
+
|
|
43
|
+
Not finding what you're looking for in this README?
|
|
44
|
+
Check out our [GitHub Wiki](https://github.com/microsoft/FluidFramework/wiki) or [fluidframework.com](https://fluidframework.com/docs/).
|
|
45
|
+
|
|
46
|
+
Still not finding what you're looking for? Please [file an issue](https://github.com/microsoft/FluidFramework/wiki/Submitting-Bugs-and-Feature-Requests).
|
|
47
|
+
Thank you!
|
|
48
|
+
|
|
49
|
+
<!-- prettier-ignore-end -->
|
|
50
|
+
|
|
51
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
52
|
+
|
|
53
|
+
<!-- AUTO-GENERATED-CONTENT:START (README_TRADEMARK_SECTION:includeHeading=TRUE) -->
|
|
54
|
+
|
|
55
|
+
<!-- prettier-ignore-start -->
|
|
56
|
+
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
57
|
+
|
|
58
|
+
## Trademark
|
|
59
|
+
|
|
60
|
+
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
61
|
+
Use of these trademarks or logos must follow Microsoft's [Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
|
|
62
|
+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
|
63
|
+
|
|
64
|
+
<!-- prettier-ignore-end -->
|
|
65
|
+
|
|
66
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
package/api-extractor.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "@fluidframework/build-common/api-extractor-common-strict.json",
|
|
4
|
+
"apiReport": {
|
|
5
|
+
"enabled": true,
|
|
6
|
+
"reportFolder": "<projectFolder>/../../../api-report/"
|
|
7
|
+
},
|
|
8
|
+
"docModel": {
|
|
9
|
+
"enabled": true,
|
|
10
|
+
"apiJsonFilePath": "<projectFolder>/../../_api-extractor-temp/doc-models/<unscopedPackageName>.api.json"
|
|
11
|
+
}
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAC5B,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,GACjB,MAAM,CAgCR;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,KAAK,CASpC"}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAC5B,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;QACtD,SAAS,GAAG,YAAY,EAAE,CAAC;KAC3B;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;QAC9C,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;KACX,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAE9B,OAAO,gBAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;IAC5B,yBAAyB;IACzB,2CAA2C;IAC3C,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAC5C,MAAM,EACN,OAAO,CACP,CAAC;AACH,CAAC;AAxCD,sCAwCC;AAED;;;GAGG;AACH,SAAgB,YAAY;IAC3B,MAAM,UAAU,GAAG;QAClB,sGAAsG;QACtG,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,sGAAsG;QACtG,IAAI,EAAE,IAAA,SAAI,GAAE;KACZ,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,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\ttenantId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tdocumentId?: string,\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = user ? user : generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(Date.now() / 1000);\n\tconst docId = documentId ?? \"\";\n\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: docId,\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tjti: uuid(),\n\t};\n\n\tconst utf8Key = { utf8: key };\n\n\treturn jsrsasign.jws.JWS.sign(\n\t\t// External API uses null\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\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\tconst randomUser = {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tid: uuid(),\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tname: uuid(),\n\t};\n\n\treturn randomUser;\n}\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.2.0
|
|
8
|
+
export declare const pkgVersion = "1.2.0";
|
|
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,UAAU,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.2.0
|
|
11
|
+
exports.pkgVersion = "1.2.0";
|
|
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,OAAO,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.2.0\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAC5B,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,GACjB,MAAM,CAgCR;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,KAAK,CASpC"}
|
package/lib/generateToken.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAC5B,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;QACtD,SAAS,GAAG,YAAY,EAAE,CAAC;KAC3B;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;QAC9C,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;KACX,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAE9B,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI;IAC5B,yBAAyB;IACzB,2CAA2C;IAC3C,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAC5C,MAAM,EACN,OAAO,CACP,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC3B,MAAM,UAAU,GAAG;QAClB,sGAAsG;QACtG,EAAE,EAAE,IAAI,EAAE;QACV,sGAAsG;QACtG,IAAI,EAAE,IAAI,EAAE;KACZ,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,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\ttenantId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tdocumentId?: string,\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = user ? user : generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(Date.now() / 1000);\n\tconst docId = documentId ?? \"\";\n\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: docId,\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tjti: uuid(),\n\t};\n\n\tconst utf8Key = { utf8: key };\n\n\treturn jsrsasign.jws.JWS.sign(\n\t\t// External API uses null\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\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\tconst randomUser = {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tid: uuid(),\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tname: uuid(),\n\t};\n\n\treturn randomUser;\n}\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.2.0
|
|
8
|
+
export declare const pkgVersion = "1.2.0";
|
|
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,UAAU,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,OAAO,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.2.0\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,69 +1,66 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"version": "1.1.0",
|
|
67
|
-
"broken": {}
|
|
68
|
-
}
|
|
2
|
+
"name": "@fluidframework/azure-service-utils",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Helper service-side utilities for connecting to Azure Fluid Relay service",
|
|
5
|
+
"homepage": "https://fluidframework.com",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/microsoft/FluidFramework.git",
|
|
9
|
+
"directory": "packages/framework/azure-service-utils"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Microsoft and contributors",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"module": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "npm run build:genver && concurrently npm:build:compile npm:lint && npm run build:docs",
|
|
19
|
+
"build:commonjs": "npm run tsc && npm run build:test",
|
|
20
|
+
"build:compile": "concurrently npm:build:commonjs npm:build:esnext",
|
|
21
|
+
"build:docs": "api-extractor run --local",
|
|
22
|
+
"build:esnext": "tsc --project ./tsconfig.esnext.json",
|
|
23
|
+
"build:full": "npm run build",
|
|
24
|
+
"build:full:compile": "npm run build:compile",
|
|
25
|
+
"build:genver": "gen-version",
|
|
26
|
+
"build:test": "tsc --project ./src/test/tsconfig.json",
|
|
27
|
+
"ci:build:docs": "api-extractor run",
|
|
28
|
+
"clean": "rimraf dist lib *.tsbuildinfo *.build.log",
|
|
29
|
+
"eslint": "eslint --format stylish src",
|
|
30
|
+
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
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",
|
|
36
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
37
|
+
"tsc": "tsc",
|
|
38
|
+
"typetests:gen": "flub generate typetests --generate --dir .",
|
|
39
|
+
"typetests:prepare": "flub generate typetests --prepare --dir . --pin"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@fluidframework/protocol-definitions": "^1.0.0",
|
|
43
|
+
"jsrsasign": "^11.1.0",
|
|
44
|
+
"uuid": "^8.3.1"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@fluid-tools/build-cli": "^0.10.0",
|
|
48
|
+
"@fluidframework/azure-service-utils-previous": "npm:@fluidframework/azure-service-utils@1.1.1",
|
|
49
|
+
"@fluidframework/build-common": "^1.2.0",
|
|
50
|
+
"@fluidframework/build-tools": "^0.10.0",
|
|
51
|
+
"@fluidframework/eslint-config-fluid": "^2.0.0",
|
|
52
|
+
"@microsoft/api-extractor": "^7.34.4",
|
|
53
|
+
"@types/jsrsasign": "^10.5.12",
|
|
54
|
+
"concurrently": "^7.6.0",
|
|
55
|
+
"copyfiles": "^2.4.1",
|
|
56
|
+
"eslint": "~8.6.0",
|
|
57
|
+
"eslint-config-prettier": "~8.5.0",
|
|
58
|
+
"eslint-plugin-jsdoc": "~39.3.0",
|
|
59
|
+
"prettier": "~2.6.2",
|
|
60
|
+
"rimraf": "^2.6.2",
|
|
61
|
+
"typescript": "~4.5.5"
|
|
62
|
+
},
|
|
63
|
+
"typeValidation": {
|
|
64
|
+
"broken": {}
|
|
65
|
+
}
|
|
69
66
|
}
|
package/src/generateToken.ts
CHANGED
|
@@ -49,45 +49,45 @@ import type { ITokenClaims, IUser, ScopeType } from "@fluidframework/protocol-de
|
|
|
49
49
|
* Default: `1.0`.
|
|
50
50
|
*/
|
|
51
51
|
export function generateToken(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
tenantId: string,
|
|
53
|
+
key: string,
|
|
54
|
+
scopes: ScopeType[],
|
|
55
|
+
documentId?: string,
|
|
56
|
+
user?: IUser,
|
|
57
|
+
lifetime: number = 60 * 60,
|
|
58
|
+
ver: string = "1.0",
|
|
59
59
|
): string {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
let userClaim = user ? user : generateUser();
|
|
61
|
+
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
62
|
+
userClaim = generateUser();
|
|
63
|
+
}
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
// Current time in seconds
|
|
66
|
+
const now = Math.round(Date.now() / 1000);
|
|
67
|
+
const docId = documentId ?? "";
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
const claims: ITokenClaims & { jti: string } = {
|
|
70
|
+
documentId: docId,
|
|
71
|
+
scopes,
|
|
72
|
+
tenantId,
|
|
73
|
+
user: userClaim,
|
|
74
|
+
iat: now,
|
|
75
|
+
exp: now + lifetime,
|
|
76
|
+
ver,
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
78
|
+
jti: uuid(),
|
|
79
|
+
};
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
const utf8Key = { utf8: key };
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
+
);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/**
|
|
@@ -95,12 +95,12 @@ export function generateToken(
|
|
|
95
95
|
* random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.
|
|
96
96
|
*/
|
|
97
97
|
export function generateUser(): IUser {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
const randomUser = {
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
100
|
+
id: uuid(),
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
102
|
+
name: uuid(),
|
|
103
|
+
};
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
return randomUser;
|
|
106
106
|
}
|
package/src/packageVersion.ts
CHANGED
package/tsconfig.esnext.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"include": ["src/**/*"],
|
|
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
|
+
"composite": true,
|
|
9
|
+
},
|
|
10
|
+
"include": ["src/**/*"],
|
|
12
11
|
}
|