Skip to content

Commit

Permalink
[Identity] Following up on reference renames from ApplicationCredenti…
Browse files Browse the repository at this point in the history
…al to AzureApplicationCredential (#18110)

Continuing from: #18072

I merged that one by mistake. I took a walk and after I came back I was too excited to see it approved, I got too close of the merge button and then I realized my mistake.

Here’s the follow-up.
  • Loading branch information
sadasant authored Oct 11, 2021
1 parent 0d68696 commit 34d6c1d
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion sdk/identity/identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function main() {
Identity v2 includes three new credential types:

- `AzurePowerShellCredential`, which re-uses any account previously authenticated with the `Az.Account` PowerShell module.
- `ApplicationCredential`, which is a simplified `DefaultAzureCredential` that only includes `EnvironmentCredential` and `ManagedIdentityCredential`.
- `AzureApplicationCredential`, which is a simplified `DefaultAzureCredential` that only includes `EnvironmentCredential` and `ManagedIdentityCredential`.
- `OnBehalfOfCredential`, which enables the [On-Behalf-Of authentication flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow).

#### New features in all credentials
Expand Down
20 changes: 10 additions & 10 deletions sdk/identity/identity/review/identity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ export class AggregateAuthenticationError extends Error {
// @public
export const AggregateAuthenticationErrorName = "AggregateAuthenticationError";

// @public
export class ApplicationCredential extends ChainedTokenCredential {
constructor(options?: ApplicationCredentialOptions);
}

// @public
export interface ApplicationCredentialOptions extends TokenCredentialOptions, CredentialPersistenceOptions {
managedIdentityClientId?: string;
}

// @public
export class AuthenticationError extends Error {
constructor(statusCode: number, errorBody: object | string | undefined | null);
Expand Down Expand Up @@ -66,6 +56,16 @@ export class AuthorizationCodeCredential implements TokenCredential {
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
}

// @public
export class AzureApplicationCredential extends ChainedTokenCredential {
constructor(options?: AzureApplicationCredentialOptions);
}

// @public
export interface AzureApplicationCredentialOptions extends TokenCredentialOptions, CredentialPersistenceOptions {
managedIdentityClientId?: string;
}

// @public
export enum AzureAuthorityHosts {
AzureChina = "https://login.chinacloudapi.cn",
Expand Down
4 changes: 2 additions & 2 deletions sdk/identity/identity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export { AuthorizationCodeCredential } from "./credentials/authorizationCodeCred
export { AzurePowerShellCredential } from "./credentials/azurePowerShellCredential";
export { AzurePowerShellCredentialOptions } from "./credentials/azurePowerShellCredentialOptions";
export {
AzureApplicationCredential as ApplicationCredential,
AzureApplicationCredentialOptions as ApplicationCredentialOptions
AzureApplicationCredential,
AzureApplicationCredentialOptions
} from "./credentials/azureApplicationCredential";

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import { assert } from "chai";
import { RestError } from "@azure/core-rest-pipeline";
import { ApplicationCredential } from "../../../src";
import { AzureApplicationCredential } from "../../../src";
import { prepareIdentityTests } from "../../httpRequests";
import {
createResponse,
IdentityTestContext,
SendCredentialRequests
} from "../../httpRequestsCommon";

describe("ApplicationCredential testing Managed Identity (internal)", function() {
describe("AzureApplicationCredential testing Managed Identity (internal)", function() {
let envCopy: string = "";
let testContext: IdentityTestContext;
let sendCredentialRequests: SendCredentialRequests;
Expand Down Expand Up @@ -39,7 +39,7 @@ describe("ApplicationCredential testing Managed Identity (internal)", function()

const { error } = await sendCredentialRequests({
scopes: ["scopes"],
credential: new ApplicationCredential(),
credential: new AzureApplicationCredential(),
insecureResponses: [
{
error: new RestError("Request Timeout", { code: "REQUEST_SEND_ERROR", statusCode: 408 })
Expand All @@ -59,7 +59,7 @@ describe("ApplicationCredential testing Managed Identity (internal)", function()

const { error } = await sendCredentialRequests({
scopes: ["scopes"],
credential: new ApplicationCredential(),
credential: new AzureApplicationCredential(),
insecureResponses: [
createResponse(200), // IMDS Endpoint ping
{ error: new RestError(errorMessage, { statusCode: 500 }) }
Expand All @@ -78,7 +78,7 @@ describe("ApplicationCredential testing Managed Identity (internal)", function()

const { error } = await sendCredentialRequests({
scopes: ["scopes"],
credential: new ApplicationCredential(),
credential: new AzureApplicationCredential(),
insecureResponses: [
createResponse(200), // IMDS Endpoint ping
{ error: netError }
Expand All @@ -95,7 +95,7 @@ describe("ApplicationCredential testing Managed Identity (internal)", function()

const authDetails = await sendCredentialRequests({
scopes: ["https://service/.default"],
credential: new ApplicationCredential(),
credential: new AzureApplicationCredential(),
secureResponses: [
createResponse(200, {
access_token: "token",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Licensed under the MIT license.

import { assert } from "chai";
import { ApplicationCredential } from "../../../src";
import { AzureApplicationCredential } from "../../../src";
import { MsalTestCleanup, msalNodeTestSetup, testTracing } from "../../msalTestUtils";
import { getError } from "../../authTestUtils";
import { Context } from "mocha";

describe("ApplicationCredential", function() {
describe("AzureApplicationCredential", function() {
let cleanup: MsalTestCleanup;
const environmentVariableNames = ["AZURE_TENANT_ID", "AZURE_CLIENT_ID", "AZURE_CLIENT_SECRET"];
const cachedValues: Record<string, string | undefined> = {};
Expand Down Expand Up @@ -36,7 +36,7 @@ describe("ApplicationCredential", function() {
process.env.AZURE_CLIENT_ID = cachedValues.AZURE_CLIENT_ID;
process.env.AZURE_CLIENT_SECRET = cachedValues.AZURE_CLIENT_SECRET;

const credential = new ApplicationCredential();
const credential = new AzureApplicationCredential();

const token = await credential.getToken(scope);
assert.ok(token?.token);
Expand All @@ -53,7 +53,7 @@ describe("ApplicationCredential", function() {
process.env.AZURE_CLIENT_ID = cachedValues.AZURE_CLIENT_ID;
process.env.AZURE_CLIENT_SECRET = cachedValues.AZURE_CLIENT_SECRET;

const credential = new ApplicationCredential();
const credential = new AzureApplicationCredential();

await credential.getToken(scope, {
tracingOptions
Expand All @@ -79,19 +79,19 @@ describe("ApplicationCredential", function() {
);

it("throws an AggregateAuthenticationError when getToken is called and no credential was configured", async () => {
const credential = new ApplicationCredential();
const credential = new AzureApplicationCredential();
const error = await getError(credential.getToken(scope));
assert.equal(error.name, "AggregateAuthenticationError");
assert.ok(error.message.indexOf(`CredentialUnavailableError: EnvironmentCredential`) > -1);
assert.ok(error.message.indexOf(`CredentialUnavailableError: ManagedIdentityCredential`) > -1);
});

it("throws an AuthenticationError when getToken is called and ApplicationCredential authentication failed", async () => {
it("throws an AuthenticationError when getToken is called and AzureApplicationCredential authentication failed", async () => {
process.env.AZURE_TENANT_ID = "tenant";
process.env.AZURE_CLIENT_ID = "client";
process.env.AZURE_CLIENT_SECRET = "secret";

const credential = new ApplicationCredential();
const credential = new AzureApplicationCredential();

const error = await getError(credential.getToken(scope));
assert.equal(error.name, "AuthenticationError");
Expand Down

0 comments on commit 34d6c1d

Please sign in to comment.