Skip to content

Commit

Permalink
[Identity] Revert selected credential (#17322)
Browse files Browse the repository at this point in the history
* Revert "[Identity] Exposing the selected credential on ChainedTokenCredential (#16683)"

This reverts commit 535e026.

* changelog update
  • Loading branch information
sadasant authored Aug 31, 2021
1 parent 4a6277f commit 1caf872
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 30 deletions.
4 changes: 4 additions & 0 deletions sdk/identity/identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 0 additions & 1 deletion sdk/identity/identity/review/identity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export type BrowserLoginStyle = "redirect" | "popup";
export class ChainedTokenCredential implements TokenCredential {
constructor(...sources: TokenCredential[]);
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
selectedCredential?: TokenCredential;
protected UnavailableMessage: string;
}

Expand Down
14 changes: 4 additions & 10 deletions sdk/identity/identity/src/credentials/chainedTokenCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -62,14 +57,15 @@ export class ChainedTokenCredential implements TokenCredential {
*/
async getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken> {
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" ||
Expand All @@ -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");
Expand Down
19 changes: 0 additions & 19 deletions sdk/identity/identity/test/public/chainedTokenCredential.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."))),
Expand Down

0 comments on commit 1caf872

Please sign in to comment.