@microsoft/teamsfx 0.3.2-rc.0 → 0.3.3-alpha.13914d2e.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.
Files changed (68) hide show
  1. package/README.md +2 -2
  2. package/dist/index.esm2017.js +1413 -0
  3. package/dist/index.esm2017.js.map +1 -0
  4. package/dist/{index.js → index.esm2017.mjs} +1467 -1506
  5. package/dist/index.esm2017.mjs.map +1 -0
  6. package/dist/index.esm5.js +1575 -0
  7. package/dist/index.esm5.js.map +1 -0
  8. package/dist/index.node.cjs.js +1653 -0
  9. package/dist/index.node.cjs.js.map +1 -0
  10. package/package.json +73 -90
  11. package/types/teamsfx.d.ts +0 -2
  12. package/dist/index.js.map +0 -1
  13. package/dist/teamsfx.js +0 -30
  14. package/dist/teamsfx.js.map +0 -1
  15. package/dist-esm/src/bot/teamsBotSsoPrompt.browser.js +0 -118
  16. package/dist-esm/src/bot/teamsBotSsoPrompt.browser.js.map +0 -1
  17. package/dist-esm/src/bot/teamsBotSsoPrompt.js +0 -349
  18. package/dist-esm/src/bot/teamsBotSsoPrompt.js.map +0 -1
  19. package/dist-esm/src/bot/teamsBotSsoPromptTokenResponse.js +0 -2
  20. package/dist-esm/src/bot/teamsBotSsoPromptTokenResponse.js.map +0 -1
  21. package/dist-esm/src/core/cache.browser.js +0 -22
  22. package/dist-esm/src/core/cache.browser.js.map +0 -1
  23. package/dist-esm/src/core/cache.js +0 -28
  24. package/dist-esm/src/core/cache.js.map +0 -1
  25. package/dist-esm/src/core/configurationProvider.js +0 -124
  26. package/dist-esm/src/core/configurationProvider.js.map +0 -1
  27. package/dist-esm/src/core/defaultTediousConnectionConfiguration.browser.js +0 -28
  28. package/dist-esm/src/core/defaultTediousConnectionConfiguration.browser.js.map +0 -1
  29. package/dist-esm/src/core/defaultTediousConnectionConfiguration.js +0 -182
  30. package/dist-esm/src/core/defaultTediousConnectionConfiguration.js.map +0 -1
  31. package/dist-esm/src/core/errors.js +0 -97
  32. package/dist-esm/src/core/errors.js.map +0 -1
  33. package/dist-esm/src/core/msGraphAuthProvider.js +0 -68
  34. package/dist-esm/src/core/msGraphAuthProvider.js.map +0 -1
  35. package/dist-esm/src/core/msGraphClientProvider.js +0 -65
  36. package/dist-esm/src/core/msGraphClientProvider.js.map +0 -1
  37. package/dist-esm/src/credential/m365TenantCredential.browser.js +0 -38
  38. package/dist-esm/src/credential/m365TenantCredential.browser.js.map +0 -1
  39. package/dist-esm/src/credential/m365TenantCredential.js +0 -126
  40. package/dist-esm/src/credential/m365TenantCredential.js.map +0 -1
  41. package/dist-esm/src/credential/onBehalfOfUserCredential.browser.js +0 -46
  42. package/dist-esm/src/credential/onBehalfOfUserCredential.browser.js.map +0 -1
  43. package/dist-esm/src/credential/onBehalfOfUserCredential.js +0 -178
  44. package/dist-esm/src/credential/onBehalfOfUserCredential.js.map +0 -1
  45. package/dist-esm/src/credential/teamsUserCredential.browser.js +0 -462
  46. package/dist-esm/src/credential/teamsUserCredential.browser.js.map +0 -1
  47. package/dist-esm/src/credential/teamsUserCredential.js +0 -56
  48. package/dist-esm/src/credential/teamsUserCredential.js.map +0 -1
  49. package/dist-esm/src/index.js +0 -14
  50. package/dist-esm/src/index.js.map +0 -1
  51. package/dist-esm/src/models/accessTokenResult.js +0 -4
  52. package/dist-esm/src/models/accessTokenResult.js.map +0 -1
  53. package/dist-esm/src/models/authCodeResult.js +0 -4
  54. package/dist-esm/src/models/authCodeResult.js.map +0 -1
  55. package/dist-esm/src/models/configuration.js +0 -20
  56. package/dist-esm/src/models/configuration.js.map +0 -1
  57. package/dist-esm/src/models/grantType.js +0 -11
  58. package/dist-esm/src/models/grantType.js.map +0 -1
  59. package/dist-esm/src/models/ssoTokenInfo.js +0 -4
  60. package/dist-esm/src/models/ssoTokenInfo.js.map +0 -1
  61. package/dist-esm/src/models/userinfo.js +0 -4
  62. package/dist-esm/src/models/userinfo.js.map +0 -1
  63. package/dist-esm/src/util/logger.js +0 -134
  64. package/dist-esm/src/util/logger.js.map +0 -1
  65. package/dist-esm/src/util/utils.js +0 -130
  66. package/dist-esm/src/util/utils.js.map +0 -1
  67. package/dist-esm/src/util/utils.node.js +0 -23
  68. package/dist-esm/src/util/utils.node.js.map +0 -1
@@ -1,20 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- /**
4
- * Available resource type.
5
- * @beta
6
- */
7
- export var ResourceType;
8
- (function (ResourceType) {
9
- /**
10
- * SQL database.
11
- *
12
- */
13
- ResourceType[ResourceType["SQL"] = 0] = "SQL";
14
- /**
15
- * Rest API.
16
- *
17
- */
18
- ResourceType[ResourceType["API"] = 1] = "API";
19
- })(ResourceType || (ResourceType = {}));
20
- //# sourceMappingURL=configuration.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../../src/models/configuration.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AA6GlC;;;GAGG;AACH,MAAM,CAAN,IAAY,YAYX;AAZD,WAAY,YAAY;IACtB;;;OAGG;IACH,6CAAG,CAAA;IAEH;;;OAGG;IACH,6CAAG,CAAA;AACL,CAAC,EAZW,YAAY,KAAZ,YAAY,QAYvB","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Configuration for current environment.\n * @beta\n */\nexport interface Configuration {\n /**\n * Authentication related configuration.\n *\n * @readonly\n */\n readonly authentication?: AuthenticationConfiguration;\n\n /**\n * Configuration for resources.\n *\n * @readonly\n */\n readonly resources?: ResourceConfiguration[];\n}\n\n/**\n * Authentication related configuration.\n * @beta\n */\nexport interface AuthenticationConfiguration {\n /**\n * Hostname of AAD authority. Default value comes from M365_AUTHORITY_HOST environment variable.\n *\n * @readonly\n */\n readonly authorityHost?: string;\n\n /**\n * AAD tenant id, default value comes from M365_TENANT_ID environment variable.\n *\n * @readonly\n */\n readonly tenantId?: string;\n\n /**\n * The client (application) ID of an App Registration in the tenant, default value comes from M365_CLIENT_ID environment variable\n *\n * @readonly\n */\n readonly clientId?: string;\n\n /**\n * Secret string that the application uses when requesting a token. Only used in confidential client applications. Can be created in the Azure app registration portal. Default value comes from M365_CLIENT_SECRET environment variable\n *\n * @readonly\n */\n readonly clientSecret?: string;\n\n /**\n * The content of a PEM-encoded public/private key certificate.\n *\n * @readonly\n */\n readonly certificateContent?: string;\n\n /**\n * Endpoint of auth service provisioned by Teams Framework. Default value comes from SIMPLE_AUTH_ENDPOINT environment variable.\n *\n * @readonly\n */\n readonly simpleAuthEndpoint?: string;\n\n /**\n * Login page for Teams to redirect to. Default value comes from INITIATE_LOGIN_ENDPOINT environment variable.\n *\n * @readonly\n */\n readonly initiateLoginEndpoint?: string;\n\n /**\n * Application ID URI. Default value comes from M365_APPLICATION_ID_URI environment variable.\n */\n readonly applicationIdUri?: string;\n}\n\n/**\n * Configuration for resources.\n * @beta\n */\nexport interface ResourceConfiguration {\n /**\n * Resource type.\n *\n * @readonly\n */\n readonly type: ResourceType;\n\n /**\n * Resource name.\n *\n * @readonly\n */\n readonly name: string;\n\n /**\n * Config for the resource.\n *\n * @readonly\n */\n readonly properties: { [index: string]: any };\n}\n\n/**\n * Available resource type.\n * @beta\n */\nexport enum ResourceType {\n /**\n * SQL database.\n *\n */\n SQL,\n\n /**\n * Rest API.\n *\n */\n API,\n}\n"]}
@@ -1,11 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- /**
4
- * @internal
5
- */
6
- export var GrantType;
7
- (function (GrantType) {
8
- GrantType["authCode"] = "authorization_code";
9
- GrantType["ssoToken"] = "sso_token";
10
- })(GrantType || (GrantType = {}));
11
- //# sourceMappingURL=grantType.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"grantType.js","sourceRoot":"","sources":["../../../src/models/grantType.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AACH,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,4CAA+B,CAAA;IAC/B,mCAAsB,CAAA;AACxB,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * @internal\n */\nexport enum GrantType {\n authCode = \"authorization_code\",\n ssoToken = \"sso_token\",\n}\n"]}
@@ -1,4 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- export {};
4
- //# sourceMappingURL=ssoTokenInfo.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ssoTokenInfo.js","sourceRoot":"","sources":["../../../src/models/ssoTokenInfo.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Base class for SSO token payload\n * Payload claims can be found here: https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens\n *\n * @internal\n */\nexport interface SSOTokenInfoBase {\n aud: string;\n iss: string;\n iat: number;\n nbf: number;\n exp: number;\n aio: string;\n name: string;\n oid: string;\n rh: string;\n scp: string;\n sub: string;\n tid: string;\n uti: string;\n ver: string;\n}\n\n/**\n * SSO token v1\n *\n * @internal\n */\nexport interface SSOTokenV2Info extends SSOTokenInfoBase {\n azp: string;\n azpacr: string;\n preferred_username: string;\n}\n\n/**\n * SSO token v2\n *\n * @internal\n */\nexport interface SSOTokenV1Info extends SSOTokenInfoBase {\n acr: string;\n amr: string[];\n appid: string;\n appidacr: string;\n family_name: string;\n given_name: string;\n ipaddr: string;\n onprem_sid: string;\n unique_name: string;\n upn: string;\n}\n"]}
@@ -1,4 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- export {};
4
- //# sourceMappingURL=userinfo.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"userinfo.js","sourceRoot":"","sources":["../../../src/models/userinfo.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * UserInfo with user displayName, objectId and preferredUserName.\n *\n * @beta\n */\nexport interface UserInfo {\n /**\n * User Display Name.\n *\n * @readonly\n */\n displayName: string;\n\n /**\n * User unique reference within the Azure Active Directory domain.\n *\n * @readonly\n */\n objectId: string;\n\n /**\n * Usually be the email address.\n *\n * @readonly\n */\n preferredUserName: string;\n}\n"]}
@@ -1,134 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- /**
4
- * Log level.
5
- *
6
- * @beta
7
- */
8
- export var LogLevel;
9
- (function (LogLevel) {
10
- /**
11
- * Show verbose, information, warning and error message.
12
- */
13
- LogLevel[LogLevel["Verbose"] = 0] = "Verbose";
14
- /**
15
- * Show information, warning and error message.
16
- */
17
- LogLevel[LogLevel["Info"] = 1] = "Info";
18
- /**
19
- * Show warning and error message.
20
- */
21
- LogLevel[LogLevel["Warn"] = 2] = "Warn";
22
- /**
23
- * Show error message.
24
- */
25
- LogLevel[LogLevel["Error"] = 3] = "Error";
26
- })(LogLevel || (LogLevel = {}));
27
- /**
28
- * Update log level helper.
29
- *
30
- * @param { LogLevel } level - log level in configuration
31
- *
32
- * @beta
33
- */
34
- export function setLogLevel(level) {
35
- internalLogger.level = level;
36
- }
37
- /**
38
- * Get log level.
39
- *
40
- * @returns Log level
41
- *
42
- * @beta
43
- */
44
- export function getLogLevel() {
45
- return internalLogger.level;
46
- }
47
- class InternalLogger {
48
- constructor() {
49
- this.level = undefined;
50
- this.defaultLogger = {
51
- verbose: console.debug,
52
- info: console.info,
53
- warn: console.warn,
54
- error: console.error,
55
- };
56
- }
57
- error(message) {
58
- this.log(LogLevel.Error, (x) => x.error, message);
59
- }
60
- warn(message) {
61
- this.log(LogLevel.Warn, (x) => x.warn, message);
62
- }
63
- info(message) {
64
- this.log(LogLevel.Info, (x) => x.info, message);
65
- }
66
- verbose(message) {
67
- this.log(LogLevel.Verbose, (x) => x.verbose, message);
68
- }
69
- log(logLevel, logFunction, message) {
70
- if (message.trim() === "") {
71
- return;
72
- }
73
- const timestamp = new Date().toUTCString();
74
- const logHeader = `[${timestamp}] : @microsoft/teamsfx : ${LogLevel[logLevel]} - `;
75
- const logMessage = `${logHeader}${message}`;
76
- if (this.level !== undefined && this.level <= logLevel) {
77
- if (this.customLogger) {
78
- logFunction(this.customLogger)(logMessage);
79
- }
80
- else if (this.customLogFunction) {
81
- this.customLogFunction(logLevel, logMessage);
82
- }
83
- else {
84
- logFunction(this.defaultLogger)(logMessage);
85
- }
86
- }
87
- }
88
- }
89
- /**
90
- * Logger instance used internally
91
- *
92
- * @internal
93
- */
94
- export const internalLogger = new InternalLogger();
95
- /**
96
- * Set custom logger. Use the output functions if it's set. Priority is higher than setLogFunction.
97
- *
98
- * @param {Logger} logger - custom logger. If it's undefined, custom logger will be cleared.
99
- *
100
- * @example
101
- * ```typescript
102
- * setLogger({
103
- * verbose: console.debug,
104
- * info: console.info,
105
- * warn: console.warn,
106
- * error: console.error,
107
- * });
108
- * ```
109
- *
110
- * @beta
111
- */
112
- export function setLogger(logger) {
113
- internalLogger.customLogger = logger;
114
- }
115
- /**
116
- * Set custom log function. Use the function if it's set. Priority is lower than setLogger.
117
- *
118
- * @param {LogFunction} logFunction - custom log function. If it's undefined, custom log function will be cleared.
119
- *
120
- * @example
121
- * ```typescript
122
- * setLogFunction((level: LogLevel, message: string) => {
123
- * if (level === LogLevel.Error) {
124
- * console.log(message);
125
- * }
126
- * });
127
- * ```
128
- *
129
- * @beta
130
- */
131
- export function setLogFunction(logFunction) {
132
- internalLogger.customLogFunction = logFunction;
133
- }
134
- //# sourceMappingURL=logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/util/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAgClC;;;;GAIG;AACH,MAAM,CAAN,IAAY,QAiBX;AAjBD,WAA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C,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;IAEO,GAAG,CACT,QAAkB,EAClB,WAAqD,EACrD,OAAe;QAEf,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YACzB,OAAO;SACR;QACD,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAI,SAAS,4BAA4B,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;QACnF,MAAM,UAAU,GAAG,GAAG,SAAS,GAAG,OAAO,EAAE,CAAC;QAC5C,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,IAAI,QAAQ,EAAE;YACtD,IAAI,IAAI,CAAC,YAAY,EAAE;gBACrB,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,UAAU,CAAC,CAAC;aAC5C;iBAAM,IAAI,IAAI,CAAC,iBAAiB,EAAE;gBACjC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;aAC9C;iBAAM;gBACL,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,UAAU,CAAC,CAAC;aAC7C;SACF;IACH,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAmB,IAAI,cAAc,EAAE,CAAC;AAEnE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,SAAS,CAAC,MAAe;IACvC,cAAc,CAAC,YAAY,GAAG,MAAM,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAAC,WAAyB;IACtD,cAAc,CAAC,iBAAiB,GAAG,WAAW,CAAC;AACjD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Interface for customized logger.\n * @beta\n */\nexport interface Logger {\n /**\n * Writes to error level logging or lower.\n */\n error(message: string): void;\n /**\n * Writes to warning level logging or lower.\n */\n warn(message: string): void;\n /**\n * Writes to info level logging or lower.\n */\n info(message: string): void;\n /**\n * Writes to verbose level logging.\n */\n verbose(message: string): void;\n}\n\n/**\n * Log function for customized logging.\n *\n * @beta\n */\nexport type LogFunction = (level: LogLevel, message: string) => void;\n\n/**\n * Log level.\n *\n * @beta\n */\nexport enum LogLevel {\n /**\n * Show verbose, information, warning and error message.\n */\n Verbose,\n /**\n * Show information, warning and error message.\n */\n Info,\n /**\n * Show warning and error message.\n */\n Warn,\n /**\n * Show error message.\n */\n Error,\n}\n\n/**\n * Update log level helper.\n *\n * @param { LogLevel } level - log level in configuration\n *\n * @beta\n */\nexport function setLogLevel(level: LogLevel): void {\n internalLogger.level = level;\n}\n\n/**\n * Get log level.\n *\n * @returns Log level\n *\n * @beta\n */\nexport function getLogLevel(): LogLevel | undefined {\n return internalLogger.level;\n}\n\nclass InternalLogger {\n public level?: LogLevel = undefined;\n\n public customLogger: Logger | undefined;\n public customLogFunction: LogFunction | undefined;\n private defaultLogger: Logger = {\n verbose: console.debug,\n info: console.info,\n warn: console.warn,\n error: console.error,\n };\n\n public error(message: string): void {\n this.log(LogLevel.Error, (x: Logger) => x.error, message);\n }\n\n public warn(message: string): void {\n this.log(LogLevel.Warn, (x: Logger) => x.warn, message);\n }\n\n public info(message: string): void {\n this.log(LogLevel.Info, (x: Logger) => x.info, message);\n }\n\n public verbose(message: string): void {\n this.log(LogLevel.Verbose, (x: Logger) => x.verbose, message);\n }\n\n private log(\n logLevel: LogLevel,\n logFunction: (x: Logger) => (message: string) => void,\n message: string\n ): void {\n if (message.trim() === \"\") {\n return;\n }\n const timestamp = new Date().toUTCString();\n const logHeader = `[${timestamp}] : @microsoft/teamsfx : ${LogLevel[logLevel]} - `;\n const logMessage = `${logHeader}${message}`;\n if (this.level !== undefined && this.level <= logLevel) {\n if (this.customLogger) {\n logFunction(this.customLogger)(logMessage);\n } else if (this.customLogFunction) {\n this.customLogFunction(logLevel, logMessage);\n } else {\n logFunction(this.defaultLogger)(logMessage);\n }\n }\n }\n}\n\n/**\n * Logger instance used internally\n *\n * @internal\n */\nexport const internalLogger: InternalLogger = new InternalLogger();\n\n/**\n * Set custom logger. Use the output functions if it's set. Priority is higher than setLogFunction.\n *\n * @param {Logger} logger - custom logger. If it's undefined, custom logger will be cleared.\n *\n * @example\n * ```typescript\n * setLogger({\n * verbose: console.debug,\n * info: console.info,\n * warn: console.warn,\n * error: console.error,\n * });\n * ```\n *\n * @beta\n */\nexport function setLogger(logger?: Logger): void {\n internalLogger.customLogger = logger;\n}\n\n/**\n * Set custom log function. Use the function if it's set. Priority is lower than setLogger.\n *\n * @param {LogFunction} logFunction - custom log function. If it's undefined, custom log function will be cleared.\n *\n * @example\n * ```typescript\n * setLogFunction((level: LogLevel, message: string) => {\n * if (level === LogLevel.Error) {\n * console.log(message);\n * }\n * });\n * ```\n *\n * @beta\n */\nexport function setLogFunction(logFunction?: LogFunction): void {\n internalLogger.customLogFunction = logFunction;\n}\n"]}
@@ -1,130 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- import { ErrorWithCode, ErrorCode } from "../core/errors";
4
- import jwt_decode from "jwt-decode";
5
- import { internalLogger } from "./logger";
6
- import { createHash } from "crypto";
7
- /**
8
- * Parse jwt token payload
9
- *
10
- * @param token
11
- *
12
- * @returns Payload object
13
- *
14
- * @internal
15
- */
16
- export function parseJwt(token) {
17
- try {
18
- const tokenObj = jwt_decode(token);
19
- if (!tokenObj || !tokenObj.exp) {
20
- throw new ErrorWithCode("Decoded token is null or exp claim does not exists.", ErrorCode.InternalError);
21
- }
22
- return tokenObj;
23
- }
24
- catch (err) {
25
- const errorMsg = "Parse jwt token failed in node env with error: " + err.message;
26
- internalLogger.error(errorMsg);
27
- throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);
28
- }
29
- }
30
- /**
31
- * @internal
32
- */
33
- export function getUserInfoFromSsoToken(ssoToken) {
34
- if (!ssoToken) {
35
- const errorMsg = "SSO token is undefined.";
36
- internalLogger.error(errorMsg);
37
- throw new ErrorWithCode(errorMsg, ErrorCode.InvalidParameter);
38
- }
39
- const tokenObject = parseJwt(ssoToken);
40
- const userInfo = {
41
- displayName: tokenObject.name,
42
- objectId: tokenObject.oid,
43
- preferredUserName: "",
44
- };
45
- if (tokenObject.ver === "2.0") {
46
- userInfo.preferredUserName = tokenObject.preferred_username;
47
- }
48
- else if (tokenObject.ver === "1.0") {
49
- userInfo.preferredUserName = tokenObject.upn;
50
- }
51
- return userInfo;
52
- }
53
- /**
54
- * Format string template with replacements
55
- *
56
- * ```typescript
57
- * const template = "{0} and {1} are fruit. {0} is my favorite one."
58
- * const formattedStr = formatString(template, "apple", "pear"); // formattedStr: "apple and pear are fruit. apple is my favorite one."
59
- * ```
60
- *
61
- * @param str string template
62
- * @param replacements replacement string array
63
- * @returns Formatted string
64
- *
65
- * @internal
66
- */
67
- export function formatString(str, ...replacements) {
68
- const args = replacements;
69
- return str.replace(/{(\d+)}/g, function (match, number) {
70
- return typeof args[number] != "undefined" ? args[number] : match;
71
- });
72
- }
73
- /**
74
- * @internal
75
- */
76
- export function validateScopesType(value) {
77
- // string
78
- if (typeof value === "string" || value instanceof String) {
79
- return;
80
- }
81
- // empty array
82
- if (Array.isArray(value) && value.length === 0) {
83
- return;
84
- }
85
- // string array
86
- if (Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === "string")) {
87
- return;
88
- }
89
- const errorMsg = "The type of scopes is not valid, it must be string or string array";
90
- internalLogger.error(errorMsg);
91
- throw new ErrorWithCode(errorMsg, ErrorCode.InvalidParameter);
92
- }
93
- /**
94
- * @internal
95
- */
96
- export function getScopesArray(scopes) {
97
- const scopesArray = typeof scopes === "string" ? scopes.split(" ") : scopes;
98
- return scopesArray.filter((x) => x !== null && x !== "");
99
- }
100
- /**
101
- * @internal
102
- */
103
- export function getAuthority(authorityHost, tenantId) {
104
- const normalizedAuthorityHost = authorityHost.replace(/\/+$/g, "");
105
- return normalizedAuthorityHost + "/" + tenantId;
106
- }
107
- /**
108
- * @internal
109
- */
110
- export function parseCertificate(certificateContent) {
111
- if (!certificateContent) {
112
- return undefined;
113
- }
114
- const certificatePattern = /(-+BEGIN CERTIFICATE-+)(\n\r?|\r\n?)([A-Za-z0-9+/\n\r]+=*)(\n\r?|\r\n?)(-+END CERTIFICATE-+)/;
115
- const match = certificatePattern.exec(certificateContent);
116
- if (!match) {
117
- const errorMsg = "The certificate content does not contain a PEM-encoded certificate.";
118
- internalLogger.error(errorMsg);
119
- throw new ErrorWithCode(errorMsg, ErrorCode.InvalidCertificate);
120
- }
121
- const thumbprint = createHash("sha1")
122
- .update(Buffer.from(match[3], "base64"))
123
- .digest("hex")
124
- .toUpperCase();
125
- return {
126
- thumbprint: thumbprint,
127
- privateKey: certificateContent,
128
- };
129
- }
130
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/util/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG1D,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,IAAI;QACF,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAqB,CAAC;QACvD,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;YAC9B,MAAM,IAAI,aAAa,CACrB,qDAAqD,EACrD,SAAS,CAAC,aAAa,CACxB,CAAC;SACH;QAED,OAAO,QAAQ,CAAC;KACjB;IAAC,OAAO,GAAQ,EAAE;QACjB,MAAM,QAAQ,GAAG,iDAAiD,GAAG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,IAAI,CAAC,kBAAkB,EAAE;QACvB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,kBAAkB,GACtB,8FAA8F,CAAC;IACjG,MAAM,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC1D,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,QAAQ,GAAG,qEAAqE,CAAC;QACvF,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC/B,MAAM,IAAI,aAAa,CAAC,QAAQ,EAAE,SAAS,CAAC,kBAAkB,CAAC,CAAC;KACjE;IACD,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC;SAClC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SACvC,MAAM,CAAC,KAAK,CAAC;SACb,WAAW,EAAE,CAAC;IAEjB,OAAO;QACL,UAAU,EAAE,UAAU;QACtB,UAAU,EAAE,kBAAkB;KAC/B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { ErrorWithCode, ErrorCode } from \"../core/errors\";\nimport { SSOTokenInfoBase, SSOTokenV1Info, SSOTokenV2Info } from \"../models/ssoTokenInfo\";\nimport { UserInfo } from \"../models/userinfo\";\nimport jwt_decode from \"jwt-decode\";\nimport { internalLogger } from \"./logger\";\nimport { createHash } from \"crypto\";\n\n/**\n * Parse jwt token payload\n *\n * @param token\n *\n * @returns Payload object\n *\n * @internal\n */\nexport function parseJwt(token: string): SSOTokenInfoBase {\n try {\n const tokenObj = jwt_decode(token) as SSOTokenInfoBase;\n if (!tokenObj || !tokenObj.exp) {\n throw new ErrorWithCode(\n \"Decoded token is null or exp claim does not exists.\",\n ErrorCode.InternalError\n );\n }\n\n return tokenObj;\n } catch (err: any) {\n const errorMsg = \"Parse jwt token failed in node env with error: \" + err.message;\n internalLogger.error(errorMsg);\n throw new ErrorWithCode(errorMsg, ErrorCode.InternalError);\n }\n}\n\n/**\n * @internal\n */\nexport function getUserInfoFromSsoToken(ssoToken: string): UserInfo {\n if (!ssoToken) {\n const errorMsg = \"SSO token is undefined.\";\n internalLogger.error(errorMsg);\n throw new ErrorWithCode(errorMsg, ErrorCode.InvalidParameter);\n }\n const tokenObject = parseJwt(ssoToken) as SSOTokenV1Info | SSOTokenV2Info;\n\n const userInfo: UserInfo = {\n displayName: tokenObject.name,\n objectId: tokenObject.oid,\n preferredUserName: \"\",\n };\n\n if (tokenObject.ver === \"2.0\") {\n userInfo.preferredUserName = (tokenObject as SSOTokenV2Info).preferred_username;\n } else if (tokenObject.ver === \"1.0\") {\n userInfo.preferredUserName = (tokenObject as SSOTokenV1Info).upn;\n }\n return userInfo;\n}\n\n/**\n * Format string template with replacements\n *\n * ```typescript\n * const template = \"{0} and {1} are fruit. {0} is my favorite one.\"\n * const formattedStr = formatString(template, \"apple\", \"pear\"); // formattedStr: \"apple and pear are fruit. apple is my favorite one.\"\n * ```\n *\n * @param str string template\n * @param replacements replacement string array\n * @returns Formatted string\n *\n * @internal\n */\nexport function formatString(str: string, ...replacements: string[]): string {\n const args = replacements;\n return str.replace(/{(\\d+)}/g, function (match, number) {\n return typeof args[number] != \"undefined\" ? args[number] : match;\n });\n}\n\n/**\n * @internal\n */\nexport function validateScopesType(value: any): void {\n // string\n if (typeof value === \"string\" || value instanceof String) {\n return;\n }\n\n // empty array\n if (Array.isArray(value) && value.length === 0) {\n return;\n }\n\n // string array\n if (Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === \"string\")) {\n return;\n }\n\n const errorMsg = \"The type of scopes is not valid, it must be string or string array\";\n internalLogger.error(errorMsg);\n throw new ErrorWithCode(errorMsg, ErrorCode.InvalidParameter);\n}\n\n/**\n * @internal\n */\nexport function getScopesArray(scopes: string | string[]): string[] {\n const scopesArray: string[] = typeof scopes === \"string\" ? scopes.split(\" \") : scopes;\n return scopesArray.filter((x) => x !== null && x !== \"\");\n}\n\n/**\n * @internal\n */\nexport function getAuthority(authorityHost: string, tenantId: string): string {\n const normalizedAuthorityHost = authorityHost.replace(/\\/+$/g, \"\");\n return normalizedAuthorityHost + \"/\" + tenantId;\n}\n\n/**\n * @internal\n */\nexport function parseCertificate(\n certificateContent: string | undefined\n): ClientCertificate | undefined {\n if (!certificateContent) {\n return undefined;\n }\n\n const certificatePattern =\n /(-+BEGIN CERTIFICATE-+)(\\n\\r?|\\r\\n?)([A-Za-z0-9+/\\n\\r]+=*)(\\n\\r?|\\r\\n?)(-+END CERTIFICATE-+)/;\n const match = certificatePattern.exec(certificateContent);\n if (!match) {\n const errorMsg = \"The certificate content does not contain a PEM-encoded certificate.\";\n internalLogger.error(errorMsg);\n throw new ErrorWithCode(errorMsg, ErrorCode.InvalidCertificate);\n }\n const thumbprint = createHash(\"sha1\")\n .update(Buffer.from(match[3], \"base64\"))\n .digest(\"hex\")\n .toUpperCase();\n\n return {\n thumbprint: thumbprint,\n privateKey: certificateContent,\n };\n}\n\n/**\n * @internal\n */\nexport interface ClientCertificate {\n thumbprint: string;\n privateKey: string;\n}\n"]}
@@ -1,23 +0,0 @@
1
- import { ConfidentialClientApplication } from "@azure/msal-node";
2
- import { getAuthority, parseCertificate } from "./utils";
3
- /**
4
- * @internal
5
- */
6
- export function createConfidentialClientApplication(authentication) {
7
- const authority = getAuthority(authentication.authorityHost, authentication.tenantId);
8
- const clientCertificate = parseCertificate(authentication.certificateContent);
9
- const auth = {
10
- clientId: authentication.clientId,
11
- authority: authority,
12
- };
13
- if (clientCertificate) {
14
- auth.clientCertificate = clientCertificate;
15
- }
16
- else {
17
- auth.clientSecret = authentication.clientSecret;
18
- }
19
- return new ConfidentialClientApplication({
20
- auth,
21
- });
22
- }
23
- //# sourceMappingURL=utils.node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.node.js","sourceRoot":"","sources":["../../../src/util/utils.node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAmB,MAAM,kBAAkB,CAAC;AAElF,OAAO,EAAqB,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE5E;;GAEG;AACH,MAAM,UAAU,mCAAmC,CACjD,cAA2C;IAE3C,MAAM,SAAS,GAAG,YAAY,CAAC,cAAc,CAAC,aAAc,EAAE,cAAc,CAAC,QAAS,CAAC,CAAC;IACxF,MAAM,iBAAiB,GAAkC,gBAAgB,CACvE,cAAc,CAAC,kBAAkB,CAClC,CAAC;IAEF,MAAM,IAAI,GAAoB;QAC5B,QAAQ,EAAE,cAAc,CAAC,QAAS;QAClC,SAAS,EAAE,SAAS;KACrB,CAAC;IAEF,IAAI,iBAAiB,EAAE;QACrB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;KAC5C;SAAM;QACL,IAAI,CAAC,YAAY,GAAG,cAAc,CAAC,YAAY,CAAC;KACjD;IAED,OAAO,IAAI,6BAA6B,CAAC;QACvC,IAAI;KACL,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { ConfidentialClientApplication, NodeAuthOptions } from \"@azure/msal-node\";\nimport { AuthenticationConfiguration } from \"../models/configuration\";\nimport { ClientCertificate, getAuthority, parseCertificate } from \"./utils\";\n\n/**\n * @internal\n */\nexport function createConfidentialClientApplication(\n authentication: AuthenticationConfiguration\n): ConfidentialClientApplication {\n const authority = getAuthority(authentication.authorityHost!, authentication.tenantId!);\n const clientCertificate: ClientCertificate | undefined = parseCertificate(\n authentication.certificateContent\n );\n\n const auth: NodeAuthOptions = {\n clientId: authentication.clientId!,\n authority: authority,\n };\n\n if (clientCertificate) {\n auth.clientCertificate = clientCertificate;\n } else {\n auth.clientSecret = authentication.clientSecret;\n }\n\n return new ConfidentialClientApplication({\n auth,\n });\n}\n"]}