@azure/identity-broker 1.0.1-alpha.20240207.2 → 1.0.1-alpha.20240215.2
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/package.json +1 -1
- package/dist-esm/identity/src/constants.js +0 -60
- package/dist-esm/identity/src/constants.js.map +0 -1
- package/dist-esm/identity/src/errors.js +0 -119
- package/dist-esm/identity/src/errors.js.map +0 -1
- package/dist-esm/identity/src/msal/msal.js +0 -5
- package/dist-esm/identity/src/msal/msal.js.map +0 -1
- package/dist-esm/identity/src/msal/types.js +0 -4
- package/dist-esm/identity/src/msal/types.js.map +0 -1
- package/dist-esm/identity/src/msal/utils.js +0 -222
- package/dist-esm/identity/src/msal/utils.js.map +0 -1
- package/dist-esm/identity/src/util/logging.js +0 -94
- package/dist-esm/identity/src/util/logging.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/identity-broker",
|
|
3
|
-
"version": "1.0.1-alpha.
|
|
3
|
+
"version": "1.0.1-alpha.20240215.2",
|
|
4
4
|
"sdk-type": "client",
|
|
5
5
|
"description": "A native plugin for Azure Identity credentials to enable broker authentication such as WAM",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
/**
|
|
4
|
-
* Current version of the `@azure/identity` package.
|
|
5
|
-
*/
|
|
6
|
-
export const SDK_VERSION = `4.1.0-beta.2`;
|
|
7
|
-
/**
|
|
8
|
-
* The default client ID for authentication
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
// TODO: temporary - this is the Azure CLI clientID - we'll replace it when
|
|
12
|
-
// Developer Sign On application is available
|
|
13
|
-
// https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/Constants.cs#L9
|
|
14
|
-
export const DeveloperSignOnClientId = "04b07795-8ddb-461a-bbee-02f9e1bf7b46";
|
|
15
|
-
/**
|
|
16
|
-
* The default tenant for authentication
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export const DefaultTenantId = "common";
|
|
20
|
-
/**
|
|
21
|
-
* A list of known Azure authority hosts
|
|
22
|
-
*/
|
|
23
|
-
export var AzureAuthorityHosts;
|
|
24
|
-
(function (AzureAuthorityHosts) {
|
|
25
|
-
/**
|
|
26
|
-
* China-based Azure Authority Host
|
|
27
|
-
*/
|
|
28
|
-
AzureAuthorityHosts["AzureChina"] = "https://login.chinacloudapi.cn";
|
|
29
|
-
/**
|
|
30
|
-
* Germany-based Azure Authority Host
|
|
31
|
-
*/
|
|
32
|
-
AzureAuthorityHosts["AzureGermany"] = "https://login.microsoftonline.de";
|
|
33
|
-
/**
|
|
34
|
-
* US Government Azure Authority Host
|
|
35
|
-
*/
|
|
36
|
-
AzureAuthorityHosts["AzureGovernment"] = "https://login.microsoftonline.us";
|
|
37
|
-
/**
|
|
38
|
-
* Public Cloud Azure Authority Host
|
|
39
|
-
*/
|
|
40
|
-
AzureAuthorityHosts["AzurePublicCloud"] = "https://login.microsoftonline.com";
|
|
41
|
-
})(AzureAuthorityHosts || (AzureAuthorityHosts = {}));
|
|
42
|
-
/**
|
|
43
|
-
* @internal
|
|
44
|
-
* The default authority host.
|
|
45
|
-
*/
|
|
46
|
-
export const DefaultAuthorityHost = AzureAuthorityHosts.AzurePublicCloud;
|
|
47
|
-
/**
|
|
48
|
-
* @internal
|
|
49
|
-
* Allow acquiring tokens for any tenant for multi-tentant auth.
|
|
50
|
-
*/
|
|
51
|
-
export const ALL_TENANTS = ["*"];
|
|
52
|
-
/**
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
export const CACHE_CAE_SUFFIX = ".cae";
|
|
56
|
-
/**
|
|
57
|
-
* @internal
|
|
58
|
-
*/
|
|
59
|
-
export const CACHE_NON_CAE_SUFFIX = ".nocae";
|
|
60
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../identity/src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,cAAc,CAAC;AAE1C;;;GAGG;AACH,2EAA2E;AAC3E,6CAA6C;AAC7C,uGAAuG;AACvG,MAAM,CAAC,MAAM,uBAAuB,GAAG,sCAAsC,CAAC;AAE9E;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC;AAExC;;GAEG;AACH,MAAM,CAAN,IAAY,mBAiBX;AAjBD,WAAY,mBAAmB;IAC7B;;OAEG;IACH,oEAA6C,CAAA;IAC7C;;OAEG;IACH,wEAAiD,CAAA;IACjD;;OAEG;IACH,2EAAoD,CAAA;IACpD;;OAEG;IACH,6EAAsD,CAAA;AACxD,CAAC,EAjBW,mBAAmB,KAAnB,mBAAmB,QAiB9B;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC,gBAAgB,CAAC;AAEzE;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAa,CAAC,GAAG,CAAC,CAAC;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Current version of the `@azure/identity` package.\n */\nexport const SDK_VERSION = `4.1.0-beta.2`;\n\n/**\n * The default client ID for authentication\n * @internal\n */\n// TODO: temporary - this is the Azure CLI clientID - we'll replace it when\n// Developer Sign On application is available\n// https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/Constants.cs#L9\nexport const DeveloperSignOnClientId = \"04b07795-8ddb-461a-bbee-02f9e1bf7b46\";\n\n/**\n * The default tenant for authentication\n * @internal\n */\nexport const DefaultTenantId = \"common\";\n\n/**\n * A list of known Azure authority hosts\n */\nexport enum AzureAuthorityHosts {\n /**\n * China-based Azure Authority Host\n */\n AzureChina = \"https://login.chinacloudapi.cn\",\n /**\n * Germany-based Azure Authority Host\n */\n AzureGermany = \"https://login.microsoftonline.de\",\n /**\n * US Government Azure Authority Host\n */\n AzureGovernment = \"https://login.microsoftonline.us\",\n /**\n * Public Cloud Azure Authority Host\n */\n AzurePublicCloud = \"https://login.microsoftonline.com\",\n}\n\n/**\n * @internal\n * The default authority host.\n */\nexport const DefaultAuthorityHost = AzureAuthorityHosts.AzurePublicCloud;\n\n/**\n * @internal\n * Allow acquiring tokens for any tenant for multi-tentant auth.\n */\nexport const ALL_TENANTS: string[] = [\"*\"];\n\n/**\n * @internal\n */\nexport const CACHE_CAE_SUFFIX = \".cae\";\n\n/**\n * @internal\n */\nexport const CACHE_NON_CAE_SUFFIX = \".nocae\";\n"]}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
function isErrorResponse(errorResponse) {
|
|
4
|
-
return (errorResponse &&
|
|
5
|
-
typeof errorResponse.error === "string" &&
|
|
6
|
-
typeof errorResponse.error_description === "string");
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* The Error.name value of an CredentialUnavailable
|
|
10
|
-
*/
|
|
11
|
-
export const CredentialUnavailableErrorName = "CredentialUnavailableError";
|
|
12
|
-
/**
|
|
13
|
-
* This signifies that the credential that was tried in a chained credential
|
|
14
|
-
* was not available to be used as the credential. Rather than treating this as
|
|
15
|
-
* an error that should halt the chain, it's caught and the chain continues
|
|
16
|
-
*/
|
|
17
|
-
export class CredentialUnavailableError extends Error {
|
|
18
|
-
constructor(message) {
|
|
19
|
-
super(message);
|
|
20
|
-
this.name = CredentialUnavailableErrorName;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* The Error.name value of an AuthenticationError
|
|
25
|
-
*/
|
|
26
|
-
export const AuthenticationErrorName = "AuthenticationError";
|
|
27
|
-
/**
|
|
28
|
-
* Provides details about a failure to authenticate with Azure Active
|
|
29
|
-
* Directory. The `errorResponse` field contains more details about
|
|
30
|
-
* the specific failure.
|
|
31
|
-
*/
|
|
32
|
-
export class AuthenticationError extends Error {
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
34
|
-
constructor(statusCode, errorBody) {
|
|
35
|
-
let errorResponse = {
|
|
36
|
-
error: "unknown",
|
|
37
|
-
errorDescription: "An unknown error occurred and no additional details are available.",
|
|
38
|
-
};
|
|
39
|
-
if (isErrorResponse(errorBody)) {
|
|
40
|
-
errorResponse = convertOAuthErrorResponseToErrorResponse(errorBody);
|
|
41
|
-
}
|
|
42
|
-
else if (typeof errorBody === "string") {
|
|
43
|
-
try {
|
|
44
|
-
// Most error responses will contain JSON-formatted error details
|
|
45
|
-
// in the response body
|
|
46
|
-
const oauthErrorResponse = JSON.parse(errorBody);
|
|
47
|
-
errorResponse = convertOAuthErrorResponseToErrorResponse(oauthErrorResponse);
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
if (statusCode === 400) {
|
|
51
|
-
errorResponse = {
|
|
52
|
-
error: "authority_not_found",
|
|
53
|
-
errorDescription: "The specified authority URL was not found.",
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
errorResponse = {
|
|
58
|
-
error: "unknown_error",
|
|
59
|
-
errorDescription: `An unknown error has occurred. Response body:\n\n${errorBody}`,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
errorResponse = {
|
|
66
|
-
error: "unknown_error",
|
|
67
|
-
errorDescription: "An unknown error occurred and no additional details are available.",
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
super(`${errorResponse.error} Status code: ${statusCode}\nMore details:\n${errorResponse.errorDescription}`);
|
|
71
|
-
this.statusCode = statusCode;
|
|
72
|
-
this.errorResponse = errorResponse;
|
|
73
|
-
// Ensure that this type reports the correct name
|
|
74
|
-
this.name = AuthenticationErrorName;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* The Error.name value of an AggregateAuthenticationError
|
|
79
|
-
*/
|
|
80
|
-
export const AggregateAuthenticationErrorName = "AggregateAuthenticationError";
|
|
81
|
-
/**
|
|
82
|
-
* Provides an `errors` array containing {@link AuthenticationError} instance
|
|
83
|
-
* for authentication failures from credentials in a {@link ChainedTokenCredential}.
|
|
84
|
-
*/
|
|
85
|
-
export class AggregateAuthenticationError extends Error {
|
|
86
|
-
constructor(errors, errorMessage) {
|
|
87
|
-
const errorDetail = errors.join("\n");
|
|
88
|
-
super(`${errorMessage}\n${errorDetail}`);
|
|
89
|
-
this.errors = errors;
|
|
90
|
-
// Ensure that this type reports the correct name
|
|
91
|
-
this.name = AggregateAuthenticationErrorName;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
function convertOAuthErrorResponseToErrorResponse(errorBody) {
|
|
95
|
-
return {
|
|
96
|
-
error: errorBody.error,
|
|
97
|
-
errorDescription: errorBody.error_description,
|
|
98
|
-
correlationId: errorBody.correlation_id,
|
|
99
|
-
errorCodes: errorBody.error_codes,
|
|
100
|
-
timestamp: errorBody.timestamp,
|
|
101
|
-
traceId: errorBody.trace_id,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Error used to enforce authentication after trying to retrieve a token silently.
|
|
106
|
-
*/
|
|
107
|
-
export class AuthenticationRequiredError extends Error {
|
|
108
|
-
constructor(
|
|
109
|
-
/**
|
|
110
|
-
* Optional parameters. A message can be specified. The {@link GetTokenOptions} of the request can also be specified to more easily associate the error with the received parameters.
|
|
111
|
-
*/
|
|
112
|
-
options) {
|
|
113
|
-
super(options.message);
|
|
114
|
-
this.scopes = options.scopes;
|
|
115
|
-
this.getTokenOptions = options.getTokenOptions;
|
|
116
|
-
this.name = "AuthenticationRequiredError";
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../identity/src/errors.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAyDlC,SAAS,eAAe,CAAC,aAAkB;IACzC,OAAO,CACL,aAAa;QACb,OAAO,aAAa,CAAC,KAAK,KAAK,QAAQ;QACvC,OAAO,aAAa,CAAC,iBAAiB,KAAK,QAAQ,CACpD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,4BAA4B,CAAC;AAE3E;;;;GAIG;AACH,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC7C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,qBAAqB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAW5C,wDAAwD;IACxD,YAAY,UAAkB,EAAE,SAA6C;QAC3E,IAAI,aAAa,GAAkB;YACjC,KAAK,EAAE,SAAS;YAChB,gBAAgB,EAAE,oEAAoE;SACvF,CAAC;QAEF,IAAI,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;YAC/B,aAAa,GAAG,wCAAwC,CAAC,SAAS,CAAC,CAAC;QACtE,CAAC;aAAM,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;YACzC,IAAI,CAAC;gBACH,iEAAiE;gBACjE,uBAAuB;gBACvB,MAAM,kBAAkB,GAAuB,IAAI,CAAC,KA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ACL,KAAK,EAAE,SAAS,CAAC,KAAK;QACtB,gBAAgB,EAAE,SAAS,CAAC,iBAAiB;QAC7C,aAAa,EAAE,SAAS,CAAC,cAAc;QACvC,UAAU,EAAE,SAAS,CAAC,WAAW;QACjC,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,OAAO,EAAE,SAAS,CAAC,QAAQ;KAC5B,CAAC;AACJ,CAAC;AAoBD;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAUpD;IACE;;OAEG;IACH,OAA2C;QAE3C,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { GetTokenOptions } from \"@azure/core-auth\";\n\n/**\n * See the official documentation for more details:\n *\n * https://learn.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-oauth-code#error-response-1\n *\n * NOTE: This documentation is for v1 OAuth support but the same error\n * response details still apply to v2.\n */\nexport interface ErrorResponse {\n /**\n * The string identifier for the error.\n */\n error: string;\n\n /**\n * The error's description.\n */\n errorDescription: string;\n\n /**\n * An array of codes pertaining to the error(s) that occurred.\n */\n errorCodes?: number[];\n\n /**\n * The timestamp at which the error occurred.\n */\n timestamp?: string;\n\n /**\n * The trace identifier for this error occurrence.\n */\n traceId?: string;\n\n /**\n * The correlation ID to be used for tracking the source of the error.\n */\n correlationId?: string;\n}\n\n/**\n * Used for internal deserialization of OAuth responses. Public model is ErrorResponse\n * @internal\n */\nexport interface OAuthErrorResponse {\n error: string;\n error_description: string;\n error_codes?: number[];\n timestamp?: string;\n trace_id?: string;\n correlation_id?: string;\n}\n\nfunction isErrorResponse(errorResponse: any): errorResponse is OAuthErrorResponse {\n return (\n errorResponse &&\n typeof errorResponse.error === \"string\" &&\n typeof errorResponse.error_description === \"string\"\n );\n}\n\n/**\n * The Error.name value of an CredentialUnavailable\n */\nexport const CredentialUnavailableErrorName = \"CredentialUnavailableError\";\n\n/**\n * This signifies that the credential that was tried in a chained credential\n * was not available to be used as the credential. Rather than treating this as\n * an error that should halt the chain, it's caught and the chain continues\n */\nexport class CredentialUnavailableError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = CredentialUnavailableErrorName;\n }\n}\n\n/**\n * The Error.name value of an AuthenticationError\n */\nexport const AuthenticationErrorName = \"AuthenticationError\";\n\n/**\n * Provides details about a failure to authenticate with Azure Active\n * Directory. The `errorResponse` field contains more details about\n * the specific failure.\n */\nexport class AuthenticationError extends Error {\n /**\n * The HTTP status code returned from the authentication request.\n */\n public readonly statusCode: number;\n\n /**\n * The error response details.\n */\n public readonly errorResponse: ErrorResponse;\n\n // eslint-disable-next-line @typescript-eslint/ban-types\n constructor(statusCode: number, errorBody: object | string | undefined | null) {\n let errorResponse: ErrorResponse = {\n error: \"unknown\",\n errorDescription: \"An unknown error occurred and no additional details are available.\",\n };\n\n if (isErrorResponse(errorBody)) {\n errorResponse = convertOAuthErrorResponseToErrorResponse(errorBody);\n } else if (typeof errorBody === \"string\") {\n try {\n // Most error responses will contain JSON-formatted error details\n // in the response body\n const oauthErrorResponse: OAuthErrorResponse = JSON.parse(errorBody);\n errorResponse = convertOAuthErrorResponseToErrorResponse(oauthErrorResponse);\n } catch (e: any) {\n if (statusCode === 400) {\n errorResponse = {\n error: \"authority_not_found\",\n errorDescription: \"The specified authority URL was not found.\",\n };\n } else {\n errorResponse = {\n error: \"unknown_error\",\n errorDescription: `An unknown error has occurred. Response body:\\n\\n${errorBody}`,\n };\n }\n }\n } else {\n errorResponse = {\n error: \"unknown_error\",\n errorDescription: \"An unknown error occurred and no additional details are available.\",\n };\n }\n\n super(\n `${errorResponse.error} Status code: ${statusCode}\\nMore details:\\n${errorResponse.errorDescription}`,\n );\n this.statusCode = statusCode;\n this.errorResponse = errorResponse;\n\n // Ensure that this type reports the correct name\n this.name = AuthenticationErrorName;\n }\n}\n\n/**\n * The Error.name value of an AggregateAuthenticationError\n */\nexport const AggregateAuthenticationErrorName = \"AggregateAuthenticationError\";\n\n/**\n * Provides an `errors` array containing {@link AuthenticationError} instance\n * for authentication failures from credentials in a {@link ChainedTokenCredential}.\n */\nexport class AggregateAuthenticationError extends Error {\n /**\n * The array of error objects that were thrown while trying to authenticate\n * with the credentials in a {@link ChainedTokenCredential}.\n */\n public errors: any[];\n\n constructor(errors: any[], errorMessage?: string) {\n const errorDetail = errors.join(\"\\n\");\n super(`${errorMessage}\\n${errorDetail}`);\n this.errors = errors;\n\n // Ensure that this type reports the correct name\n this.name = AggregateAuthenticationErrorName;\n }\n}\n\nfunction convertOAuthErrorResponseToErrorResponse(errorBody: OAuthErrorResponse): ErrorResponse {\n return {\n error: errorBody.error,\n errorDescription: errorBody.error_description,\n correlationId: errorBody.correlation_id,\n errorCodes: errorBody.error_codes,\n timestamp: errorBody.timestamp,\n traceId: errorBody.trace_id,\n };\n}\n\n/**\n * Optional parameters to the {@link AuthenticationRequiredError}\n */\nexport interface AuthenticationRequiredErrorOptions {\n /**\n * The list of scopes for which the token will have access.\n */\n scopes: string[];\n /**\n * The options passed to the getToken request.\n */\n getTokenOptions?: GetTokenOptions;\n /**\n * The message of the error.\n */\n message?: string;\n}\n\n/**\n * Error used to enforce authentication after trying to retrieve a token silently.\n */\nexport class AuthenticationRequiredError extends Error {\n /**\n * The list of scopes for which the token will have access.\n */\n public scopes: string[];\n /**\n * The options passed to the getToken request.\n */\n public getTokenOptions?: GetTokenOptions;\n\n constructor(\n /**\n * Optional parameters. A message can be specified. The {@link GetTokenOptions} of the request can also be specified to more easily associate the error with the received parameters.\n */\n options: AuthenticationRequiredErrorOptions,\n ) {\n super(options.message);\n this.scopes = options.scopes;\n this.getTokenOptions = options.getTokenOptions;\n this.name = \"AuthenticationRequiredError\";\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"msal.js","sourceRoot":"","sources":["../../../../../identity/src/msal/msal.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as msalCommon from \"@azure/msal-node\";\n\nexport { msalCommon };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../identity/src/msal/types.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * @internal\n */\nexport type AppType = \"public\" | \"confidential\" | \"publicFirst\" | \"confidentialFirst\";\n\n/**\n * The shape we use return the token (and the expiration date).\n * @internal\n */\nexport interface MsalToken {\n accessToken?: string;\n expiresOn: Date | null;\n}\n\n/**\n * Internal representation of MSAL's Account information.\n * Helps us to disambiguate the MSAL classes accross environments.\n * @internal\n */\nexport interface MsalAccountInfo {\n homeAccountId: string;\n environment?: string;\n tenantId: string;\n username: string;\n localAccountId: string;\n name?: string;\n // Leaving idTokenClaims as object since that's how MSAL has this assigned.\n /* eslint-disable-next-line @typescript-eslint/ban-types */\n idTokenClaims?: object;\n}\n\n/**\n * Represents the common properties of any of the MSAL responses.\n * @internal\n */\nexport interface MsalResult {\n authority?: string;\n account: MsalAccountInfo | null;\n accessToken: string;\n expiresOn: Date | null;\n}\n\n/**\n * The record to use to find the cached tokens in the cache.\n */\nexport interface AuthenticationRecord {\n /**\n * The associated authority, if used.\n */\n authority: string;\n /**\n * The home account Id.\n */\n homeAccountId: string;\n /**\n * The associated client ID.\n */\n clientId: string;\n /**\n * The associated tenant ID.\n */\n tenantId: string;\n /**\n * The username of the logged in account.\n */\n username: string;\n}\n"]}
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
import { AuthenticationRequiredError, CredentialUnavailableError } from "../errors";
|
|
4
|
-
import { credentialLogger, formatError } from "../util/logging";
|
|
5
|
-
import { DefaultAuthorityHost, DefaultTenantId } from "../constants";
|
|
6
|
-
import { randomUUID as coreRandomUUID, isNode } from "@azure/core-util";
|
|
7
|
-
import { AbortError } from "@azure/abort-controller";
|
|
8
|
-
import { msalCommon } from "./msal";
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
const logger = credentialLogger("IdentityUtils");
|
|
13
|
-
/**
|
|
14
|
-
* Latest AuthenticationRecord version
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
const LatestAuthenticationRecordVersion = "1.0";
|
|
18
|
-
/**
|
|
19
|
-
* Ensures the validity of the MSAL token
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
export function ensureValidMsalToken(scopes, msalToken, getTokenOptions) {
|
|
23
|
-
const error = (message) => {
|
|
24
|
-
logger.getToken.info(message);
|
|
25
|
-
return new AuthenticationRequiredError({
|
|
26
|
-
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
27
|
-
getTokenOptions,
|
|
28
|
-
message,
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
if (!msalToken) {
|
|
32
|
-
throw error("No response");
|
|
33
|
-
}
|
|
34
|
-
if (!msalToken.expiresOn) {
|
|
35
|
-
throw error(`Response had no "expiresOn" property.`);
|
|
36
|
-
}
|
|
37
|
-
if (!msalToken.accessToken) {
|
|
38
|
-
throw error(`Response had no "accessToken" property.`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Generates a valid authority by combining a host with a tenantId.
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
export function getAuthority(tenantId, host) {
|
|
46
|
-
if (!host) {
|
|
47
|
-
host = DefaultAuthorityHost;
|
|
48
|
-
}
|
|
49
|
-
if (new RegExp(`${tenantId}/?$`).test(host)) {
|
|
50
|
-
return host;
|
|
51
|
-
}
|
|
52
|
-
if (host.endsWith("/")) {
|
|
53
|
-
return host + tenantId;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return `${host}/${tenantId}`;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Generates the known authorities.
|
|
61
|
-
* If the Tenant Id is `adfs`, the authority can't be validated since the format won't match the expected one.
|
|
62
|
-
* For that reason, we have to force MSAL to disable validating the authority
|
|
63
|
-
* by sending it within the known authorities in the MSAL configuration.
|
|
64
|
-
* @internal
|
|
65
|
-
*/
|
|
66
|
-
export function getKnownAuthorities(tenantId, authorityHost, disableInstanceDiscovery) {
|
|
67
|
-
if ((tenantId === "adfs" && authorityHost) || disableInstanceDiscovery) {
|
|
68
|
-
return [authorityHost];
|
|
69
|
-
}
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Generates a logger that can be passed to the MSAL clients.
|
|
74
|
-
* @param credLogger - The logger of the credential.
|
|
75
|
-
* @internal
|
|
76
|
-
*/
|
|
77
|
-
export const defaultLoggerCallback = (credLogger, platform = isNode ? "Node" : "Browser") => (level, message, containsPii) => {
|
|
78
|
-
if (containsPii) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
switch (level) {
|
|
82
|
-
case msalCommon.LogLevel.Error:
|
|
83
|
-
credLogger.info(`MSAL ${platform} V2 error: ${message}`);
|
|
84
|
-
return;
|
|
85
|
-
case msalCommon.LogLevel.Info:
|
|
86
|
-
credLogger.info(`MSAL ${platform} V2 info message: ${message}`);
|
|
87
|
-
return;
|
|
88
|
-
case msalCommon.LogLevel.Verbose:
|
|
89
|
-
credLogger.info(`MSAL ${platform} V2 verbose message: ${message}`);
|
|
90
|
-
return;
|
|
91
|
-
case msalCommon.LogLevel.Warning:
|
|
92
|
-
credLogger.info(`MSAL ${platform} V2 warning: ${message}`);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* @internal
|
|
98
|
-
*/
|
|
99
|
-
export function getMSALLogLevel(logLevel) {
|
|
100
|
-
switch (logLevel) {
|
|
101
|
-
case "error":
|
|
102
|
-
return msalCommon.LogLevel.Error;
|
|
103
|
-
case "info":
|
|
104
|
-
return msalCommon.LogLevel.Info;
|
|
105
|
-
case "verbose":
|
|
106
|
-
return msalCommon.LogLevel.Verbose;
|
|
107
|
-
case "warning":
|
|
108
|
-
return msalCommon.LogLevel.Warning;
|
|
109
|
-
default:
|
|
110
|
-
// default msal logging level should be Info
|
|
111
|
-
return msalCommon.LogLevel.Info;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Wraps core-util's randomUUID in order to allow for mocking in tests.
|
|
116
|
-
* This prepares the library for the upcoming core-util update to ESM.
|
|
117
|
-
*
|
|
118
|
-
* @internal
|
|
119
|
-
* @returns A string containing a random UUID
|
|
120
|
-
*/
|
|
121
|
-
export function randomUUID() {
|
|
122
|
-
return coreRandomUUID();
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Handles MSAL errors.
|
|
126
|
-
*/
|
|
127
|
-
export function handleMsalError(scopes, error, getTokenOptions) {
|
|
128
|
-
if (error.name === "AuthError" ||
|
|
129
|
-
error.name === "ClientAuthError" ||
|
|
130
|
-
error.name === "BrowserAuthError") {
|
|
131
|
-
const msalError = error;
|
|
132
|
-
switch (msalError.errorCode) {
|
|
133
|
-
case "endpoints_resolution_error":
|
|
134
|
-
logger.info(formatError(scopes, error.message));
|
|
135
|
-
return new CredentialUnavailableError(error.message);
|
|
136
|
-
case "device_code_polling_cancelled":
|
|
137
|
-
return new AbortError("The authentication has been aborted by the caller.");
|
|
138
|
-
case "consent_required":
|
|
139
|
-
case "interaction_required":
|
|
140
|
-
case "login_required":
|
|
141
|
-
logger.info(formatError(scopes, `Authentication returned errorCode ${msalError.errorCode}`));
|
|
142
|
-
break;
|
|
143
|
-
default:
|
|
144
|
-
logger.info(formatError(scopes, `Failed to acquire token: ${error.message}`));
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (error.name === "ClientConfigurationError" ||
|
|
149
|
-
error.name === "BrowserConfigurationAuthError" ||
|
|
150
|
-
error.name === "AbortError") {
|
|
151
|
-
return error;
|
|
152
|
-
}
|
|
153
|
-
if (error.name === "NativeAuthError") {
|
|
154
|
-
logger.info(formatError(scopes, `Error from the native broker: ${error.message} with status code: ${error.statusCode}`));
|
|
155
|
-
return error;
|
|
156
|
-
}
|
|
157
|
-
return new AuthenticationRequiredError({ scopes, getTokenOptions, message: error.message });
|
|
158
|
-
}
|
|
159
|
-
// transformations.ts
|
|
160
|
-
export function publicToMsal(account) {
|
|
161
|
-
const [environment] = account.authority.match(/([a-z]*\.[a-z]*\.[a-z]*)/) || [""];
|
|
162
|
-
return {
|
|
163
|
-
...account,
|
|
164
|
-
localAccountId: account.homeAccountId,
|
|
165
|
-
environment,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
export function msalToPublic(clientId, account) {
|
|
169
|
-
const record = {
|
|
170
|
-
authority: getAuthority(account.tenantId, account.environment),
|
|
171
|
-
homeAccountId: account.homeAccountId,
|
|
172
|
-
tenantId: account.tenantId || DefaultTenantId,
|
|
173
|
-
username: account.username,
|
|
174
|
-
clientId,
|
|
175
|
-
version: LatestAuthenticationRecordVersion,
|
|
176
|
-
};
|
|
177
|
-
return record;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Serializes an `AuthenticationRecord` into a string.
|
|
181
|
-
*
|
|
182
|
-
* The output of a serialized authentication record will contain the following properties:
|
|
183
|
-
*
|
|
184
|
-
* - "authority"
|
|
185
|
-
* - "homeAccountId"
|
|
186
|
-
* - "clientId"
|
|
187
|
-
* - "tenantId"
|
|
188
|
-
* - "username"
|
|
189
|
-
* - "version"
|
|
190
|
-
*
|
|
191
|
-
* To later convert this string to a serialized `AuthenticationRecord`, please use the exported function `deserializeAuthenticationRecord()`.
|
|
192
|
-
*/
|
|
193
|
-
export function serializeAuthenticationRecord(record) {
|
|
194
|
-
return JSON.stringify(record);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Deserializes a previously serialized authentication record from a string into an object.
|
|
198
|
-
*
|
|
199
|
-
* The input string must contain the following properties:
|
|
200
|
-
*
|
|
201
|
-
* - "authority"
|
|
202
|
-
* - "homeAccountId"
|
|
203
|
-
* - "clientId"
|
|
204
|
-
* - "tenantId"
|
|
205
|
-
* - "username"
|
|
206
|
-
* - "version"
|
|
207
|
-
*
|
|
208
|
-
* If the version we receive is unsupported, an error will be thrown.
|
|
209
|
-
*
|
|
210
|
-
* At the moment, the only available version is: "1.0", which is always set when the authentication record is serialized.
|
|
211
|
-
*
|
|
212
|
-
* @param serializedRecord - Authentication record previously serialized into string.
|
|
213
|
-
* @returns AuthenticationRecord.
|
|
214
|
-
*/
|
|
215
|
-
export function deserializeAuthenticationRecord(serializedRecord) {
|
|
216
|
-
const parsed = JSON.parse(serializedRecord);
|
|
217
|
-
if (parsed.version && parsed.version !== LatestAuthenticationRecordVersion) {
|
|
218
|
-
throw Error("Unsupported AuthenticationRecord version");
|
|
219
|
-
}
|
|
220
|
-
return parsed;
|
|
221
|
-
}
|
|
222
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../identity/src/msal/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AACpF,OAAO,EAAoB,gBAAgB,EAAE,WAAW,EAAE,MAAM,iBAAiB,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AO,CAAC,WAAW,CAAC;QAC9D,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,eAAe;QAC7C,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,QAAQ;QACR,OAAO,EAAE,iCAAiC;KAC3C,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,6BAA6B,CAAC,MAA4B;IACxE,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,+BAA+B,CAAC,gBAAwB;IACtE,MAAM,MAAM,GAAgD,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAEzF,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,KAAK,iCAAiC,EAAE,CAAC;QAC3E,MAAM,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AuthenticationRecord, MsalAccountInfo, MsalToken } from \"./types\";\nimport { AuthenticationRequiredError, CredentialUnavailableError } from \"../errors\";\nimport { CredentialLogger, credentialLogger, formatError } from \"../util/logging\";\nimport { DefaultAuthorityHost, DefaultTenantId } from \"../constants\";\nimport { randomUUID as coreRandomUUID, isNode } from \"@azure/core-util\";\n\nimport { AbortError } from \"@azure/abort-controller\";\nimport { AzureLogLevel } from \"@azure/logger\";\nimport { GetTokenOptions } from \"@azure/core-auth\";\nimport { msalCommon } from \"./msal\";\n\nexport interface ILoggerCallback {\n (level: msalCommon.LogLevel, message: string, containsPii: boolean): void;\n}\n\n/**\n * @internal\n */\nconst logger = credentialLogger(\"IdentityUtils\");\n\n/**\n * Latest AuthenticationRecord version\n * @internal\n */\nconst LatestAuthenticationRecordVersion = \"1.0\";\n\n/**\n * Ensures the validity of the MSAL token\n * @internal\n */\nexport function ensureValidMsalToken(\n scopes: string | string[],\n msalToken?: MsalToken,\n getTokenOptions?: GetTokenOptions,\n): void {\n const error = (message: string): Error => {\n logger.getToken.info(message);\n return new AuthenticationRequiredError({\n scopes: Array.isArray(scopes) ? scopes : [scopes],\n getTokenOptions,\n message,\n });\n };\n if (!msalToken) {\n throw error(\"No response\");\n }\n if (!msalToken.expiresOn) {\n throw error(`Response had no \"expiresOn\" property.`);\n }\n if (!msalToken.accessToken) {\n throw error(`Response had no \"accessToken\" property.`);\n }\n}\n\n/**\n * Generates a valid authority by combining a host with a tenantId.\n * @internal\n */\nexport function getAuthority(tenantId: string, host?: string): string {\n if (!host) {\n host = DefaultAuthorityHost;\n }\n if (new RegExp(`${tenantId}/?$`).test(host)) {\n return host;\n }\n if (host.endsWith(\"/\")) {\n return host + tenantId;\n } else {\n return `${host}/${tenantId}`;\n }\n}\n\n/**\n * Generates the known authorities.\n * If the Tenant Id is `adfs`, the authority can't be validated since the format won't match the expected one.\n * For that reason, we have to force MSAL to disable validating the authority\n * by sending it within the known authorities in the MSAL configuration.\n * @internal\n */\nexport function getKnownAuthorities(\n tenantId: string,\n authorityHost: string,\n disableInstanceDiscovery?: boolean,\n): string[] {\n if ((tenantId === \"adfs\" && authorityHost) || disableInstanceDiscovery) {\n return [authorityHost];\n }\n return [];\n}\n\n/**\n * Generates a logger that can be passed to the MSAL clients.\n * @param credLogger - The logger of the credential.\n * @internal\n */\nexport const defaultLoggerCallback: (\n logger: CredentialLogger,\n platform?: \"Node\" | \"Browser\",\n) => ILoggerCallback =\n (credLogger: CredentialLogger, platform: \"Node\" | \"Browser\" = isNode ? \"Node\" : \"Browser\") =>\n (level, message, containsPii): void => {\n if (containsPii) {\n return;\n }\n switch (level) {\n case msalCommon.LogLevel.Error:\n credLogger.info(`MSAL ${platform} V2 error: ${message}`);\n return;\n case msalCommon.LogLevel.Info:\n credLogger.info(`MSAL ${platform} V2 info message: ${message}`);\n return;\n case msalCommon.LogLevel.Verbose:\n credLogger.info(`MSAL ${platform} V2 verbose message: ${message}`);\n return;\n case msalCommon.LogLevel.Warning:\n credLogger.info(`MSAL ${platform} V2 warning: ${message}`);\n return;\n }\n };\n\n/**\n * @internal\n */\nexport function getMSALLogLevel(logLevel: AzureLogLevel | undefined): msalCommon.LogLevel {\n switch (logLevel) {\n case \"error\":\n return msalCommon.LogLevel.Error;\n case \"info\":\n return msalCommon.LogLevel.Info;\n case \"verbose\":\n return msalCommon.LogLevel.Verbose;\n case \"warning\":\n return msalCommon.LogLevel.Warning;\n default:\n // default msal logging level should be Info\n return msalCommon.LogLevel.Info;\n }\n}\n\n/**\n * Wraps core-util's randomUUID in order to allow for mocking in tests.\n * This prepares the library for the upcoming core-util update to ESM.\n *\n * @internal\n * @returns A string containing a random UUID\n */\nexport function randomUUID(): string {\n return coreRandomUUID();\n}\n\n/**\n * Handles MSAL errors.\n */\nexport function handleMsalError(\n scopes: string[],\n error: Error,\n getTokenOptions?: GetTokenOptions,\n): Error {\n if (\n error.name === \"AuthError\" ||\n error.name === \"ClientAuthError\" ||\n error.name === \"BrowserAuthError\"\n ) {\n const msalError = error as msalCommon.AuthError;\n switch (msalError.errorCode) {\n case \"endpoints_resolution_error\":\n logger.info(formatError(scopes, error.message));\n return new CredentialUnavailableError(error.message);\n case \"device_code_polling_cancelled\":\n return new AbortError(\"The authentication has been aborted by the caller.\");\n case \"consent_required\":\n case \"interaction_required\":\n case \"login_required\":\n logger.info(\n formatError(scopes, `Authentication returned errorCode ${msalError.errorCode}`),\n );\n break;\n default:\n logger.info(formatError(scopes, `Failed to acquire token: ${error.message}`));\n break;\n }\n }\n if (\n error.name === \"ClientConfigurationError\" ||\n error.name === \"BrowserConfigurationAuthError\" ||\n error.name === \"AbortError\"\n ) {\n return error;\n }\n if (error.name === \"NativeAuthError\") {\n logger.info(\n formatError(\n scopes,\n `Error from the native broker: ${error.message} with status code: ${\n (error as any).statusCode\n }`,\n ),\n );\n return error;\n }\n return new AuthenticationRequiredError({ scopes, getTokenOptions, message: error.message });\n}\n\n// transformations.ts\n\nexport function publicToMsal(account: AuthenticationRecord): msalCommon.AccountInfo {\n const [environment] = account.authority.match(/([a-z]*\\.[a-z]*\\.[a-z]*)/) || [\"\"];\n return {\n ...account,\n localAccountId: account.homeAccountId,\n environment,\n };\n}\n\nexport function msalToPublic(clientId: string, account: MsalAccountInfo): AuthenticationRecord {\n const record = {\n authority: getAuthority(account.tenantId, account.environment),\n homeAccountId: account.homeAccountId,\n tenantId: account.tenantId || DefaultTenantId,\n username: account.username,\n clientId,\n version: LatestAuthenticationRecordVersion,\n };\n return record;\n}\n\n/**\n * Serializes an `AuthenticationRecord` into a string.\n *\n * The output of a serialized authentication record will contain the following properties:\n *\n * - \"authority\"\n * - \"homeAccountId\"\n * - \"clientId\"\n * - \"tenantId\"\n * - \"username\"\n * - \"version\"\n *\n * To later convert this string to a serialized `AuthenticationRecord`, please use the exported function `deserializeAuthenticationRecord()`.\n */\nexport function serializeAuthenticationRecord(record: AuthenticationRecord): string {\n return JSON.stringify(record);\n}\n\n/**\n * Deserializes a previously serialized authentication record from a string into an object.\n *\n * The input string must contain the following properties:\n *\n * - \"authority\"\n * - \"homeAccountId\"\n * - \"clientId\"\n * - \"tenantId\"\n * - \"username\"\n * - \"version\"\n *\n * If the version we receive is unsupported, an error will be thrown.\n *\n * At the moment, the only available version is: \"1.0\", which is always set when the authentication record is serialized.\n *\n * @param serializedRecord - Authentication record previously serialized into string.\n * @returns AuthenticationRecord.\n */\nexport function deserializeAuthenticationRecord(serializedRecord: string): AuthenticationRecord {\n const parsed: AuthenticationRecord & { version?: string } = JSON.parse(serializedRecord);\n\n if (parsed.version && parsed.version !== LatestAuthenticationRecordVersion) {\n throw Error(\"Unsupported AuthenticationRecord version\");\n }\n\n return parsed;\n}\n"]}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
import { createClientLogger } from "@azure/logger";
|
|
4
|
-
/**
|
|
5
|
-
* The AzureLogger used for all clients within the identity package
|
|
6
|
-
*/
|
|
7
|
-
export const logger = createClientLogger("identity");
|
|
8
|
-
/**
|
|
9
|
-
* Separates a list of environment variable names into a plain object with two arrays: an array of missing environment variables and another array with assigned environment variables.
|
|
10
|
-
* @param supportedEnvVars - List of environment variable names
|
|
11
|
-
*/
|
|
12
|
-
export function processEnvVars(supportedEnvVars) {
|
|
13
|
-
return supportedEnvVars.reduce((acc, envVariable) => {
|
|
14
|
-
if (process.env[envVariable]) {
|
|
15
|
-
acc.assigned.push(envVariable);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
acc.missing.push(envVariable);
|
|
19
|
-
}
|
|
20
|
-
return acc;
|
|
21
|
-
}, { missing: [], assigned: [] });
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Based on a given list of environment variable names,
|
|
25
|
-
* logs the environment variables currently assigned during the usage of a credential that goes by the given name.
|
|
26
|
-
* @param credentialName - Name of the credential in use
|
|
27
|
-
* @param supportedEnvVars - List of environment variables supported by that credential
|
|
28
|
-
*/
|
|
29
|
-
export function logEnvVars(credentialName, supportedEnvVars) {
|
|
30
|
-
const { assigned } = processEnvVars(supportedEnvVars);
|
|
31
|
-
logger.info(`${credentialName} => Found the following environment variables: ${assigned.join(", ")}`);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Formatting the success event on the credentials
|
|
35
|
-
*/
|
|
36
|
-
export function formatSuccess(scope) {
|
|
37
|
-
return `SUCCESS. Scopes: ${Array.isArray(scope) ? scope.join(", ") : scope}.`;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Formatting the success event on the credentials
|
|
41
|
-
*/
|
|
42
|
-
export function formatError(scope, error) {
|
|
43
|
-
let message = "ERROR.";
|
|
44
|
-
if (scope?.length) {
|
|
45
|
-
message += ` Scopes: ${Array.isArray(scope) ? scope.join(", ") : scope}.`;
|
|
46
|
-
}
|
|
47
|
-
return `${message} Error message: ${typeof error === "string" ? error : error.message}.`;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Generates a CredentialLoggerInstance.
|
|
51
|
-
*
|
|
52
|
-
* It logs with the format:
|
|
53
|
-
*
|
|
54
|
-
* `[title] => [message]`
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
export function credentialLoggerInstance(title, parent, log = logger) {
|
|
58
|
-
const fullTitle = parent ? `${parent.fullTitle} ${title}` : title;
|
|
59
|
-
function info(message) {
|
|
60
|
-
log.info(`${fullTitle} =>`, message);
|
|
61
|
-
}
|
|
62
|
-
function warning(message) {
|
|
63
|
-
log.warning(`${fullTitle} =>`, message);
|
|
64
|
-
}
|
|
65
|
-
function verbose(message) {
|
|
66
|
-
log.verbose(`${fullTitle} =>`, message);
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
title,
|
|
70
|
-
fullTitle,
|
|
71
|
-
info,
|
|
72
|
-
warning,
|
|
73
|
-
verbose,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Generates a CredentialLogger, which is a logger declared at the credential's constructor, and used at any point in the credential.
|
|
78
|
-
* It has all the properties of a CredentialLoggerInstance, plus other logger instances, one per method.
|
|
79
|
-
*
|
|
80
|
-
* It logs with the format:
|
|
81
|
-
*
|
|
82
|
-
* `[title] => [message]`
|
|
83
|
-
* `[title] => getToken() => [message]`
|
|
84
|
-
*
|
|
85
|
-
*/
|
|
86
|
-
export function credentialLogger(title, log = logger) {
|
|
87
|
-
const credLogger = credentialLoggerInstance(title, undefined, log);
|
|
88
|
-
return {
|
|
89
|
-
...credLogger,
|
|
90
|
-
parent: log,
|
|
91
|
-
getToken: credentialLoggerInstance("=> getToken()", credLogger, log),
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=logging.js.map
|
|
@@ -1 +0,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MAAM,EAAE,GAAG;QACX,QAAQ,EAAE,wBAAwB,CAAC,eAAe,EAAE,UAAU,EAAE,GAAG,CAAC;KACrE,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureLogger, createClientLogger } from \"@azure/logger\";\n\n/**\n * The AzureLogger used for all clients within the identity package\n */\nexport const logger = createClientLogger(\"identity\");\n\ninterface EnvironmentAccumulator {\n missing: string[];\n assigned: string[];\n}\n\n/**\n * Separates a list of environment variable names into a plain object with two arrays: an array of missing environment variables and another array with assigned environment variables.\n * @param supportedEnvVars - List of environment variable names\n */\nexport function processEnvVars(supportedEnvVars: string[]): EnvironmentAccumulator {\n return supportedEnvVars.reduce(\n (acc: EnvironmentAccumulator, envVariable: string) => {\n if (process.env[envVariable]) {\n acc.assigned.push(envVariable);\n } else {\n acc.missing.push(envVariable);\n }\n return acc;\n },\n { missing: [], assigned: [] },\n );\n}\n\n/**\n * Based on a given list of environment variable names,\n * logs the environment variables currently assigned during the usage of a credential that goes by the given name.\n * @param credentialName - Name of the credential in use\n * @param supportedEnvVars - List of environment variables supported by that credential\n */\nexport function logEnvVars(credentialName: string, supportedEnvVars: string[]): void {\n const { assigned } = processEnvVars(supportedEnvVars);\n logger.info(\n `${credentialName} => Found the following environment variables: ${assigned.join(\", \")}`,\n );\n}\n\n/**\n * Formatting the success event on the credentials\n */\nexport function formatSuccess(scope: string | string[]): string {\n return `SUCCESS. Scopes: ${Array.isArray(scope) ? scope.join(\", \") : scope}.`;\n}\n\n/**\n * Formatting the success event on the credentials\n */\nexport function formatError(scope: string | string[] | undefined, error: Error | string): string {\n let message = \"ERROR.\";\n if (scope?.length) {\n message += ` Scopes: ${Array.isArray(scope) ? scope.join(\", \") : scope}.`;\n }\n return `${message} Error message: ${typeof error === \"string\" ? error : error.message}.`;\n}\n\n/**\n * A CredentialLoggerInstance is a logger properly formatted to work in a credential's constructor, and its methods.\n */\nexport interface CredentialLoggerInstance {\n title: string;\n fullTitle: string;\n info(message: string): void;\n warning(message: string): void;\n verbose(message: string): void;\n /**\n * The logging functions for warning and error are intentionally left out, since we want the identity logging to be at the info level.\n * Otherwise, they would look like:\n *\n * warning(message: string): void;\n * error(err: Error): void;\n */\n}\n\n/**\n * Generates a CredentialLoggerInstance.\n *\n * It logs with the format:\n *\n * `[title] => [message]`\n *\n */\nexport function credentialLoggerInstance(\n title: string,\n parent?: CredentialLoggerInstance,\n log: AzureLogger = logger,\n): CredentialLoggerInstance {\n const fullTitle = parent ? `${parent.fullTitle} ${title}` : title;\n\n function info(message: string): void {\n log.info(`${fullTitle} =>`, message);\n }\n\n function warning(message: string): void {\n log.warning(`${fullTitle} =>`, message);\n }\n\n function verbose(message: string): void {\n log.verbose(`${fullTitle} =>`, message);\n }\n return {\n title,\n fullTitle,\n info,\n warning,\n verbose,\n };\n}\n\n/**\n * A CredentialLogger is a logger declared at the credential's constructor, and used at any point in the credential.\n * It has all the properties of a CredentialLoggerInstance, plus other logger instances, one per method.\n */\nexport interface CredentialLogger extends CredentialLoggerInstance {\n parent: AzureLogger;\n getToken: CredentialLoggerInstance;\n}\n\n/**\n * Generates a CredentialLogger, which is a logger declared at the credential's constructor, and used at any point in the credential.\n * It has all the properties of a CredentialLoggerInstance, plus other logger instances, one per method.\n *\n * It logs with the format:\n *\n * `[title] => [message]`\n * `[title] => getToken() => [message]`\n *\n */\nexport function credentialLogger(title: string, log: AzureLogger = logger): CredentialLogger {\n const credLogger = credentialLoggerInstance(title, undefined, log);\n return {\n ...credLogger,\n parent: log,\n getToken: credentialLoggerInstance(\"=> getToken()\", credLogger, log),\n };\n}\n"]}
|