Skip to content

Commit

Permalink
[identity] Remove MSAL-Common
Browse files Browse the repository at this point in the history
  • Loading branch information
mpodwysocki committed Nov 10, 2023
1 parent b771818 commit a7c7378
Show file tree
Hide file tree
Showing 13 changed files with 342 additions and 69 deletions.
10 changes: 3 additions & 7 deletions sdk/identity/identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"./dist-esm/src/credentials/azureApplicationCredential.js": "./dist-esm/src/credentials/azureApplicationCredential.browser.js",
"./dist-esm/src/credentials/onBehalfOfCredential.js": "./dist-esm/src/credentials/onBehalfOfCredential.browser.js",
"./dist-esm/src/credentials/workloadIdentityCredential.js": "./dist-esm/src/credentials/workloadIdentityCredential.browser.js",
"./dist-esm/src/msal/utils.js": "./dist-esm/src/msal/utils.browser.js",
"./dist-esm/src/util/authHostEnv.js": "./dist-esm/src/util/authHostEnv.browser.js",
"./dist-esm/src/util/processMultiTenantRequest.js": "./dist-esm/src/util/processMultiTenantRequest.browser.js",
"./dist-esm/src/tokenCache/TokenCachePersistence.js": "./dist-esm/src/tokenCache/TokenCachePersistence.browser.js",
Expand Down Expand Up @@ -113,14 +114,12 @@
"@azure/core-util": "^1.6.1",
"@azure/logger": "^1.0.0",
"@azure/msal-browser": "^3.5.0",
"@azure/msal-common": "^13.1.0",
"@azure/msal-node": "^2.5.1",
"events": "^3.0.0",
"jws": "^4.0.0",
"open": "^8.0.0",
"stoppable": "^1.1.0",
"tslib": "^2.2.0",
"uuid": "^8.3.0"
"tslib": "^2.2.0"
},
"devDependencies": {
"@azure-tools/test-recorder": "^3.0.0",
Expand All @@ -137,7 +136,6 @@
"@types/node": "^14.0.0",
"@types/sinon": "^10.0.0",
"@types/stoppable": "^1.1.0",
"@types/uuid": "^8.0.0",
"chai": "^4.2.0",
"cross-env": "^7.0.2",
"dotenv": "^16.0.0",
Expand All @@ -161,8 +159,6 @@
"rimraf": "^3.0.0",
"sinon": "^15.0.0",
"ts-node": "^10.0.0",
"typescript": "~5.0.0",
"util": "^0.12.1",
"uuid": "^8.3.2"
"typescript": "~5.0.0"
}
}
23 changes: 8 additions & 15 deletions sdk/identity/identity/samples-dev/azureDeveloperCliCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,26 @@
import { AzureDeveloperCliCredential, DefaultAzureCredential } from "@azure/identity";
import dotenv from "dotenv";

// Load the .env file if it exists
dotenv.config();

async function testDefaultCredential() {
async function testDefaultCredential(): Promise<void> {
const credential = new DefaultAzureCredential();

try {
const token = await credential.getToken("https://storage.azure.com/.default");
console.log(token);
} catch (err) {
console.log("Error with DefaultAzureCredential:", err);
}
const { token } = await credential.getToken("https://storage.azure.com/.default");
console.log(`Token: ${token}`);
}

async function testAzureDeveloperCliCredential() {
async function testAzureDeveloperCliCredential(): Promise<void> {
const credential = new AzureDeveloperCliCredential({
tenantId: process.env.AZURE_TENANT_ID,
});

try {
const token = await credential.getToken("https://storage.azure.com/.default");
console.log(token);
} catch (err) {
console.log("Error with Credential:", err);
}
const { token } = await credential.getToken("https://storage.azure.com/.default");
console.log(`Token: ${token}`);
}

async function main() {
async function main(): Promise<void> {
await testDefaultCredential();
await testAzureDeveloperCliCredential();
}
Expand Down
11 changes: 5 additions & 6 deletions sdk/identity/identity/samples-dev/clientSecretCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import { ClientSecretCredential } from "@azure/identity";
import { KeyClient } from "@azure/keyvault-keys";
import dotenv from "dotenv";

// Load the .env file if it exists
require("dotenv").config();
dotenv.config();

export async function main(): Promise<void> {
const credential = new ClientSecretCredential(
process.env.AZURE_TENANT_ID!, // The tenant ID in Azure Active Directory
process.env.AZURE_CLIENT_ID!, // The app registration client Id in the AAD tenant
process.env.AZURE_TENANT_ID!, // The tenant ID in Microsoft Entra ID
process.env.AZURE_CLIENT_ID!, // The app registration client Id in the Microsoft Entra tenant
process.env.AZURE_CLIENT_SECRET! // The app registration secret for the registered application
);

Expand All @@ -26,7 +27,5 @@ export async function main(): Promise<void> {
}

main().catch((err) => {
console.log("error code: ", err.code);
console.log("error message: ", err.message);
console.log("error stack: ", err.stack);
console.error("The sample encountered an error:", err);
});
7 changes: 3 additions & 4 deletions sdk/identity/identity/samples-dev/defaultAzureCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient } from "@azure/keyvault-keys";
import dotenv from "dotenv";

// Load the .env file if it exists
require("dotenv").config();
dotenv.config();

/**
* The `DefaultAzureCredential` is appropriate for most scenarios where the application is intended to ultimately be run in the Azure Cloud.
Expand All @@ -30,7 +31,5 @@ export async function main(): Promise<void> {
}

main().catch((err) => {
console.log("error code: ", err.code);
console.log("error message: ", err.message);
console.log("error stack: ", err.stack);
console.error("The sample encountered an error:", err);
});
11 changes: 5 additions & 6 deletions sdk/identity/identity/samples-dev/environmentCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import { EnvironmentCredential } from "@azure/identity";
import { KeyClient } from "@azure/keyvault-keys";
import dotenv from "dotenv";

// Load the .env file if it exists
require("dotenv").config();
dotenv.config();

export async function main(): Promise<void> {
// EnvironmentCredential expects the following three environment variables:
// - AZURE_TENANT_ID: The tenant ID in Azure Active Directory
// - AZURE_CLIENT_ID: The application (client) ID registered in the AAD tenant
// - AZURE_TENANT_ID: The tenant ID in Microsoft Entra ID
// - AZURE_CLIENT_ID: The application (client) ID registered in the Microsoft Entra tenant
// - AZURE_CLIENT_SECRET: The client secret for the registered application
const credential = new EnvironmentCredential();

Expand All @@ -26,7 +27,5 @@ export async function main(): Promise<void> {
}

main().catch((err) => {
console.log("error code: ", err.code);
console.log("error message: ", err.message);
console.log("error stack: ", err.stack);
console.error("The sample encountered an error:", err);
});
22 changes: 7 additions & 15 deletions sdk/identity/identity/samples-dev/workloadIdentityCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,24 @@ import dotenv from "dotenv";

dotenv.config();

async function testDefaultCredential() {
async function testDefaultCredential(): Promise<void> {
const credential = new DefaultAzureCredential();

try {
const token = await credential.getToken("https://storage.azure.com/.default");
console.log(token);
} catch (err) {
console.log("Error with DefaultAzureCredential:", err);
}
const { token } = await credential.getToken("https://storage.azure.com/.default");
console.log(`Token: ${token}`);
}

async function testWorkloadCredential() {
async function testWorkloadCredential(): Promise<void> {
const credential = new WorkloadIdentityCredential({
tenantId: process.env.AZURE_TENANT_ID,
clientId: process.env.AZURE_CLIENT_ID,
});

try {
const token = await credential.getToken("https://storage.azure.com/.default");
console.log(token);
} catch (err) {
console.log("Error with WorkloadIdentityCredential:", err);
}
const result = await credential.getToken("https://storage.azure.com/.default");
console.log(`Token: ${result?.token}`);
}

async function main() {
async function main(): Promise<void> {
await testDefaultCredential();
await testWorkloadCredential();
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/identity/src/client/identityClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { INetworkModule, NetworkRequestOptions, NetworkResponse } from "@azure/msal-common";
import type { INetworkModule, NetworkRequestOptions, NetworkResponse } from "@azure/msal-node";
import { AccessToken, GetTokenOptions } from "@azure/core-auth";
import { ServiceClient } from "@azure/core-client";
import { isNode } from "@azure/core-util";
Expand Down
11 changes: 5 additions & 6 deletions sdk/identity/identity/src/msal/nodeFlows/msalNodeCommon.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import * as msalCommon from "@azure/msal-common";
import * as msalNode from "@azure/msal-node";
import { AccessToken, GetTokenOptions } from "@azure/core-auth";
import { getLogLevel } from "@azure/logger";
Expand Down Expand Up @@ -64,7 +63,7 @@ export interface MsalNodeOptions extends MsalFlowOptions {
* @internal
*/
let persistenceProvider:
| ((options?: TokenCachePersistenceOptions) => Promise<msalCommon.ICachePlugin>)
| ((options?: TokenCachePersistenceOptions) => Promise<msalNode.ICachePlugin>)
| undefined = undefined;

/**
Expand Down Expand Up @@ -107,8 +106,8 @@ export abstract class MsalNode extends MsalBaseUtilities implements MsalFlow {
protected identityClient?: IdentityClient;
protected requiresConfidential: boolean = false;
protected azureRegion?: string;
protected createCachePlugin: (() => Promise<msalCommon.ICachePlugin>) | undefined;
protected createCachePluginCae: (() => Promise<msalCommon.ICachePlugin>) | undefined;
protected createCachePlugin: (() => Promise<msalNode.ICachePlugin>) | undefined;
protected createCachePluginCae: (() => Promise<msalNode.ICachePlugin>) | undefined;

/**
* MSAL currently caches the tokens depending on the claims used to retrieve them.
Expand Down Expand Up @@ -289,10 +288,10 @@ export abstract class MsalNode extends MsalBaseUtilities implements MsalFlow {
* Allows the cancellation of a MSAL request.
*/
protected withCancellation(
promise: Promise<msalCommon.AuthenticationResult | null>,
promise: Promise<msalNode.AuthenticationResult | null>,
abortSignal?: AbortSignalLike,
onCancel?: () => void
): Promise<msalCommon.AuthenticationResult | null> {
): Promise<msalNode.AuthenticationResult | null> {
return new Promise((resolve, reject) => {
promise
.then((msalToken) => {
Expand Down
Loading

0 comments on commit a7c7378

Please sign in to comment.