@azure/identity 2.1.0-alpha.20220315.2 → 2.1.0-alpha.20220318.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.
Potentially problematic release.
This version of @azure/identity might be problematic. Click here for more details.
- package/CHANGELOG.md +3 -0
- package/dist/index.js +38 -2
- package/dist/index.js.map +1 -1
- package/dist-esm/src/client/identityClient.js +37 -1
- package/dist-esm/src/client/identityClient.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js +1 -1
- package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js.map +1 -1
- package/dist-esm/src/tokenCredentialOptions.js.map +1 -1
- package/package.json +1 -1
- package/types/identity.d.ts +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
### Features Added
|
|
6
6
|
|
|
7
|
+
- All of our credentials now support a new option on their constructor: `loggingOptions`, which allows configuring the logging options of the HTTP pipelines.
|
|
8
|
+
- Within the new `loggingOptions` we have also added `allowLoggingAccountIdentifiers`, a property that if set to true logs information specific to the authenticated account after each successful authentication, including: the Client ID, the Tenant ID, the Object ID of the authenticated user, and if possible the User Principal Name.
|
|
9
|
+
|
|
7
10
|
### Breaking Changes
|
|
8
11
|
|
|
9
12
|
### Bugs Fixed
|
package/dist/index.js
CHANGED
|
@@ -367,7 +367,7 @@ function getIdentityClientAuthorityHost(options) {
|
|
|
367
367
|
*/
|
|
368
368
|
class IdentityClient extends coreClient.ServiceClient {
|
|
369
369
|
constructor(options) {
|
|
370
|
-
var _a;
|
|
370
|
+
var _a, _b;
|
|
371
371
|
const packageDetails = `azsdk-js-identity/2.1.0-beta.2`;
|
|
372
372
|
const userAgentPrefix = ((_a = options === null || options === void 0 ? void 0 : options.userAgentOptions) === null || _a === void 0 ? void 0 : _a.userAgentPrefix)
|
|
373
373
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
@@ -383,6 +383,7 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
383
383
|
}, baseUri }));
|
|
384
384
|
this.authorityHost = baseUri;
|
|
385
385
|
this.abortControllers = new Map();
|
|
386
|
+
this.allowLoggingAccountIdentifiers = (_b = options === null || options === void 0 ? void 0 : options.loggingOptions) === null || _b === void 0 ? void 0 : _b.allowLoggingAccountIdentifiers;
|
|
386
387
|
}
|
|
387
388
|
async sendTokenRequest(request, expiresOnParser) {
|
|
388
389
|
logger$j.info(`IdentityClient: sending token request to [${request.url}]`);
|
|
@@ -397,6 +398,7 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
397
398
|
if (!parsedBody.access_token) {
|
|
398
399
|
return null;
|
|
399
400
|
}
|
|
401
|
+
this.logIdentifiers(response);
|
|
400
402
|
const token = {
|
|
401
403
|
accessToken: {
|
|
402
404
|
token: parsedBody.access_token,
|
|
@@ -518,6 +520,7 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
518
520
|
abortSignal: this.generateAbortSignal(noCorrelationId),
|
|
519
521
|
});
|
|
520
522
|
const response = await this.sendRequest(request);
|
|
523
|
+
this.logIdentifiers(response);
|
|
521
524
|
return {
|
|
522
525
|
body: response.bodyAsText ? JSON.parse(response.bodyAsText) : undefined,
|
|
523
526
|
headers: response.headers.toJSON(),
|
|
@@ -534,12 +537,45 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
534
537
|
abortSignal: this.generateAbortSignal(this.getCorrelationId(options)),
|
|
535
538
|
});
|
|
536
539
|
const response = await this.sendRequest(request);
|
|
540
|
+
this.logIdentifiers(response);
|
|
537
541
|
return {
|
|
538
542
|
body: response.bodyAsText ? JSON.parse(response.bodyAsText) : undefined,
|
|
539
543
|
headers: response.headers.toJSON(),
|
|
540
544
|
status: response.status,
|
|
541
545
|
};
|
|
542
546
|
}
|
|
547
|
+
/**
|
|
548
|
+
* If allowLoggingAccountIdentifiers was set on the constructor options
|
|
549
|
+
* we try to log the account identifiers by parsing the received access token.
|
|
550
|
+
*
|
|
551
|
+
* The account identifiers we try to log are:
|
|
552
|
+
* - `appid`: The application or Client Identifier.
|
|
553
|
+
* - `upn`: User Principal Name.
|
|
554
|
+
* - It might not be available in some authentication scenarios.
|
|
555
|
+
* - If it's not available, we put a placeholder: "No User Principal Name available".
|
|
556
|
+
* - `tid`: Tenant Identifier.
|
|
557
|
+
* - `oid`: Object Identifier of the authenticated user.
|
|
558
|
+
*/
|
|
559
|
+
logIdentifiers(response) {
|
|
560
|
+
if (!this.allowLoggingAccountIdentifiers || !response.bodyAsText) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const unavailableUpn = "No User Principal Name available";
|
|
564
|
+
try {
|
|
565
|
+
const parsed = response.parsedBody || JSON.parse(response.bodyAsText);
|
|
566
|
+
const accessToken = parsed.access_token;
|
|
567
|
+
if (!accessToken) {
|
|
568
|
+
// Without an access token allowLoggingAccountIdentifiers isn't useful.
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
const base64Metadata = accessToken.split(".")[1];
|
|
572
|
+
const { appid, upn, tid, oid } = JSON.parse(Buffer.from(base64Metadata, "base64").toString("utf8"));
|
|
573
|
+
logger$j.info(`[Authenticated account] Client ID: ${appid}. Tenant ID: ${tid}. User Principal Name: ${upn || unavailableUpn}. Object ID (user): ${oid}`);
|
|
574
|
+
}
|
|
575
|
+
catch (e) {
|
|
576
|
+
logger$j.warning("allowLoggingAccountIdentifiers was set, but we couldn't log the account information. Error:", e.message);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
543
579
|
}
|
|
544
580
|
|
|
545
581
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -978,7 +1014,7 @@ class MsalNode extends MsalBaseUtilities {
|
|
|
978
1014
|
const tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
|
|
979
1015
|
this.authorityHost = options.authorityHost || process.env.AZURE_AUTHORITY_HOST;
|
|
980
1016
|
const authority = getAuthority(tenantId, this.authorityHost);
|
|
981
|
-
this.identityClient = new IdentityClient(Object.assign(Object.assign({}, options.tokenCredentialOptions), { authorityHost: authority }));
|
|
1017
|
+
this.identityClient = new IdentityClient(Object.assign(Object.assign({}, options.tokenCredentialOptions), { authorityHost: authority, loggingOptions: options.loggingOptions }));
|
|
982
1018
|
let clientCapabilities = ["cp1"];
|
|
983
1019
|
if (process.env.AZURE_IDENTITY_DISABLE_CP1) {
|
|
984
1020
|
clientCapabilities = [];
|