@fluidframework/azure-service-utils 2.0.0-dev.6.4.0.192049 → 2.0.0-dev.7.2.0.204906
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 +20 -1
- package/CHANGELOG.md +52 -0
- package/api-extractor.json +1 -9
- package/api-report/azure-service-utils.api.md +17 -0
- package/dist/azure-service-utils-alpha.d.ts +64 -0
- package/dist/azure-service-utils-beta.d.ts +64 -0
- package/dist/azure-service-utils-public.d.ts +64 -0
- package/dist/azure-service-utils-untrimmed.d.ts +64 -0
- package/dist/generateToken.d.ts +2 -0
- package/dist/generateToken.d.ts.map +1 -1
- package/dist/generateToken.js +8 -4
- package/dist/generateToken.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -10
- package/dist/index.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/generateToken.d.ts +2 -0
- package/lib/generateToken.d.ts.map +1 -1
- package/lib/generateToken.js +8 -4
- package/lib/generateToken.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -10
- package/lib/index.js.map +1 -1
- package/package.json +25 -15
- package/src/generateToken.ts +6 -3
- package/src/index.ts +3 -1
package/.eslintrc.js
CHANGED
|
@@ -5,12 +5,31 @@
|
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
7
|
extends: [require.resolve("@fluidframework/eslint-config-fluid/strict"), "prettier"],
|
|
8
|
-
plugins: ["eslint-plugin-jsdoc"],
|
|
9
8
|
parserOptions: {
|
|
10
9
|
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
|
|
11
10
|
},
|
|
12
11
|
rules: {
|
|
13
12
|
"import/no-unassigned-import": "off",
|
|
14
13
|
"@typescript-eslint/strict-boolean-expressions": "off",
|
|
14
|
+
|
|
15
|
+
// Useful for developer accessibility
|
|
16
|
+
"unicorn/prevent-abbreviations": [
|
|
17
|
+
"error",
|
|
18
|
+
{
|
|
19
|
+
allowList: {
|
|
20
|
+
// Industry-standard index variable name.
|
|
21
|
+
i: true,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
],
|
|
15
25
|
},
|
|
26
|
+
overrides: [
|
|
27
|
+
{
|
|
28
|
+
// Overrides for type-tests
|
|
29
|
+
files: ["src/test/types/*"],
|
|
30
|
+
rules: {
|
|
31
|
+
"unicorn/prevent-abbreviations": "off",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
16
35
|
};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# @fluidframework/azure-service-utils
|
|
2
2
|
|
|
3
|
+
## 2.0.0-internal.7.1.0
|
|
4
|
+
|
|
5
|
+
Dependency updates only.
|
|
6
|
+
|
|
7
|
+
## 2.0.0-internal.7.0.0
|
|
8
|
+
|
|
9
|
+
### Major Changes
|
|
10
|
+
|
|
11
|
+
- Dependencies on @fluidframework/protocol-definitions package updated to 3.0.0 [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
|
|
12
|
+
|
|
13
|
+
This included the following changes from the protocol-definitions release:
|
|
14
|
+
|
|
15
|
+
- Updating signal interfaces for some planned improvements. The intention is split the interface between signals
|
|
16
|
+
submitted by clients to the server and the resulting signals sent from the server to clients.
|
|
17
|
+
- A new optional type member is available on the ISignalMessage interface and a new ISentSignalMessage interface has
|
|
18
|
+
been added, which will be the typing for signals sent from the client to the server. Both extend a new
|
|
19
|
+
ISignalMessageBase interface that contains common members.
|
|
20
|
+
- The @fluidframework/common-definitions package dependency has been updated to version 1.0.0.
|
|
21
|
+
|
|
22
|
+
- Server upgrade: dependencies on Fluid server packages updated to 2.0.1 [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
|
|
23
|
+
|
|
24
|
+
Dependencies on the following Fluid server package have been updated to version 2.0.1:
|
|
25
|
+
|
|
26
|
+
- @fluidframework/gitresources: 2.0.1
|
|
27
|
+
- @fluidframework/server-kafka-orderer: 2.0.1
|
|
28
|
+
- @fluidframework/server-lambdas: 2.0.1
|
|
29
|
+
- @fluidframework/server-lambdas-driver: 2.0.1
|
|
30
|
+
- @fluidframework/server-local-server: 2.0.1
|
|
31
|
+
- @fluidframework/server-memory-orderer: 2.0.1
|
|
32
|
+
- @fluidframework/protocol-base: 2.0.1
|
|
33
|
+
- @fluidframework/server-routerlicious: 2.0.1
|
|
34
|
+
- @fluidframework/server-routerlicious-base: 2.0.1
|
|
35
|
+
- @fluidframework/server-services: 2.0.1
|
|
36
|
+
- @fluidframework/server-services-client: 2.0.1
|
|
37
|
+
- @fluidframework/server-services-core: 2.0.1
|
|
38
|
+
- @fluidframework/server-services-ordering-kafkanode: 2.0.1
|
|
39
|
+
- @fluidframework/server-services-ordering-rdkafka: 2.0.1
|
|
40
|
+
- @fluidframework/server-services-ordering-zookeeper: 2.0.1
|
|
41
|
+
- @fluidframework/server-services-shared: 2.0.1
|
|
42
|
+
- @fluidframework/server-services-telemetry: 2.0.1
|
|
43
|
+
- @fluidframework/server-services-utils: 2.0.1
|
|
44
|
+
- @fluidframework/server-test-utils: 2.0.1
|
|
45
|
+
- tinylicious: 2.0.1
|
|
46
|
+
|
|
47
|
+
- Minimum TypeScript version now 5.1.6 [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
|
|
48
|
+
|
|
49
|
+
The minimum supported TypeScript version for Fluid 2.0 clients is now 5.1.6.
|
|
50
|
+
|
|
51
|
+
## 2.0.0-internal.6.4.0
|
|
52
|
+
|
|
53
|
+
Dependency updates only.
|
|
54
|
+
|
|
3
55
|
## 2.0.0-internal.6.3.0
|
|
4
56
|
|
|
5
57
|
Dependency updates only.
|
package/api-extractor.json
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
-
"extends": "@fluidframework/build-common/api-extractor-
|
|
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
|
-
}
|
|
3
|
+
"extends": "@fluidframework/build-common/api-extractor-base.json"
|
|
12
4
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
## API Report File for "@fluidframework/azure-service-utils"
|
|
2
|
+
|
|
3
|
+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
|
|
7
|
+
import { IUser } from '@fluidframework/protocol-definitions';
|
|
8
|
+
import { ScopeType } from '@fluidframework/protocol-definitions';
|
|
9
|
+
|
|
10
|
+
// @public
|
|
11
|
+
export function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
|
|
12
|
+
|
|
13
|
+
export { IUser }
|
|
14
|
+
|
|
15
|
+
export { ScopeType }
|
|
16
|
+
|
|
17
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of helper utilities for building backend APIs for use with
|
|
3
|
+
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
7
|
+
* to be run in a browser context.
|
|
8
|
+
* It is **not** Node.js-compatible.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { IUser } from '@fluidframework/protocol-definitions';
|
|
14
|
+
import { ScopeType } from '@fluidframework/protocol-definitions';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no
|
|
18
|
+
* need for different implementations, so they should be kept in sync if changes are needed.
|
|
19
|
+
*
|
|
20
|
+
* The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries
|
|
21
|
+
* (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which
|
|
22
|
+
* layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function
|
|
23
|
+
* exported, so it needs to be sourced from either the package itself or a non-dev dependency.
|
|
24
|
+
*
|
|
25
|
+
* The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that
|
|
26
|
+
* no longer works because the azure packages are in a separate release group.
|
|
27
|
+
*
|
|
28
|
+
* If a token needs to be generated on the client side, you should re-use this function. If you need service-side token
|
|
29
|
+
* generation, you should use the function available in the server-services-client package in order to avoid
|
|
30
|
+
* interdependencies between service and client packages.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)
|
|
34
|
+
* to authorize access to a Routerlicious-based Fluid service.
|
|
35
|
+
*
|
|
36
|
+
* @remarks Note: this function uses a browser friendly auth library
|
|
37
|
+
* ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.
|
|
38
|
+
* It is **not** Node.js-compatible.
|
|
39
|
+
*
|
|
40
|
+
* @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}
|
|
41
|
+
* @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.
|
|
42
|
+
* @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}
|
|
43
|
+
* @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.
|
|
44
|
+
* If not specified, the token will not be associated with a document, and an empty string will be used.
|
|
45
|
+
* @param user - User with whom generated tokens will be associated.
|
|
46
|
+
* If not specified, the token will not be associated with a user, and a randomly generated mock user will be
|
|
47
|
+
* used instead.
|
|
48
|
+
* See {@link @fluidframework/protocol-definitions#ITokenClaims.user}
|
|
49
|
+
* @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.
|
|
50
|
+
* Expiration = now + lifetime.
|
|
51
|
+
* Expressed in seconds.
|
|
52
|
+
* Default: 3600 (1 hour).
|
|
53
|
+
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
54
|
+
* Default: `1.0`.
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
|
|
59
|
+
|
|
60
|
+
export { IUser }
|
|
61
|
+
|
|
62
|
+
export { ScopeType }
|
|
63
|
+
|
|
64
|
+
export { }
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of helper utilities for building backend APIs for use with
|
|
3
|
+
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
7
|
+
* to be run in a browser context.
|
|
8
|
+
* It is **not** Node.js-compatible.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { IUser } from '@fluidframework/protocol-definitions';
|
|
14
|
+
import { ScopeType } from '@fluidframework/protocol-definitions';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no
|
|
18
|
+
* need for different implementations, so they should be kept in sync if changes are needed.
|
|
19
|
+
*
|
|
20
|
+
* The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries
|
|
21
|
+
* (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which
|
|
22
|
+
* layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function
|
|
23
|
+
* exported, so it needs to be sourced from either the package itself or a non-dev dependency.
|
|
24
|
+
*
|
|
25
|
+
* The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that
|
|
26
|
+
* no longer works because the azure packages are in a separate release group.
|
|
27
|
+
*
|
|
28
|
+
* If a token needs to be generated on the client side, you should re-use this function. If you need service-side token
|
|
29
|
+
* generation, you should use the function available in the server-services-client package in order to avoid
|
|
30
|
+
* interdependencies between service and client packages.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)
|
|
34
|
+
* to authorize access to a Routerlicious-based Fluid service.
|
|
35
|
+
*
|
|
36
|
+
* @remarks Note: this function uses a browser friendly auth library
|
|
37
|
+
* ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.
|
|
38
|
+
* It is **not** Node.js-compatible.
|
|
39
|
+
*
|
|
40
|
+
* @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}
|
|
41
|
+
* @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.
|
|
42
|
+
* @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}
|
|
43
|
+
* @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.
|
|
44
|
+
* If not specified, the token will not be associated with a document, and an empty string will be used.
|
|
45
|
+
* @param user - User with whom generated tokens will be associated.
|
|
46
|
+
* If not specified, the token will not be associated with a user, and a randomly generated mock user will be
|
|
47
|
+
* used instead.
|
|
48
|
+
* See {@link @fluidframework/protocol-definitions#ITokenClaims.user}
|
|
49
|
+
* @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.
|
|
50
|
+
* Expiration = now + lifetime.
|
|
51
|
+
* Expressed in seconds.
|
|
52
|
+
* Default: 3600 (1 hour).
|
|
53
|
+
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
54
|
+
* Default: `1.0`.
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
|
|
59
|
+
|
|
60
|
+
export { IUser }
|
|
61
|
+
|
|
62
|
+
export { ScopeType }
|
|
63
|
+
|
|
64
|
+
export { }
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of helper utilities for building backend APIs for use with
|
|
3
|
+
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
7
|
+
* to be run in a browser context.
|
|
8
|
+
* It is **not** Node.js-compatible.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { IUser } from '@fluidframework/protocol-definitions';
|
|
14
|
+
import { ScopeType } from '@fluidframework/protocol-definitions';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no
|
|
18
|
+
* need for different implementations, so they should be kept in sync if changes are needed.
|
|
19
|
+
*
|
|
20
|
+
* The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries
|
|
21
|
+
* (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which
|
|
22
|
+
* layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function
|
|
23
|
+
* exported, so it needs to be sourced from either the package itself or a non-dev dependency.
|
|
24
|
+
*
|
|
25
|
+
* The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that
|
|
26
|
+
* no longer works because the azure packages are in a separate release group.
|
|
27
|
+
*
|
|
28
|
+
* If a token needs to be generated on the client side, you should re-use this function. If you need service-side token
|
|
29
|
+
* generation, you should use the function available in the server-services-client package in order to avoid
|
|
30
|
+
* interdependencies between service and client packages.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)
|
|
34
|
+
* to authorize access to a Routerlicious-based Fluid service.
|
|
35
|
+
*
|
|
36
|
+
* @remarks Note: this function uses a browser friendly auth library
|
|
37
|
+
* ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.
|
|
38
|
+
* It is **not** Node.js-compatible.
|
|
39
|
+
*
|
|
40
|
+
* @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}
|
|
41
|
+
* @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.
|
|
42
|
+
* @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}
|
|
43
|
+
* @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.
|
|
44
|
+
* If not specified, the token will not be associated with a document, and an empty string will be used.
|
|
45
|
+
* @param user - User with whom generated tokens will be associated.
|
|
46
|
+
* If not specified, the token will not be associated with a user, and a randomly generated mock user will be
|
|
47
|
+
* used instead.
|
|
48
|
+
* See {@link @fluidframework/protocol-definitions#ITokenClaims.user}
|
|
49
|
+
* @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.
|
|
50
|
+
* Expiration = now + lifetime.
|
|
51
|
+
* Expressed in seconds.
|
|
52
|
+
* Default: 3600 (1 hour).
|
|
53
|
+
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
54
|
+
* Default: `1.0`.
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
|
|
59
|
+
|
|
60
|
+
export { IUser }
|
|
61
|
+
|
|
62
|
+
export { ScopeType }
|
|
63
|
+
|
|
64
|
+
export { }
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of helper utilities for building backend APIs for use with
|
|
3
|
+
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
7
|
+
* to be run in a browser context.
|
|
8
|
+
* It is **not** Node.js-compatible.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { IUser } from '@fluidframework/protocol-definitions';
|
|
14
|
+
import { ScopeType } from '@fluidframework/protocol-definitions';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no
|
|
18
|
+
* need for different implementations, so they should be kept in sync if changes are needed.
|
|
19
|
+
*
|
|
20
|
+
* The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries
|
|
21
|
+
* (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which
|
|
22
|
+
* layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function
|
|
23
|
+
* exported, so it needs to be sourced from either the package itself or a non-dev dependency.
|
|
24
|
+
*
|
|
25
|
+
* The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that
|
|
26
|
+
* no longer works because the azure packages are in a separate release group.
|
|
27
|
+
*
|
|
28
|
+
* If a token needs to be generated on the client side, you should re-use this function. If you need service-side token
|
|
29
|
+
* generation, you should use the function available in the server-services-client package in order to avoid
|
|
30
|
+
* interdependencies between service and client packages.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)
|
|
34
|
+
* to authorize access to a Routerlicious-based Fluid service.
|
|
35
|
+
*
|
|
36
|
+
* @remarks Note: this function uses a browser friendly auth library
|
|
37
|
+
* ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.
|
|
38
|
+
* It is **not** Node.js-compatible.
|
|
39
|
+
*
|
|
40
|
+
* @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}
|
|
41
|
+
* @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.
|
|
42
|
+
* @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}
|
|
43
|
+
* @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.
|
|
44
|
+
* If not specified, the token will not be associated with a document, and an empty string will be used.
|
|
45
|
+
* @param user - User with whom generated tokens will be associated.
|
|
46
|
+
* If not specified, the token will not be associated with a user, and a randomly generated mock user will be
|
|
47
|
+
* used instead.
|
|
48
|
+
* See {@link @fluidframework/protocol-definitions#ITokenClaims.user}
|
|
49
|
+
* @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.
|
|
50
|
+
* Expiration = now + lifetime.
|
|
51
|
+
* Expressed in seconds.
|
|
52
|
+
* Default: 3600 (1 hour).
|
|
53
|
+
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
54
|
+
* Default: `1.0`.
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
|
|
59
|
+
|
|
60
|
+
export { IUser }
|
|
61
|
+
|
|
62
|
+
export { ScopeType }
|
|
63
|
+
|
|
64
|
+
export { }
|
package/dist/generateToken.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ import type { IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
|
38
38
|
* Default: 3600 (1 hour).
|
|
39
39
|
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
40
40
|
* Default: `1.0`.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
41
43
|
*/
|
|
42
44
|
export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
|
|
43
45
|
/**
|
|
@@ -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
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;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,EAG1B,GAAG,GAAE,MAAc,GACjB,MAAM,CA+BR;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,KAAK,CASpC"}
|
package/dist/generateToken.js
CHANGED
|
@@ -46,17 +46,21 @@ const uuid_1 = require("uuid");
|
|
|
46
46
|
* Default: 3600 (1 hour).
|
|
47
47
|
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
48
48
|
* Default: `1.0`.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
49
51
|
*/
|
|
50
|
-
function generateToken(tenantId, key, scopes, documentId, user, lifetime = 60 * 60,
|
|
51
|
-
|
|
52
|
+
function generateToken(tenantId, key, scopes, documentId, user, lifetime = 60 * 60,
|
|
53
|
+
// Naming intended to match `ITokenClaims.ver`
|
|
54
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
55
|
+
ver = "1.0") {
|
|
56
|
+
let userClaim = user ?? generateUser();
|
|
52
57
|
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
53
58
|
userClaim = generateUser();
|
|
54
59
|
}
|
|
55
60
|
// Current time in seconds
|
|
56
61
|
const now = Math.round(Date.now() / 1000);
|
|
57
|
-
const docId = documentId ?? "";
|
|
58
62
|
const claims = {
|
|
59
|
-
documentId:
|
|
63
|
+
documentId: documentId ?? "",
|
|
60
64
|
scopes,
|
|
61
65
|
tenantId,
|
|
62
66
|
user: userClaim,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,yCAA8C;AAC9C,+BAAkC;AAIlC;;;;;;;;;;;;;;;GAeG;AAEH
|
|
1
|
+
{"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,yCAA8C;AAC9C,+BAAkC;AAIlC;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,aAAa,CAC5B,QAAgB,EAChB,GAAW,EACX,MAAmB,EACnB,UAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE;AAC1B,8CAA8C;AAC9C,yDAAyD;AACzD,MAAc,KAAK;IAEnB,IAAI,SAAS,GAAG,IAAI,IAAI,YAAY,EAAE,CAAC;IACvC,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;IAE1C,MAAM,MAAM,GAAmC;QAC9C,UAAU,EAAE,UAAU,IAAI,EAAE;QAC5B,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;AAzCD,sCAyCC;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 *\n * @public\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\t// Naming intended to match `ITokenClaims.ver`\n\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = 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\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: documentId ?? \"\",\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/index.d.ts
CHANGED
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
* A set of helper utilities for building backend APIs for use with
|
|
7
7
|
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
8
8
|
*
|
|
9
|
+
* @remarks
|
|
9
10
|
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
10
11
|
* to be run in a browser context.
|
|
11
12
|
* It is **not** Node.js-compatible.
|
|
12
13
|
*
|
|
13
14
|
* @packageDocumentation
|
|
14
15
|
*/
|
|
15
|
-
export { IUser
|
|
16
|
+
export type { IUser } from "@fluidframework/protocol-definitions";
|
|
17
|
+
export { ScopeType } from "@fluidframework/protocol-definitions";
|
|
16
18
|
export { generateToken } from "./generateToken";
|
|
17
19
|
//# 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;;;;;;;;;;GAUG;AAEH,YAAY,EAAE,KAAK,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,16 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.generateToken = exports.ScopeType = void 0;
|
|
8
|
-
/**
|
|
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.
|
|
15
|
-
*
|
|
16
|
-
* @packageDocumentation
|
|
17
|
-
*/
|
|
18
8
|
var protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
19
9
|
Object.defineProperty(exports, "ScopeType", { enumerable: true, get: function () { return protocol_definitions_1.ScopeType; } });
|
|
20
10
|
var generateToken_1 = require("./generateToken");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAeH,6EAAiE;AAAxD,iHAAA,SAAS,OAAA;AAClB,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 * @remarks\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 type { IUser } from \"@fluidframework/protocol-definitions\";\nexport { ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
|
package/dist/tsdoc-metadata.json
CHANGED
package/lib/generateToken.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ import type { IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
|
38
38
|
* Default: 3600 (1 hour).
|
|
39
39
|
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
40
40
|
* Default: `1.0`.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
41
43
|
*/
|
|
42
44
|
export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
|
|
43
45
|
/**
|
|
@@ -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
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;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,EAG1B,GAAG,GAAE,MAAc,GACjB,MAAM,CA+BR;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,KAAK,CASpC"}
|
package/lib/generateToken.js
CHANGED
|
@@ -43,17 +43,21 @@ import { v4 as uuid } from "uuid";
|
|
|
43
43
|
* Default: 3600 (1 hour).
|
|
44
44
|
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
45
45
|
* Default: `1.0`.
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
46
48
|
*/
|
|
47
|
-
export function generateToken(tenantId, key, scopes, documentId, user, lifetime = 60 * 60,
|
|
48
|
-
|
|
49
|
+
export function generateToken(tenantId, key, scopes, documentId, user, lifetime = 60 * 60,
|
|
50
|
+
// Naming intended to match `ITokenClaims.ver`
|
|
51
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
52
|
+
ver = "1.0") {
|
|
53
|
+
let userClaim = user ?? generateUser();
|
|
49
54
|
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
50
55
|
userClaim = generateUser();
|
|
51
56
|
}
|
|
52
57
|
// Current time in seconds
|
|
53
58
|
const now = Math.round(Date.now() / 1000);
|
|
54
|
-
const docId = documentId ?? "";
|
|
55
59
|
const claims = {
|
|
56
|
-
documentId:
|
|
60
|
+
documentId: documentId ?? "",
|
|
57
61
|
scopes,
|
|
58
62
|
tenantId,
|
|
59
63
|
user: userClaim,
|
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
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAC5B,QAAgB,EAChB,GAAW,EACX,MAAmB,EACnB,UAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE;AAC1B,8CAA8C;AAC9C,yDAAyD;AACzD,MAAc,KAAK;IAEnB,IAAI,SAAS,GAAG,IAAI,IAAI,YAAY,EAAE,CAAC;IACvC,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;IAE1C,MAAM,MAAM,GAAmC;QAC9C,UAAU,EAAE,UAAU,IAAI,EAAE;QAC5B,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 *\n * @public\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\t// Naming intended to match `ITokenClaims.ver`\n\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = 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\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: documentId ?? \"\",\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/index.d.ts
CHANGED
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
* A set of helper utilities for building backend APIs for use with
|
|
7
7
|
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
8
8
|
*
|
|
9
|
+
* @remarks
|
|
9
10
|
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
10
11
|
* to be run in a browser context.
|
|
11
12
|
* It is **not** Node.js-compatible.
|
|
12
13
|
*
|
|
13
14
|
* @packageDocumentation
|
|
14
15
|
*/
|
|
15
|
-
export { IUser
|
|
16
|
+
export type { IUser } from "@fluidframework/protocol-definitions";
|
|
17
|
+
export { ScopeType } from "@fluidframework/protocol-definitions";
|
|
16
18
|
export { generateToken } from "./generateToken";
|
|
17
19
|
//# 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;;;;;;;;;;GAUG;AAEH,YAAY,EAAE,KAAK,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -2,16 +2,6 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
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.
|
|
12
|
-
*
|
|
13
|
-
* @packageDocumentation
|
|
14
|
-
*/
|
|
15
5
|
export { ScopeType } from "@fluidframework/protocol-definitions";
|
|
16
6
|
export { generateToken } from "./generateToken";
|
|
17
7
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,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 * @remarks\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 type { IUser } from \"@fluidframework/protocol-definitions\";\nexport { ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/azure-service-utils",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.7.2.0.204906",
|
|
4
4
|
"description": "Helper service-side utilities for connecting to Azure Fluid Relay service",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -11,29 +11,39 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"author": "Microsoft and contributors",
|
|
13
13
|
"sideEffects": false,
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./lib/index.d.ts",
|
|
18
|
+
"default": "./lib/index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
14
26
|
"main": "dist/index.js",
|
|
15
|
-
"module": "
|
|
27
|
+
"module": "lib/index.js",
|
|
16
28
|
"types": "dist/index.d.ts",
|
|
17
29
|
"dependencies": {
|
|
18
|
-
"@fluidframework/protocol-definitions": "^
|
|
30
|
+
"@fluidframework/protocol-definitions": "^3.0.0",
|
|
19
31
|
"jsrsasign": "^10.5.25",
|
|
20
32
|
"uuid": "^9.0.0"
|
|
21
33
|
},
|
|
22
34
|
"devDependencies": {
|
|
23
|
-
"@fluid-tools/build-cli": "
|
|
24
|
-
"@fluidframework/azure-service-utils-previous": "npm:@fluidframework/azure-service-utils@2.0.0-internal.
|
|
25
|
-
"@fluidframework/build-common": "^2.0.
|
|
26
|
-
"@fluidframework/build-tools": "
|
|
27
|
-
"@fluidframework/eslint-config-fluid": "^
|
|
28
|
-
"@microsoft/api-extractor": "^7.
|
|
35
|
+
"@fluid-tools/build-cli": "0.26.0-203096",
|
|
36
|
+
"@fluidframework/azure-service-utils-previous": "npm:@fluidframework/azure-service-utils@2.0.0-internal.7.1.0",
|
|
37
|
+
"@fluidframework/build-common": "^2.0.2",
|
|
38
|
+
"@fluidframework/build-tools": "0.26.0-203096",
|
|
39
|
+
"@fluidframework/eslint-config-fluid": "^3.0.0",
|
|
40
|
+
"@microsoft/api-extractor": "^7.37.0",
|
|
29
41
|
"@types/jsrsasign": "^8.0.8",
|
|
30
|
-
"
|
|
31
|
-
"eslint": "~
|
|
32
|
-
"
|
|
33
|
-
"eslint-plugin-jsdoc": "~39.3.0",
|
|
34
|
-
"prettier": "~2.6.2",
|
|
42
|
+
"eslint": "~8.50.0",
|
|
43
|
+
"eslint-config-prettier": "~9.0.0",
|
|
44
|
+
"prettier": "~3.0.3",
|
|
35
45
|
"rimraf": "^4.4.0",
|
|
36
|
-
"typescript": "~
|
|
46
|
+
"typescript": "~5.1.6"
|
|
37
47
|
},
|
|
38
48
|
"typeValidation": {
|
|
39
49
|
"broken": {}
|
package/src/generateToken.ts
CHANGED
|
@@ -47,6 +47,8 @@ import type { ITokenClaims, IUser, ScopeType } from "@fluidframework/protocol-de
|
|
|
47
47
|
* Default: 3600 (1 hour).
|
|
48
48
|
* @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
|
|
49
49
|
* Default: `1.0`.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
50
52
|
*/
|
|
51
53
|
export function generateToken(
|
|
52
54
|
tenantId: string,
|
|
@@ -55,19 +57,20 @@ export function generateToken(
|
|
|
55
57
|
documentId?: string,
|
|
56
58
|
user?: IUser,
|
|
57
59
|
lifetime: number = 60 * 60,
|
|
60
|
+
// Naming intended to match `ITokenClaims.ver`
|
|
61
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
58
62
|
ver: string = "1.0",
|
|
59
63
|
): string {
|
|
60
|
-
let userClaim = user
|
|
64
|
+
let userClaim = user ?? generateUser();
|
|
61
65
|
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
62
66
|
userClaim = generateUser();
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
// Current time in seconds
|
|
66
70
|
const now = Math.round(Date.now() / 1000);
|
|
67
|
-
const docId = documentId ?? "";
|
|
68
71
|
|
|
69
72
|
const claims: ITokenClaims & { jti: string } = {
|
|
70
|
-
documentId:
|
|
73
|
+
documentId: documentId ?? "",
|
|
71
74
|
scopes,
|
|
72
75
|
tenantId,
|
|
73
76
|
user: userClaim,
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* A set of helper utilities for building backend APIs for use with
|
|
8
8
|
* {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
|
|
9
9
|
*
|
|
10
|
+
* @remarks
|
|
10
11
|
* Note that this library's primary entry-point ({@link generateToken}) is only intended
|
|
11
12
|
* to be run in a browser context.
|
|
12
13
|
* It is **not** Node.js-compatible.
|
|
@@ -14,5 +15,6 @@
|
|
|
14
15
|
* @packageDocumentation
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
|
-
export { IUser
|
|
18
|
+
export type { IUser } from "@fluidframework/protocol-definitions";
|
|
19
|
+
export { ScopeType } from "@fluidframework/protocol-definitions";
|
|
18
20
|
export { generateToken } from "./generateToken";
|