@azure/identity-cache-persistence 1.1.1 → 1.1.2-alpha.20240619.4
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-esm/identity/src/constants.js +1 -1
- package/dist-esm/identity/src/constants.js.map +1 -1
- package/dist-esm/identity/src/credentials/azurePipelinesCredential.js +35 -60
- package/dist-esm/identity/src/credentials/azurePipelinesCredential.js.map +1 -1
- package/dist-esm/identity/src/credentials/interactiveBrowserCredential.js +18 -21
- package/dist-esm/identity/src/credentials/interactiveBrowserCredential.js.map +1 -1
- package/dist-esm/identity/src/credentials/managedIdentityCredential/index.js +3 -288
- package/dist-esm/identity/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/identity/src/credentials/managedIdentityCredential/legacyMsiProvider.js +309 -0
- package/dist-esm/identity/src/credentials/managedIdentityCredential/legacyMsiProvider.js.map +1 -0
- package/dist-esm/identity/src/credentials/onBehalfOfCredential.js +66 -6
- package/dist-esm/identity/src/credentials/onBehalfOfCredential.js.map +1 -1
- package/dist-esm/identity/src/msal/nodeFlows/msalClient.js +135 -24
- package/dist-esm/identity/src/msal/nodeFlows/msalClient.js.map +1 -1
- package/dist-esm/identity/src/msal/nodeFlows/msalPlugins.js.map +1 -1
- package/package.json +3 -3
- package/dist-esm/identity/src/msal/nodeFlows/msalClientCertificate.js +0 -122
- package/dist-esm/identity/src/msal/nodeFlows/msalClientCertificate.js.map +0 -1
- package/dist-esm/identity/src/msal/nodeFlows/msalOnBehalfOf.js +0 -66
- package/dist-esm/identity/src/msal/nodeFlows/msalOnBehalfOf.js.map +0 -1
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
import { __awaiter } from "tslib";
|
|
4
|
-
import { MsalNode } from "./msalNodeCommon";
|
|
5
|
-
import { createHash, createPrivateKey } from "crypto";
|
|
6
|
-
import { formatError } from "../../util/logging";
|
|
7
|
-
import { handleMsalError } from "../utils";
|
|
8
|
-
import { promisify } from "util";
|
|
9
|
-
import { readFile } from "fs";
|
|
10
|
-
const readFileAsync = promisify(readFile);
|
|
11
|
-
/**
|
|
12
|
-
* Tries to asynchronously load a certificate from the given path.
|
|
13
|
-
*
|
|
14
|
-
* @param configuration - Either the PEM value or the path to the certificate.
|
|
15
|
-
* @param sendCertificateChain - Option to include x5c header for SubjectName and Issuer name authorization.
|
|
16
|
-
* @returns - The certificate parts, or `undefined` if the certificate could not be loaded.
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export function parseCertificate(configuration, sendCertificateChain) {
|
|
20
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const certificateParts = {};
|
|
22
|
-
const certificate = configuration
|
|
23
|
-
.certificate;
|
|
24
|
-
const certificatePath = configuration
|
|
25
|
-
.certificatePath;
|
|
26
|
-
certificateParts.certificateContents =
|
|
27
|
-
certificate || (yield readFileAsync(certificatePath, "utf8"));
|
|
28
|
-
if (sendCertificateChain) {
|
|
29
|
-
certificateParts.x5c = certificateParts.certificateContents;
|
|
30
|
-
}
|
|
31
|
-
const certificatePattern = /(-+BEGIN CERTIFICATE-+)(\n\r?|\r\n?)([A-Za-z0-9+/\n\r]+=*)(\n\r?|\r\n?)(-+END CERTIFICATE-+)/g;
|
|
32
|
-
const publicKeys = [];
|
|
33
|
-
// Match all possible certificates, in the order they are in the file. These will form the chain that is used for x5c
|
|
34
|
-
let match;
|
|
35
|
-
do {
|
|
36
|
-
match = certificatePattern.exec(certificateParts.certificateContents);
|
|
37
|
-
if (match) {
|
|
38
|
-
publicKeys.push(match[3]);
|
|
39
|
-
}
|
|
40
|
-
} while (match);
|
|
41
|
-
if (publicKeys.length === 0) {
|
|
42
|
-
throw new Error("The file at the specified path does not contain a PEM-encoded certificate.");
|
|
43
|
-
}
|
|
44
|
-
certificateParts.thumbprint = createHash("sha1")
|
|
45
|
-
.update(Buffer.from(publicKeys[0], "base64"))
|
|
46
|
-
.digest("hex")
|
|
47
|
-
.toUpperCase();
|
|
48
|
-
return certificateParts;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* MSAL client certificate client. Calls to MSAL's confidential application's `acquireTokenByClientCredential` during `doGetToken`.
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
export class MsalClientCertificate extends MsalNode {
|
|
56
|
-
constructor(options) {
|
|
57
|
-
super(options);
|
|
58
|
-
this.requiresConfidential = true;
|
|
59
|
-
this.configuration = options.configuration;
|
|
60
|
-
this.sendCertificateChain = options.sendCertificateChain;
|
|
61
|
-
}
|
|
62
|
-
// Changing the MSAL configuration asynchronously
|
|
63
|
-
init(options) {
|
|
64
|
-
const _super = Object.create(null, {
|
|
65
|
-
init: { get: () => super.init }
|
|
66
|
-
});
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
try {
|
|
69
|
-
const parts = yield parseCertificate(this.configuration, this.sendCertificateChain);
|
|
70
|
-
let privateKey;
|
|
71
|
-
if (this.configuration.certificatePassword !== undefined) {
|
|
72
|
-
const privateKeyObject = createPrivateKey({
|
|
73
|
-
key: parts.certificateContents,
|
|
74
|
-
passphrase: this.configuration.certificatePassword,
|
|
75
|
-
format: "pem",
|
|
76
|
-
});
|
|
77
|
-
privateKey = privateKeyObject
|
|
78
|
-
.export({
|
|
79
|
-
format: "pem",
|
|
80
|
-
type: "pkcs8",
|
|
81
|
-
})
|
|
82
|
-
.toString();
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
privateKey = parts.certificateContents;
|
|
86
|
-
}
|
|
87
|
-
this.msalConfig.auth.clientCertificate = {
|
|
88
|
-
thumbprint: parts.thumbprint,
|
|
89
|
-
privateKey: privateKey,
|
|
90
|
-
x5c: parts.x5c,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
this.logger.info(formatError("", error));
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
return _super.init.call(this, options);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
doGetToken(scopes_1) {
|
|
101
|
-
return __awaiter(this, arguments, void 0, function* (scopes, options = {}) {
|
|
102
|
-
try {
|
|
103
|
-
const clientCredReq = {
|
|
104
|
-
scopes,
|
|
105
|
-
correlationId: options.correlationId,
|
|
106
|
-
azureRegion: this.azureRegion,
|
|
107
|
-
authority: options.authority,
|
|
108
|
-
claims: options.claims,
|
|
109
|
-
};
|
|
110
|
-
const result = yield this.getApp("confidential", options.enableCae).acquireTokenByClientCredential(clientCredReq);
|
|
111
|
-
// Even though we're providing the same default in memory persistence cache that we use for DeviceCodeCredential,
|
|
112
|
-
// The Client Credential flow does not return the account information from the authentication service,
|
|
113
|
-
// so each time getToken gets called, we will have to acquire a new token through the service.
|
|
114
|
-
return this.handleResult(scopes, result || undefined);
|
|
115
|
-
}
|
|
116
|
-
catch (err) {
|
|
117
|
-
throw handleMsalError(scopes, err, options);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
//# sourceMappingURL=msalClientCertificate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"msalClientCertificate.js","sourceRoot":"","sources":["../../../../../../identity/src/msal/nodeFlows/msalClientCertificate.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAOlC,OAAO,EAAE,QAAQ,EAAmB,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAKtD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAE9B,MAAM,aAAa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,CAAC;YACD,OAAO,OAAM,IAAI,YAAC,OAAO,EAAE;QAC7B,CAAC;KAAA;IAEe,UAAU;6DACxB,MAAgB,EAChB,UAAyC,EAAE;YAE3C,IAAI,CAAC;gBACH,MAAM,aAAa,GAA4B;oBAC7C,MAAM;oBACN,aAAa,EAAE,OAAO,CAAC,aAAa;oBACpC,WAAW,EAAE,IAAI,CAAC,WAAW;oBAC7B,SAAS,EAAE,OAAO,CAAC,SAAS;oBAC5B,MAAM,EAAE,OAAO,CAAC,MAAM;iBACvB,CAAC;gBACF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAC9B,cAAc,EACd,OAAO,CAAC,SAAS,CAClB,CAAC,8BAA8B,CAAC,aAAa,CAAC,CAAC;gBAChD,iHAAiH;gBACjH,sGAAsG;gBACtG,8FAA8F;gBAC9F,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,IAAI,SAAS,CAAC,CAAC;YACxD,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,MAAM,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;KAAA;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n ClientCertificateCredentialPEMConfiguration,\n ClientCertificatePEMCertificate,\n ClientCertificatePEMCertificatePath,\n} from \"../../credentials/clientCertificateCredential\";\nimport { MsalNode, MsalNodeOptions } from \"./msalNodeCommon\";\nimport { createHash, createPrivateKey } from \"crypto\";\n\nimport { AccessToken } from \"@azure/core-auth\";\nimport { ClientCredentialRequest } from \"@azure/msal-node\";\nimport { CredentialFlowGetTokenOptions } from \"../credentials\";\nimport { formatError } from \"../../util/logging\";\nimport { handleMsalError } from \"../utils\";\nimport { promisify } from \"util\";\nimport { readFile } from \"fs\";\n\nconst readFileAsync = promisify(readFile);\n\n/**\n * Options that can be passed to configure MSAL to handle client certificates.\n * @internal\n */\nexport interface MsalClientCertificateOptions extends MsalNodeOptions {\n /**\n * Location of the PEM certificate.\n */\n configuration: ClientCertificateCredentialPEMConfiguration;\n /**\n * Option to include x5c header for SubjectName and Issuer name authorization.\n * Set this option to send base64 encoded public certificate in the client assertion header as an x5c claim\n */\n sendCertificateChain?: boolean;\n}\n\n/**\n * Parts of a certificate, as understood by MSAL.\n * @internal\n */\ninterface CertificateParts {\n /**\n * Hex encoded X.509 SHA-1 thumbprint of the certificate\n */\n thumbprint: string;\n /**\n * The PEM encoded private key (string should contain -----BEGIN PRIVATE KEY----- ... -----END PRIVATE KEY-----\n */\n certificateContents: string;\n /**\n * x5c header.\n */\n x5c: string;\n}\n\n/**\n * Tries to asynchronously load a certificate from the given path.\n *\n * @param configuration - Either the PEM value or the path to the certificate.\n * @param sendCertificateChain - Option to include x5c header for SubjectName and Issuer name authorization.\n * @returns - The certificate parts, or `undefined` if the certificate could not be loaded.\n * @internal\n */\nexport async function parseCertificate(\n configuration: ClientCertificateCredentialPEMConfiguration,\n sendCertificateChain?: boolean,\n): Promise<CertificateParts> {\n const certificateParts: Partial<CertificateParts> = {};\n\n const certificate: string | undefined = (configuration as ClientCertificatePEMCertificate)\n .certificate;\n const certificatePath: string | undefined = (configuration as ClientCertificatePEMCertificatePath)\n .certificatePath;\n certificateParts.certificateContents =\n certificate || (await readFileAsync(certificatePath!, \"utf8\"));\n if (sendCertificateChain) {\n certificateParts.x5c = certificateParts.certificateContents;\n }\n\n const certificatePattern =\n /(-+BEGIN CERTIFICATE-+)(\\n\\r?|\\r\\n?)([A-Za-z0-9+/\\n\\r]+=*)(\\n\\r?|\\r\\n?)(-+END CERTIFICATE-+)/g;\n const publicKeys: string[] = [];\n\n // Match all possible certificates, in the order they are in the file. These will form the chain that is used for x5c\n let match;\n do {\n match = certificatePattern.exec(certificateParts.certificateContents);\n if (match) {\n publicKeys.push(match[3]);\n }\n } while (match);\n\n if (publicKeys.length === 0) {\n throw new Error(\"The file at the specified path does not contain a PEM-encoded certificate.\");\n }\n\n certificateParts.thumbprint = createHash(\"sha1\")\n .update(Buffer.from(publicKeys[0], \"base64\"))\n .digest(\"hex\")\n .toUpperCase();\n\n return certificateParts as CertificateParts;\n}\n\n/**\n * MSAL client certificate client. Calls to MSAL's confidential application's `acquireTokenByClientCredential` during `doGetToken`.\n * @internal\n */\nexport class MsalClientCertificate extends MsalNode {\n private configuration: ClientCertificateCredentialPEMConfiguration;\n private sendCertificateChain?: boolean;\n\n constructor(options: MsalClientCertificateOptions) {\n super(options);\n this.requiresConfidential = true;\n this.configuration = options.configuration;\n this.sendCertificateChain = options.sendCertificateChain;\n }\n\n // Changing the MSAL configuration asynchronously\n async init(options?: CredentialFlowGetTokenOptions): Promise<void> {\n try {\n const parts = await parseCertificate(this.configuration, this.sendCertificateChain);\n\n let privateKey: string | undefined;\n if (this.configuration.certificatePassword !== undefined) {\n const privateKeyObject = createPrivateKey({\n key: parts.certificateContents,\n passphrase: this.configuration.certificatePassword,\n format: \"pem\",\n });\n\n privateKey = privateKeyObject\n .export({\n format: \"pem\",\n type: \"pkcs8\",\n })\n .toString();\n } else {\n privateKey = parts.certificateContents;\n }\n\n this.msalConfig.auth.clientCertificate = {\n thumbprint: parts.thumbprint,\n privateKey: privateKey,\n x5c: parts.x5c,\n };\n } catch (error: any) {\n this.logger.info(formatError(\"\", error));\n throw error;\n }\n return super.init(options);\n }\n\n protected async doGetToken(\n scopes: string[],\n options: CredentialFlowGetTokenOptions = {},\n ): Promise<AccessToken> {\n try {\n const clientCredReq: ClientCredentialRequest = {\n scopes,\n correlationId: options.correlationId,\n azureRegion: this.azureRegion,\n authority: options.authority,\n claims: options.claims,\n };\n const result = await this.getApp(\n \"confidential\",\n options.enableCae,\n ).acquireTokenByClientCredential(clientCredReq);\n // Even though we're providing the same default in memory persistence cache that we use for DeviceCodeCredential,\n // The Client Credential flow does not return the account information from the authentication service,\n // so each time getToken gets called, we will have to acquire a new token through the service.\n return this.handleResult(scopes, result || undefined);\n } catch (err: any) {\n throw handleMsalError(scopes, err, options);\n }\n }\n}\n"]}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
import { __awaiter } from "tslib";
|
|
4
|
-
import { MsalNode } from "./msalNodeCommon";
|
|
5
|
-
import { formatError } from "../../util/logging";
|
|
6
|
-
import { handleMsalError } from "../utils";
|
|
7
|
-
import { parseCertificate } from "./msalClientCertificate";
|
|
8
|
-
/**
|
|
9
|
-
* MSAL on behalf of flow. Calls to MSAL's confidential application's `acquireTokenOnBehalfOf` during `doGetToken`.
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export class MsalOnBehalfOf extends MsalNode {
|
|
13
|
-
constructor(options) {
|
|
14
|
-
super(options);
|
|
15
|
-
this.logger.info("Initialized MSAL's On-Behalf-Of flow");
|
|
16
|
-
this.requiresConfidential = true;
|
|
17
|
-
this.userAssertionToken = options.userAssertionToken;
|
|
18
|
-
this.certificatePath = options.certificatePath;
|
|
19
|
-
this.sendCertificateChain = options.sendCertificateChain;
|
|
20
|
-
this.clientSecret = options.clientSecret;
|
|
21
|
-
}
|
|
22
|
-
// Changing the MSAL configuration asynchronously
|
|
23
|
-
init(options) {
|
|
24
|
-
const _super = Object.create(null, {
|
|
25
|
-
init: { get: () => super.init }
|
|
26
|
-
});
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
if (this.certificatePath) {
|
|
29
|
-
try {
|
|
30
|
-
const parts = yield parseCertificate({ certificatePath: this.certificatePath }, this.sendCertificateChain);
|
|
31
|
-
this.msalConfig.auth.clientCertificate = {
|
|
32
|
-
thumbprint: parts.thumbprint,
|
|
33
|
-
privateKey: parts.certificateContents,
|
|
34
|
-
x5c: parts.x5c,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
this.logger.info(formatError("", error));
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.msalConfig.auth.clientSecret = this.clientSecret;
|
|
44
|
-
}
|
|
45
|
-
return _super.init.call(this, options);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
doGetToken(scopes_1) {
|
|
49
|
-
return __awaiter(this, arguments, void 0, function* (scopes, options = {}) {
|
|
50
|
-
try {
|
|
51
|
-
const result = yield this.getApp("confidential", options.enableCae).acquireTokenOnBehalfOf({
|
|
52
|
-
scopes,
|
|
53
|
-
correlationId: options.correlationId,
|
|
54
|
-
authority: options.authority,
|
|
55
|
-
claims: options.claims,
|
|
56
|
-
oboAssertion: this.userAssertionToken,
|
|
57
|
-
});
|
|
58
|
-
return this.handleResult(scopes, result || undefined);
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
throw handleMsalError(scopes, err, options);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=msalOnBehalfOf.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"msalOnBehalfOf.js","sourceRoot":"","sources":["../../../../../../identity/src/msal/nodeFlows/msalOnBehalfOf.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,EAAE,QAAQ,EAAmB,MAAM,kBAAkB,CAAC;AAI7D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AA0B3D;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,QAAQ;IAM1C,YAAY,OAA8B;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACzD,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;QACjC,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AAS,EAAE,OAAO,CAAC,SAAS;oBAC5B,MAAM,EAAE,OAAO,CAAC,MAAM;oBACtB,YAAY,EAAE,IAAI,CAAC,kBAAkB;iBACtC,CAAC,CAAC;gBACH,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,IAAI,SAAS,CAAC,CAAC;YACxD,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,MAAM,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;KAAA;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { MsalNode, MsalNodeOptions } from \"./msalNodeCommon\";\n\nimport { AccessToken } from \"@azure/core-auth\";\nimport { CredentialFlowGetTokenOptions } from \"../credentials\";\nimport { formatError } from \"../../util/logging\";\nimport { handleMsalError } from \"../utils\";\nimport { parseCertificate } from \"./msalClientCertificate\";\n\n/**\n * Options that can be passed to configure MSAL to handle On-Behalf-Of authentication requests.\n * @internal\n */\nexport interface MsalOnBehalfOfOptions extends MsalNodeOptions {\n /**\n * A client secret that was generated for the App Registration.\n */\n clientSecret?: string;\n /**\n * Location of the PEM certificate.\n */\n certificatePath?: string;\n /**\n * Option to include x5c header for SubjectName and Issuer name authorization.\n * Set this option to send base64 encoded public certificate in the client assertion header as an x5c claim\n */\n sendCertificateChain?: boolean;\n /**\n * The user assertion for the On-Behalf-Of flow.\n */\n userAssertionToken: string;\n}\n\n/**\n * MSAL on behalf of flow. Calls to MSAL's confidential application's `acquireTokenOnBehalfOf` during `doGetToken`.\n * @internal\n */\nexport class MsalOnBehalfOf extends MsalNode {\n private userAssertionToken: string;\n private certificatePath?: string;\n private sendCertificateChain?: boolean;\n private clientSecret?: string;\n\n constructor(options: MsalOnBehalfOfOptions) {\n super(options);\n this.logger.info(\"Initialized MSAL's On-Behalf-Of flow\");\n this.requiresConfidential = true;\n this.userAssertionToken = options.userAssertionToken;\n this.certificatePath = options.certificatePath;\n this.sendCertificateChain = options.sendCertificateChain;\n this.clientSecret = options.clientSecret;\n }\n\n // Changing the MSAL configuration asynchronously\n async init(options?: CredentialFlowGetTokenOptions): Promise<void> {\n if (this.certificatePath) {\n try {\n const parts = await parseCertificate(\n { certificatePath: this.certificatePath },\n this.sendCertificateChain,\n );\n this.msalConfig.auth.clientCertificate = {\n thumbprint: parts.thumbprint,\n privateKey: parts.certificateContents,\n x5c: parts.x5c,\n };\n } catch (error: any) {\n this.logger.info(formatError(\"\", error));\n throw error;\n }\n } else {\n this.msalConfig.auth.clientSecret = this.clientSecret;\n }\n return super.init(options);\n }\n\n protected async doGetToken(\n scopes: string[],\n options: CredentialFlowGetTokenOptions = {},\n ): Promise<AccessToken> {\n try {\n const result = await this.getApp(\"confidential\", options.enableCae).acquireTokenOnBehalfOf({\n scopes,\n correlationId: options.correlationId,\n authority: options.authority,\n claims: options.claims,\n oboAssertion: this.userAssertionToken,\n });\n return this.handleResult(scopes, result || undefined);\n } catch (err: any) {\n throw handleMsalError(scopes, err, options);\n }\n }\n}\n"]}
|