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] Migrate rest of identity projects to use snippets extraction #33201

Merged
merged 26 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3f51e5a
Migration: Update package.json, tsconfig.json, and api-extractor.json
mpodwysocki Feb 26, 2025
7e79c90
Migration: Update test config
mpodwysocki Feb 26, 2025
9d25c34
Migration: Clean up files
mpodwysocki Feb 26, 2025
46c9338
Migration: Apply codemod: "fixSourceFile"
mpodwysocki Feb 26, 2025
0f37f89
Migration: Apply codemod: "fixTestingImports"
mpodwysocki Feb 26, 2025
e6788fe
Migration: Apply codemod: "replaceAssertIsRejected"
mpodwysocki Feb 26, 2025
0493024
Migration: Apply codemod: "replaceSinonStub"
mpodwysocki Feb 26, 2025
4eeaefa
Migration: Apply codemod: "addViHelper"
mpodwysocki Feb 26, 2025
7d50234
Migration: Apply codemod: "replaceSupportTracing"
mpodwysocki Feb 26, 2025
fa98681
Migration: Apply codemod: "replaceTestUtils"
mpodwysocki Feb 26, 2025
175a4f4
Migration: npm run format
mpodwysocki Feb 26, 2025
4e84aef
Migration: Update package.json, tsconfig.json, and api-extractor.json
mpodwysocki Feb 26, 2025
22ddf59
Migration: Update test config
mpodwysocki Feb 26, 2025
5f2bcc2
Migration: Clean up files
mpodwysocki Feb 26, 2025
c9f5ead
Migration: Apply codemod: "fixSourceFile"
mpodwysocki Feb 26, 2025
f62f04b
Migration: Apply codemod: "fixTestingImports"
mpodwysocki Feb 26, 2025
a9ec6e5
Migration: Apply codemod: "replaceAssertIsRejected"
mpodwysocki Feb 26, 2025
bf633cd
Migration: Apply codemod: "replaceSinonStub"
mpodwysocki Feb 26, 2025
a0d8c76
Migration: Apply codemod: "addViHelper"
mpodwysocki Feb 26, 2025
d8dc2b9
Migration: Apply codemod: "replaceSupportTracing"
mpodwysocki Feb 26, 2025
1a10b54
Migration: Apply codemod: "replaceTestUtils"
mpodwysocki Feb 26, 2025
d66b74d
Migration: npm run format
mpodwysocki Feb 26, 2025
6dfc979
[identity] Migrate identity projects to use snippets extraction
mpodwysocki Feb 26, 2025
d3e30c2
[identity] Migrate identity projects to use snippets extraction
mpodwysocki Feb 26, 2025
e069c69
[identity] Migrate identity projects to use snippets extraction
mpodwysocki Feb 26, 2025
93b3316
[identity] Migrate identity projects to use snippets extraction
mpodwysocki Feb 26, 2025
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
23 changes: 14 additions & 9 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/identity/identity-cache-persistence/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ If this is your first time using `@azure/identity` or Microsoft Entra ID, we rec

As of `@azure/identity` version 2.0.0, the Identity client library for JavaScript includes a plugin API. This package (`@azure/identity-cache-persistence`) exports a plugin object that you must pass as an argument to the top-level `useIdentityPlugin` function from the `@azure/identity` package. Enable token cache persistence in your program as follows:

```ts snippet:getting_started
```ts snippet:ReadmeSampleUsePlugin
import { useIdentityPlugin } from "@azure/identity";
import { cachePersistencePlugin } from "@azure/identity-cache-persistence";

Expand All @@ -44,7 +44,7 @@ After calling `useIdentityPlugin`, the persistent token cache plugin is register

Once the plugin is registered, you can enable token cache persistence by passing `tokenCachePersistenceOptions` with an `enabled` property set to `true` to a credential constructor. In the following example, we use the `DeviceCodeCredential`, since persistent caching of its tokens allows you to skip the interactive device-code authentication flow if a cached token is available.

```ts snippet:device_code_credential_example
```ts snippet:ReadmeSampleDeviceCodeCredential
import { DeviceCodeCredential } from "@azure/identity";

const credential = new DeviceCodeCredential({
Expand All @@ -66,7 +66,7 @@ console.log((await credential.getToken(scope)).token.substring(0, 10), "...");

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:

```ts snippet:logging
```ts snippet:SetLogLevel
import { setLogLevel } from "@azure/logger";

setLogLevel("info");
Expand Down
17 changes: 9 additions & 8 deletions sdk/identity/identity-cache-persistence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"unit-test:browser": "echo skipped",
"unit-test:node": "echo skipped",
"update-snippets": "echo skipped"
"update-snippets": "dev-tool run update-snippets"
},
"files": [
"dist/",
Expand Down Expand Up @@ -71,16 +71,17 @@
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/logger": "^1.1.4",
"@types/node": "^18.0.0",
"@vitest/browser": "^3.0.3",
"@vitest/coverage-istanbul": "^3.0.3",
"@vitest/browser": "^3.0.6",
"@vitest/coverage-istanbul": "^3.0.6",
"dotenv": "^16.0.0",
"eslint": "^9.9.0",
"playwright": "^1.49.0",
"playwright": "^1.50.1",
"typescript": "~5.7.2",
"vitest": "^3.0.3"
"vitest": "^3.0.6"
},
"type": "module",
"tshy": {
"project": "./tsconfig.src.json",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
Expand All @@ -93,8 +94,7 @@
"browser",
"react-native"
],
"selfLink": false,
"project": "./tsconfig.src.json"
"selfLink": false
},
"browser": "./dist/browser/index.js",
"exports": {
Expand All @@ -117,5 +117,6 @@
"default": "./dist/commonjs/index.js"
}
}
}
},
"react-native": "./dist/react-native/index.js"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import { useIdentityPlugin, DeviceCodeCredential } from "@azure/identity";
import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
useIdentityPlugin(cachePersistencePlugin);

import dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const credential = new DeviceCodeCredential({
// This property must be provided, with `enabled` set to true to enable
// persistent token caching.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
/**
* @summary Authenticates using persistent token caching with Interactive Browser Credential
*/
import {
InteractiveBrowserCredential,
useIdentityPlugin,
AuthenticationRecord,
} from "@azure/identity";
import type { AuthenticationRecord } from "@azure/identity";
import { InteractiveBrowserCredential, useIdentityPlugin } from "@azure/identity";
import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
import path from "path";
import fs from "fs";
import dotenv from "dotenv";
import path from "node:path";
import fs from "node:fs";
import "dotenv/config";

useIdentityPlugin(cachePersistencePlugin);

dotenv.config();
// The app registration client ID in the Microsoft Entra tenant
const clientId = "APP-REGISTRATION-CLIENT-ID";
// The tenant ID in Microsoft Entra ID
Expand All @@ -26,7 +21,7 @@ const loginHint = `EMAIL-ADDRESS`;
// The file path to save the authentication record
const authenticationRecordFilePath = path.resolve(__dirname, "authenticationRecord.json");

async function main() {
async function main(): Promise<void> {
try {
const fileContents = await fs.promises.readFile(authenticationRecordFilePath, "utf8");
const authenticationRecord = JSON.parse(fileContents);
Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/identity-cache-persistence/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface AzurePluginContext {
*
* Example:
*
* ```ts snippet:device_code_credential_example
* ```ts snippet:ReadmeSampleDeviceCodeCredential
* import { DeviceCodeCredential } from "@azure/identity";
*
* const credential = new DeviceCodeCredential({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("ClientCertificateCredential (internal)", () => {
);
});

afterEach(async function () {
afterEach(async () => {
await cleanup();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("ClientSecretCredential (internal)", () => {
"acquireTokenByClientCredential",
);
});
afterEach(async function () {
afterEach(async () => {
await cleanup();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("DeviceCodeCredential (internal)", () => {
doGetTokenSpy = vi.spyOn(PublicClientApplication.prototype, "acquireTokenByDeviceCode");
});

afterEach(async function () {
afterEach(async () => {
await cleanup();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("UsernamePasswordCredential (internal)", () => {
doGetTokenSpy = vi.spyOn(PublicClientApplication.prototype, "acquireTokenByUsernamePassword");
});

afterEach(async function () {
afterEach(async () => {
await cleanup();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import { DeviceCodeCredential, useIdentityPlugin } from "@azure/identity";
import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
import { setLogLevel } from "@azure/logger";
import { describe, it, assert } from "vitest";
import { describe, it } from "vitest";

describe("snippets", () => {
it("getting_started", () => {
it("ReadmeSampleUsePlugin", () => {
useIdentityPlugin(cachePersistencePlugin);
});

it("device_code_credential_example", async () => {
it("ReadmeSampleDeviceCodeCredential", async () => {
const credential = new DeviceCodeCredential({
tokenCachePersistenceOptions: {
enabled: true,
Expand All @@ -25,7 +25,7 @@ describe("snippets", () => {
console.log((await credential.getToken(scope)).token.substring(0, 10), "...");
});

it("logging", async () => {
it("SetLogLevel", async () => {
setLogLevel("info");
});
});
17 changes: 10 additions & 7 deletions sdk/identity/identity-cache-persistence/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
],
"compilerOptions": {
"esModuleInterop": true
}
{
"path": "./tsconfig.src.json"
},
{
"path": "./tsconfig.samples.json"
},
{
"path": "./tsconfig.test.json"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export default mergeConfig(
viteConfig,
defineConfig({
test: {
include: [
"dist-test/browser/test/**/*.spec.js",
],
include: ["dist-test/browser/test/**/*.spec.js",],
testTimeout: 1200000,
hookTimeout: 1200000,
},
}),
);
12 changes: 11 additions & 1 deletion sdk/identity/identity-cache-persistence/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { defineConfig, mergeConfig } from "vitest/config";
import viteConfig from "../../../vitest.shared.config.ts";

export default viteConfig;
export default mergeConfig(
viteConfig,
defineConfig({
test: {
testTimeout: 1200000,
hookTimeout: 1200000,
},
}),
);
12 changes: 12 additions & 0 deletions sdk/identity/identity-cache-persistence/vitest.esm.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { mergeConfig } from "vitest/config";
import vitestConfig from "./vitest.config.ts";
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";

export default mergeConfig(
vitestConfig,
vitestEsmConfig
);
Loading
Loading