@fluidframework/azure-service-utils 0.52.1 → 0.54.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/dist/generateToken.d.ts +15 -0
- package/dist/generateToken.d.ts.map +1 -0
- package/dist/generateToken.js +47 -0
- package/dist/generateToken.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/generateToken.d.ts +15 -0
- package/lib/generateToken.d.ts.map +1 -0
- package/lib/generateToken.js +42 -0
- package/lib/generateToken.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +3 -2
- package/src/generateToken.ts +56 -0
- package/src/index.ts +1 -1
- package/src/packageVersion.ts +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
6
|
+
/**
|
|
7
|
+
* Generates a JWT token to authorize routerlicious. This function uses a browser friendly auth library (jsrsasign)
|
|
8
|
+
* and should only be used in client context.
|
|
9
|
+
* If a token ever needs to be generated on the client side, it should re-use this function. If it needs to be used on
|
|
10
|
+
* the service side, please use the copy available in the server-services-client package in order to avoid
|
|
11
|
+
* interdependencies between service and client packages
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
|
|
14
|
+
export declare function generateUser(): IUser;
|
|
15
|
+
//# sourceMappingURL=generateToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateToken.d.ts","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAgB,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAItF;;;;;;GAMG;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,GAAG,MAAM,CAuB/B;AAED,wBAAgB,YAAY,IAAI,KAAK,CAOpC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.generateUser = exports.generateToken = void 0;
|
|
8
|
+
const jsrsasign_1 = require("jsrsasign");
|
|
9
|
+
const uuid_1 = require("uuid");
|
|
10
|
+
/**
|
|
11
|
+
* Generates a JWT token to authorize routerlicious. This function uses a browser friendly auth library (jsrsasign)
|
|
12
|
+
* and should only be used in client context.
|
|
13
|
+
* If a token ever needs to be generated on the client side, it should re-use this function. If it needs to be used on
|
|
14
|
+
* the service side, please use the copy available in the server-services-client package in order to avoid
|
|
15
|
+
* interdependencies between service and client packages
|
|
16
|
+
*/
|
|
17
|
+
function generateToken(tenantId, key, scopes, documentId, user, lifetime = 60 * 60, ver = "1.0") {
|
|
18
|
+
let userClaim = (user) ? user : generateUser();
|
|
19
|
+
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
20
|
+
userClaim = generateUser();
|
|
21
|
+
}
|
|
22
|
+
// Current time in seconds
|
|
23
|
+
const now = Math.round((new Date()).getTime() / 1000);
|
|
24
|
+
const claims = {
|
|
25
|
+
documentId,
|
|
26
|
+
scopes,
|
|
27
|
+
tenantId,
|
|
28
|
+
user: userClaim,
|
|
29
|
+
iat: now,
|
|
30
|
+
exp: now + lifetime,
|
|
31
|
+
ver,
|
|
32
|
+
jti: uuid_1.v4(),
|
|
33
|
+
};
|
|
34
|
+
const utf8Key = { utf8: key };
|
|
35
|
+
// eslint-disable-next-line no-null/no-null
|
|
36
|
+
return jsrsasign_1.KJUR.jws.JWS.sign(null, JSON.stringify({ alg: "HS256", typ: "JWT" }), claims, utf8Key);
|
|
37
|
+
}
|
|
38
|
+
exports.generateToken = generateToken;
|
|
39
|
+
function generateUser() {
|
|
40
|
+
const randomUser = {
|
|
41
|
+
id: uuid_1.v4(),
|
|
42
|
+
name: uuid_1.v4(),
|
|
43
|
+
};
|
|
44
|
+
return randomUser;
|
|
45
|
+
}
|
|
46
|
+
exports.generateUser = generateUser;
|
|
47
|
+
//# sourceMappingURL=generateToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,yCAA8C;AAC9C,+BAAkC;AAElC;;;;;;GAMG;AACH,SAAgB,aAAa,CACzB,QAAgB,EAChB,GAAW,EACX,MAAmB,EACnB,UAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE,EAC1B,MAAc,KAAK;IACnB,IAAI,SAAS,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;IAC/C,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,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAEtD,MAAM,MAAM,GAAmC;QAC3C,UAAU;QACV,MAAM;QACN,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,QAAQ;QACnB,GAAG;QACH,GAAG,EAAE,SAAI,EAAE;KACd,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAC9B,2CAA2C;IAC3C,OAAO,gBAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACtG,CAAC;AA9BD,sCA8BC;AAED,SAAgB,YAAY;IACxB,MAAM,UAAU,GAAG;QACf,EAAE,EAAE,SAAI,EAAE;QACV,IAAI,EAAE,SAAI,EAAE;KACf,CAAC;IAEF,OAAO,UAAU,CAAC;AACtB,CAAC;AAPD,oCAOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\n/**\n * Generates a JWT token to authorize routerlicious. This function uses a browser friendly auth library (jsrsasign)\n * and should only be used in client context.\n * If a token ever needs to be generated on the client side, it should re-use this function. If it needs to be used on\n * the service side, please use the copy available in the server-services-client package in order to avoid\n * interdependencies between service and client packages\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\"): 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((new Date()).getTime() / 1000);\n\n const claims: ITokenClaims & { jti: string } = {\n documentId,\n scopes,\n tenantId,\n user: userClaim,\n iat: now,\n exp: now + lifetime,\n ver,\n jti: uuid(),\n };\n\n const utf8Key = { utf8: key };\n // eslint-disable-next-line no-null/no-null\n return jsrsasign.jws.JWS.sign(null, JSON.stringify({ alg:\"HS256\", typ: \"JWT\" }), claims, utf8Key);\n}\n\nexport function generateUser(): IUser {\n const randomUser = {\n id: uuid(),\n name: uuid(),\n };\n\n return randomUser;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
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;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,6 @@ exports.generateToken = exports.ScopeType = void 0;
|
|
|
12
12
|
*/
|
|
13
13
|
var protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
14
14
|
Object.defineProperty(exports, "ScopeType", { enumerable: true, get: function () { return protocol_definitions_1.ScopeType; } });
|
|
15
|
-
var
|
|
16
|
-
Object.defineProperty(exports, "generateToken", { enumerable: true, get: function () { return
|
|
15
|
+
var generateToken_1 = require("./generateToken");
|
|
16
|
+
Object.defineProperty(exports, "generateToken", { enumerable: true, get: function () { return generateToken_1.generateToken; } });
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AAEH,6EAAiE;AAAxD,iHAAA,SAAS,OAAA;AAClB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;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 Azure Fluid Relay.\n *\n * @packageDocumentation\n */\n\nexport { 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 = "0.
|
|
8
|
+
export declare const pkgVersion = "0.54.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
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 = "0.
|
|
11
|
+
exports.pkgVersion = "0.54.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,QAAQ,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 = \"0.
|
|
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,QAAQ,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 = \"0.54.0\";\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
6
|
+
/**
|
|
7
|
+
* Generates a JWT token to authorize routerlicious. This function uses a browser friendly auth library (jsrsasign)
|
|
8
|
+
* and should only be used in client context.
|
|
9
|
+
* If a token ever needs to be generated on the client side, it should re-use this function. If it needs to be used on
|
|
10
|
+
* the service side, please use the copy available in the server-services-client package in order to avoid
|
|
11
|
+
* interdependencies between service and client packages
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
|
|
14
|
+
export declare function generateUser(): IUser;
|
|
15
|
+
//# sourceMappingURL=generateToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateToken.d.ts","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAgB,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAItF;;;;;;GAMG;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,GAAG,MAAM,CAuB/B;AAED,wBAAgB,YAAY,IAAI,KAAK,CAOpC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { KJUR as jsrsasign } from "jsrsasign";
|
|
6
|
+
import { v4 as uuid } from "uuid";
|
|
7
|
+
/**
|
|
8
|
+
* Generates a JWT token to authorize routerlicious. This function uses a browser friendly auth library (jsrsasign)
|
|
9
|
+
* and should only be used in client context.
|
|
10
|
+
* If a token ever needs to be generated on the client side, it should re-use this function. If it needs to be used on
|
|
11
|
+
* the service side, please use the copy available in the server-services-client package in order to avoid
|
|
12
|
+
* interdependencies between service and client packages
|
|
13
|
+
*/
|
|
14
|
+
export function generateToken(tenantId, key, scopes, documentId, user, lifetime = 60 * 60, ver = "1.0") {
|
|
15
|
+
let userClaim = (user) ? user : generateUser();
|
|
16
|
+
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
17
|
+
userClaim = generateUser();
|
|
18
|
+
}
|
|
19
|
+
// Current time in seconds
|
|
20
|
+
const now = Math.round((new Date()).getTime() / 1000);
|
|
21
|
+
const claims = {
|
|
22
|
+
documentId,
|
|
23
|
+
scopes,
|
|
24
|
+
tenantId,
|
|
25
|
+
user: userClaim,
|
|
26
|
+
iat: now,
|
|
27
|
+
exp: now + lifetime,
|
|
28
|
+
ver,
|
|
29
|
+
jti: uuid(),
|
|
30
|
+
};
|
|
31
|
+
const utf8Key = { utf8: key };
|
|
32
|
+
// eslint-disable-next-line no-null/no-null
|
|
33
|
+
return jsrsasign.jws.JWS.sign(null, JSON.stringify({ alg: "HS256", typ: "JWT" }), claims, utf8Key);
|
|
34
|
+
}
|
|
35
|
+
export function generateUser() {
|
|
36
|
+
const randomUser = {
|
|
37
|
+
id: uuid(),
|
|
38
|
+
name: uuid(),
|
|
39
|
+
};
|
|
40
|
+
return randomUser;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=generateToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CACzB,QAAgB,EAChB,GAAW,EACX,MAAmB,EACnB,UAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE,EAC1B,MAAc,KAAK;IACnB,IAAI,SAAS,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;IAC/C,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,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAEtD,MAAM,MAAM,GAAmC;QAC3C,UAAU;QACV,MAAM;QACN,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,QAAQ;QACnB,GAAG;QACH,GAAG,EAAE,IAAI,EAAE;KACd,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAC9B,2CAA2C;IAC3C,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACtG,CAAC;AAED,MAAM,UAAU,YAAY;IACxB,MAAM,UAAU,GAAG;QACf,EAAE,EAAE,IAAI,EAAE;QACV,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 */\n\nimport { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\n/**\n * Generates a JWT token to authorize routerlicious. This function uses a browser friendly auth library (jsrsasign)\n * and should only be used in client context.\n * If a token ever needs to be generated on the client side, it should re-use this function. If it needs to be used on\n * the service side, please use the copy available in the server-services-client package in order to avoid\n * interdependencies between service and client packages\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\"): 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((new Date()).getTime() / 1000);\n\n const claims: ITokenClaims & { jti: string } = {\n documentId,\n scopes,\n tenantId,\n user: userClaim,\n iat: now,\n exp: now + lifetime,\n ver,\n jti: uuid(),\n };\n\n const utf8Key = { utf8: key };\n // eslint-disable-next-line no-null/no-null\n return jsrsasign.jws.JWS.sign(null, JSON.stringify({ alg:\"HS256\", typ: \"JWT\" }), claims, utf8Key);\n}\n\nexport function generateUser(): IUser {\n const randomUser = {\n id: uuid(),\n name: uuid(),\n };\n\n return randomUser;\n}\n"]}
|
package/lib/index.d.ts
CHANGED
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;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;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 Azure Fluid Relay.\n *\n * @packageDocumentation\n */\n\nexport { 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 = "0.
|
|
8
|
+
export declare const pkgVersion = "0.54.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
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,QAAQ,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 = \"0.
|
|
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,QAAQ,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 = \"0.54.0\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/azure-service-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.0",
|
|
4
4
|
"description": "Helper service-side utilities for connecting to Azure Fluid Relay service",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": "https://github.com/microsoft/FluidFramework",
|
|
@@ -32,12 +32,13 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@fluidframework/protocol-definitions": "^0.1026.0",
|
|
35
|
-
"
|
|
35
|
+
"jsrsasign": "^10.2.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@fluidframework/build-common": "^0.23.0",
|
|
39
39
|
"@fluidframework/eslint-config-fluid": "^0.24.0",
|
|
40
40
|
"@microsoft/api-extractor": "^7.16.1",
|
|
41
|
+
"@types/jsrsasign": "^8.0.8",
|
|
41
42
|
"@typescript-eslint/eslint-plugin": "~4.14.0",
|
|
42
43
|
"@typescript-eslint/parser": "~4.14.0",
|
|
43
44
|
"concurrently": "^6.2.0",
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ITokenClaims, IUser, ScopeType } from "@fluidframework/protocol-definitions";
|
|
7
|
+
import { KJUR as jsrsasign } from "jsrsasign";
|
|
8
|
+
import { v4 as uuid } from "uuid";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generates a JWT token to authorize routerlicious. This function uses a browser friendly auth library (jsrsasign)
|
|
12
|
+
* and should only be used in client context.
|
|
13
|
+
* If a token ever needs to be generated on the client side, it should re-use this function. If it needs to be used on
|
|
14
|
+
* the service side, please use the copy available in the server-services-client package in order to avoid
|
|
15
|
+
* interdependencies between service and client packages
|
|
16
|
+
*/
|
|
17
|
+
export function generateToken(
|
|
18
|
+
tenantId: string,
|
|
19
|
+
key: string,
|
|
20
|
+
scopes: ScopeType[],
|
|
21
|
+
documentId?: string,
|
|
22
|
+
user?: IUser,
|
|
23
|
+
lifetime: number = 60 * 60,
|
|
24
|
+
ver: string = "1.0"): string {
|
|
25
|
+
let userClaim = (user) ? user : generateUser();
|
|
26
|
+
if (userClaim.id === "" || userClaim.id === undefined) {
|
|
27
|
+
userClaim = generateUser();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Current time in seconds
|
|
31
|
+
const now = Math.round((new Date()).getTime() / 1000);
|
|
32
|
+
|
|
33
|
+
const claims: ITokenClaims & { jti: string } = {
|
|
34
|
+
documentId,
|
|
35
|
+
scopes,
|
|
36
|
+
tenantId,
|
|
37
|
+
user: userClaim,
|
|
38
|
+
iat: now,
|
|
39
|
+
exp: now + lifetime,
|
|
40
|
+
ver,
|
|
41
|
+
jti: uuid(),
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const utf8Key = { utf8: key };
|
|
45
|
+
// eslint-disable-next-line no-null/no-null
|
|
46
|
+
return jsrsasign.jws.JWS.sign(null, JSON.stringify({ alg:"HS256", typ: "JWT" }), claims, utf8Key);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function generateUser(): IUser {
|
|
50
|
+
const randomUser = {
|
|
51
|
+
id: uuid(),
|
|
52
|
+
name: uuid(),
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return randomUser;
|
|
56
|
+
}
|
package/src/index.ts
CHANGED
package/src/packageVersion.ts
CHANGED