From 1caf872697e6b6fb84da22a99b8d6433a144057a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez?= Date: Tue, 31 Aug 2021 15:04:59 -0400 Subject: [PATCH] [Identity] Revert selected credential (#17322) * Revert "[Identity] Exposing the selected credential on ChainedTokenCredential (#16683)" This reverts commit 535e026e7aa605b1a76f2c10c9de89518d0a021e. * changelog update --- sdk/identity/identity/CHANGELOG.md | 4 ++++ sdk/identity/identity/review/identity.api.md | 1 - .../src/credentials/chainedTokenCredential.ts | 14 ++++---------- .../public/chainedTokenCredential.spec.ts | 19 ------------------- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/sdk/identity/identity/CHANGELOG.md b/sdk/identity/identity/CHANGELOG.md index a45f25df2919..59627d7c6616 100644 --- a/sdk/identity/identity/CHANGELOG.md +++ b/sdk/identity/identity/CHANGELOG.md @@ -6,6 +6,10 @@ ### Breaking Changes +#### Breaking Changes from 2.0.0-beta.5 + +- The property named `selectedCredential` that was added to `ChainedTokenCredential` and `DefaultAzureCredential` has been removed, since customers reported that logging was enough. + ### Bugs Fixed - `ClientSecretCredential`, `ClientCertificateCredential` and `UsernamePasswordCredential` now throw if the required parameters are not provided (even in JavaScript). diff --git a/sdk/identity/identity/review/identity.api.md b/sdk/identity/identity/review/identity.api.md index c4462db4fa91..46e790880c93 100644 --- a/sdk/identity/identity/review/identity.api.md +++ b/sdk/identity/identity/review/identity.api.md @@ -103,7 +103,6 @@ export type BrowserLoginStyle = "redirect" | "popup"; export class ChainedTokenCredential implements TokenCredential { constructor(...sources: TokenCredential[]); getToken(scopes: string | string[], options?: GetTokenOptions): Promise; - selectedCredential?: TokenCredential; protected UnavailableMessage: string; } diff --git a/sdk/identity/identity/src/credentials/chainedTokenCredential.ts b/sdk/identity/identity/src/credentials/chainedTokenCredential.ts index af24c6912a70..d8ca5388ed23 100644 --- a/sdk/identity/identity/src/credentials/chainedTokenCredential.ts +++ b/sdk/identity/identity/src/credentials/chainedTokenCredential.ts @@ -26,11 +26,6 @@ export class ChainedTokenCredential implements TokenCredential { private _sources: TokenCredential[] = []; - /** - * The selected credential, in case users want to read it or use it directly. - */ - public selectedCredential?: TokenCredential; - /** * Creates an instance of ChainedTokenCredential using the given credentials. * @@ -62,14 +57,15 @@ export class ChainedTokenCredential implements TokenCredential { */ async getToken(scopes: string | string[], options?: GetTokenOptions): Promise { let token = null; - const errors: Error[] = []; + let successfulCredentialName = ""; + const errors = []; const { span, updatedOptions } = createSpan("ChainedTokenCredential-getToken", options); for (let i = 0; i < this._sources.length && token === null; i++) { try { token = await this._sources[i].getToken(scopes, updatedOptions); - this.selectedCredential = this._sources[i]; + successfulCredentialName = this._sources[i].constructor.name; } catch (err) { if ( err.name === "CredentialUnavailableError" || @@ -95,9 +91,7 @@ export class ChainedTokenCredential implements TokenCredential { span.end(); - logger.getToken.info( - `Result for ${this.selectedCredential!.constructor.name}: ${formatSuccess(scopes)}` - ); + logger.getToken.info(`Result for ${successfulCredentialName}: ${formatSuccess(scopes)}`); if (token === null) { throw new CredentialUnavailableError("Failed to retrieve a valid token"); diff --git a/sdk/identity/identity/test/public/chainedTokenCredential.spec.ts b/sdk/identity/identity/test/public/chainedTokenCredential.spec.ts index f800de900fd0..7ff86ec114ba 100644 --- a/sdk/identity/identity/test/public/chainedTokenCredential.spec.ts +++ b/sdk/identity/identity/test/public/chainedTokenCredential.spec.ts @@ -39,25 +39,6 @@ describe("ChainedTokenCredential", function() { assert.strictEqual(accessToken && accessToken.token, "firstToken"); }); - it("sets the successful credential on the selectedCredential property", async () => { - class ExpectedCredential implements TokenCredential { - async getToken() { - return { token: "firstToken", expiresOnTimestamp: 0 }; - } - } - const chainedTokenCredential = new ChainedTokenCredential( - mockCredential(Promise.reject(new CredentialUnavailableError("unavailable."))), - new ExpectedCredential(), - mockCredential(Promise.resolve({ token: "secondToken", expiresOnTimestamp: 0 })) - ); - const accessToken = await chainedTokenCredential.getToken("scope"); - assert.strictEqual(accessToken && accessToken.token, "firstToken"); - assert.strictEqual( - chainedTokenCredential.selectedCredential!.constructor.name, - "ExpectedCredential" - ); - }); - it("returns an AggregateAuthenticationError when no token is returned and one credential returned an error", async () => { const chainedTokenCredential = new ChainedTokenCredential( mockCredential(Promise.reject(new CredentialUnavailableError("unavailable."))),