@azure/identity 2.1.0-alpha.20220311.2 → 2.1.0-alpha.20220321.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 CHANGED
@@ -4,6 +4,10 @@
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
+ - Added `disableAuthorityValidation`, which allows passing any `authorityHost` regardless of whether it can be validated or not. This is specially useful in private clouds.
10
+
7
11
  ### Breaking Changes
8
12
 
9
13
  ### Bugs Fixed
package/README.md CHANGED
@@ -88,9 +88,9 @@ If interactive authentication cannot be supported in the session, then the `-Use
88
88
 
89
89
  #### Authenticate via Visual Studio Code
90
90
 
91
- Developers using Visual Studio Code can use the [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account) to authenticate via the IDE. Apps using `DefaultAzureCredential` or `VisualStudioCodeCredential` can then use this account to authenticate calls in their app when running locally.
91
+ Developers using Visual Studio Code can use the [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account) to authenticate via the editor. Apps using `DefaultAzureCredential` or `VisualStudioCodeCredential` can then use this account to authenticate calls in their app when running locally.
92
92
 
93
- To authenticate in Visual Studio Code, first ensure the Azure Account extension is installed. Once the extension is installed, open the **Command Palette** and run the **Azure: Sign In** command.
93
+ To authenticate in Visual Studio Code, ensure **version 0.9.11 or earlier** of the Azure Account extension is installed. Once installed, open the **Command Palette** and run the **Azure: Sign In** command.
94
94
 
95
95
  Additionally, use the [`@azure/identity-vscode`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity-vscode) plugin package. This package provides the dependencies of `VisualStudioCodeCredential` and enables it. See [Plugins](##plugins).
96
96
 
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.
@@ -615,12 +651,16 @@ function getAuthority(tenantId, host) {
615
651
  }
616
652
  /**
617
653
  * Generates the known authorities.
654
+ * If `disableAuthorityValidation` is passed, it returns the authority host as a known host, thus disabling the authority validation.
618
655
  * If the Tenant Id is `adfs`, the authority can't be validated since the format won't match the expected one.
619
656
  * For that reason, we have to force MSAL to disable validating the authority
620
657
  * by sending it within the known authorities in the MSAL configuration.
621
658
  * @internal
622
659
  */
623
- function getKnownAuthorities(tenantId, authorityHost) {
660
+ function getKnownAuthorities(tenantId, authorityHost, disableAuthorityValidation) {
661
+ if (disableAuthorityValidation) {
662
+ return [authorityHost];
663
+ }
624
664
  if (tenantId === "adfs" && authorityHost) {
625
665
  return [authorityHost];
626
666
  }
@@ -978,17 +1018,17 @@ class MsalNode extends MsalBaseUtilities {
978
1018
  const tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
979
1019
  this.authorityHost = options.authorityHost || process.env.AZURE_AUTHORITY_HOST;
980
1020
  const authority = getAuthority(tenantId, this.authorityHost);
981
- this.identityClient = new IdentityClient(Object.assign(Object.assign({}, options.tokenCredentialOptions), { authorityHost: authority }));
1021
+ this.identityClient = new IdentityClient(Object.assign(Object.assign({}, options.tokenCredentialOptions), { authorityHost: authority, loggingOptions: options.loggingOptions }));
982
1022
  let clientCapabilities = ["cp1"];
983
1023
  if (process.env.AZURE_IDENTITY_DISABLE_CP1) {
984
1024
  clientCapabilities = [];
985
1025
  }
986
- return {
1026
+ const configuration = {
987
1027
  auth: {
988
1028
  clientId,
989
1029
  authority,
990
- knownAuthorities: getKnownAuthorities(tenantId, authority),
991
1030
  clientCapabilities,
1031
+ knownAuthorities: getKnownAuthorities(tenantId, authority, options.disableAuthorityValidation),
992
1032
  },
993
1033
  // Cache is defined in this.prepare();
994
1034
  system: {
@@ -998,6 +1038,7 @@ class MsalNode extends MsalBaseUtilities {
998
1038
  },
999
1039
  },
1000
1040
  };
1041
+ return configuration;
1001
1042
  }
1002
1043
  /**
1003
1044
  * Prepares the MSAL applications.