Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Identity] Following up on reference renames from ApplicationCredential to AzureApplicationCredential #18110

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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