@azure/identity 4.5.0-alpha.20240916.2 → 4.5.0-alpha.20240926.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"consumer.js","sourceRoot":"","sources":["../../../src/plugins/consumer.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,wBAAwB,EACxB,+BAA+B,GAChC,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAEpF;;;;GAIG;AACH,MAAM,aAAa,GAAuB;IACxC,kBAAkB,EAAE,wBAAwB;IAC5C,yBAAyB,EAAE,+BAA+B;IAC1D,uBAAuB,EAAE,uBAAuB;CACjD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAsB;IACtD,MAAM,CAAC,aAAa,CAAC,CAAC;AACxB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AzurePluginContext, IdentityPlugin } from \"./provider\";\nimport {\n msalNodeFlowCacheControl,\n msalNodeFlowNativeBrokerControl,\n} from \"../msal/nodeFlows/msalPlugins\";\n\nimport { vsCodeCredentialControl } from \"../credentials/visualStudioCodeCredential\";\n\n/**\n * The context passed to an Identity plugin. This contains objects that\n * plugins can use to set backend implementations.\n * @internal\n */\nconst pluginContext: AzurePluginContext = {\n cachePluginControl: msalNodeFlowCacheControl,\n nativeBrokerPluginControl: msalNodeFlowNativeBrokerControl,\n vsCodeCredentialControl: vsCodeCredentialControl,\n};\n\n/**\n * Extend Azure Identity with additional functionality. Pass a plugin from\n * a plugin package, such as:\n *\n * - `@azure/identity-cache-persistence`: provides persistent token caching\n * - `@azure/identity-vscode`: provides the dependencies of\n * `VisualStudioCodeCredential` and enables it\n *\n * Example:\n *\n * ```javascript\n * import { cachePersistencePlugin } from \"@azure/identity-cache-persistence\";\n *\n * import { useIdentityPlugin, DefaultAzureCredential } from \"@azure/identity\";\n * useIdentityPlugin(cachePersistencePlugin);\n *\n * // The plugin has the capability to extend `DefaultAzureCredential` and to\n * // add middleware to the underlying credentials, such as persistence.\n * const credential = new DefaultAzureCredential({\n * tokenCachePersistenceOptions: {\n * enabled: true\n * }\n * });\n * ```\n *\n * @param plugin - the plugin to register\n */\nexport function useIdentityPlugin(plugin: IdentityPlugin): void {\n plugin(pluginContext);\n}\n"]}
1
+ {"version":3,"file":"consumer.js","sourceRoot":"","sources":["../../../src/plugins/consumer.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,wBAAwB,EACxB,+BAA+B,GAChC,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAEpF;;;;GAIG;AACH,MAAM,aAAa,GAAuB;IACxC,kBAAkB,EAAE,wBAAwB;IAC5C,yBAAyB,EAAE,+BAA+B;IAC1D,uBAAuB,EAAE,uBAAuB;CACjD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAsB;IACtD,MAAM,CAAC,aAAa,CAAC,CAAC;AACxB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AzurePluginContext, IdentityPlugin } from \"./provider\";\nimport {\n msalNodeFlowCacheControl,\n msalNodeFlowNativeBrokerControl,\n} from \"../msal/nodeFlows/msalPlugins\";\n\nimport { vsCodeCredentialControl } from \"../credentials/visualStudioCodeCredential\";\n\n/**\n * The context passed to an Identity plugin. This contains objects that\n * plugins can use to set backend implementations.\n * @internal\n */\nconst pluginContext: AzurePluginContext = {\n cachePluginControl: msalNodeFlowCacheControl,\n nativeBrokerPluginControl: msalNodeFlowNativeBrokerControl,\n vsCodeCredentialControl: vsCodeCredentialControl,\n};\n\n/**\n * Extend Azure Identity with additional functionality. Pass a plugin from\n * a plugin package, such as:\n *\n * - `@azure/identity-cache-persistence`: provides persistent token caching\n * - `@azure/identity-vscode`: provides the dependencies of\n * `VisualStudioCodeCredential` and enables it\n *\n * Example:\n *\n * ```ts snippet:consumer_example\n * import { useIdentityPlugin, DeviceCodeCredential } from \"@azure/identity\";\n *\n * useIdentityPlugin(cachePersistencePlugin);\n * // The plugin has the capability to extend `DeviceCodeCredential` and to\n * // add middleware to the underlying credentials, such as persistence.\n * const credential = new DeviceCodeCredential({\n * tokenCachePersistenceOptions: {\n * enabled: true,\n * },\n * });\n * ```\n *\n * @param plugin - the plugin to register\n */\nexport function useIdentityPlugin(plugin: IdentityPlugin): void {\n plugin(pluginContext);\n}\n"]}
@@ -4,14 +4,14 @@ import { bearerTokenAuthenticationPolicy, createEmptyPipeline, createPipelineReq
4
4
  /**
5
5
  * Returns a callback that provides a bearer token.
6
6
  * For example, the bearer token can be used to authenticate a request as follows:
7
- * ```js
8
- * import { DefaultAzureCredential } from "@azure/identity";
7
+ * ```ts snippet:token_provider_example
8
+ * import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity";
9
+ * import { createPipelineRequest } from "@azure/core-rest-pipeline";
9
10
  *
10
11
  * const credential = new DefaultAzureCredential();
11
12
  * const scope = "https://cognitiveservices.azure.com/.default";
12
13
  * const getAccessToken = getBearerTokenProvider(credential, scope);
13
14
  * const token = await getAccessToken();
14
- *
15
15
  * // usage
16
16
  * const request = createPipelineRequest({ url: "https://example.com" });
17
17
  * request.headers.set("Authorization", `Bearer ${token}`);
@@ -1 +1 @@
1
- {"version":3,"file":"tokenProvider.js","sourceRoot":"","sources":["../../src/tokenProvider.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAiBnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,sBAAsB,CACpC,UAA2B,EAC3B,MAAyB,EACzB,OAAuC;IAEvC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACtD,MAAM,QAAQ,GAAG,mBAAmB,EAAE,CAAC;IACvC,QAAQ,CAAC,SAAS,CAAC,+BAA+B,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC5E,KAAK,UAAU,iBAAiB;;QAC9B,sDAAsD;QACtD,sDAAsD;QACtD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,WAAW,CACpC;YACE,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CACvB,OAAO,CAAC,OAAO,CAAC;gBACd,OAAO;gBACP,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC;SACL,EACD,qBAAqB,CAAC;YACpB,GAAG,EAAE,qBAAqB;YAC1B,WAAW;YACX,cAAc;SACf,CAAC,CACH,CAAC;QACF,MAAM,WAAW,GAAG,MAAA,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,0CAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACpE,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { TokenCredential, TracingContext } from \"@azure/core-auth\";\nimport {\n bearerTokenAuthenticationPolicy,\n createEmptyPipeline,\n createPipelineRequest,\n} from \"@azure/core-rest-pipeline\";\n\n/**\n * The options to configure the token provider.\n */\nexport interface GetBearerTokenProviderOptions {\n /** The abort signal to abort requests to get tokens */\n abortSignal?: AbortSignal;\n /** The tracing options for the requests to get tokens */\n tracingOptions?: {\n /**\n * Tracing Context for the current request to get a token.\n */\n tracingContext?: TracingContext;\n };\n}\n\n/**\n * Returns a callback that provides a bearer token.\n * For example, the bearer token can be used to authenticate a request as follows:\n * ```js\n * import { DefaultAzureCredential } from \"@azure/identity\";\n *\n * const credential = new DefaultAzureCredential();\n * const scope = \"https://cognitiveservices.azure.com/.default\";\n * const getAccessToken = getBearerTokenProvider(credential, scope);\n * const token = await getAccessToken();\n *\n * // usage\n * const request = createPipelineRequest({ url: \"https://example.com\" });\n * request.headers.set(\"Authorization\", `Bearer ${token}`);\n * ```\n *\n * @param credential - The credential used to authenticate the request.\n * @param scopes - The scopes required for the bearer token.\n * @param options - Options to configure the token provider.\n * @returns a callback that provides a bearer token.\n */\nexport function getBearerTokenProvider(\n credential: TokenCredential,\n scopes: string | string[],\n options?: GetBearerTokenProviderOptions,\n): () => Promise<string> {\n const { abortSignal, tracingOptions } = options || {};\n const pipeline = createEmptyPipeline();\n pipeline.addPolicy(bearerTokenAuthenticationPolicy({ credential, scopes }));\n async function getRefreshedToken(): Promise<string> {\n // Create a pipeline with just the bearer token policy\n // and run a dummy request through it to get the token\n const res = await pipeline.sendRequest(\n {\n sendRequest: (request) =>\n Promise.resolve({\n request,\n status: 200,\n headers: request.headers,\n }),\n },\n createPipelineRequest({\n url: \"https://example.com\",\n abortSignal,\n tracingOptions,\n }),\n );\n const accessToken = res.headers.get(\"authorization\")?.split(\" \")[1];\n if (!accessToken) {\n throw new Error(\"Failed to get access token\");\n }\n return accessToken;\n }\n return getRefreshedToken;\n}\n"]}
1
+ {"version":3,"file":"tokenProvider.js","sourceRoot":"","sources":["../../src/tokenProvider.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAiBnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,sBAAsB,CACpC,UAA2B,EAC3B,MAAyB,EACzB,OAAuC;IAEvC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACtD,MAAM,QAAQ,GAAG,mBAAmB,EAAE,CAAC;IACvC,QAAQ,CAAC,SAAS,CAAC,+BAA+B,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC5E,KAAK,UAAU,iBAAiB;;QAC9B,sDAAsD;QACtD,sDAAsD;QACtD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,WAAW,CACpC;YACE,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CACvB,OAAO,CAAC,OAAO,CAAC;gBACd,OAAO;gBACP,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC;SACL,EACD,qBAAqB,CAAC;YACpB,GAAG,EAAE,qBAAqB;YAC1B,WAAW;YACX,cAAc;SACf,CAAC,CACH,CAAC;QACF,MAAM,WAAW,GAAG,MAAA,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,0CAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACpE,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { TokenCredential, TracingContext } from \"@azure/core-auth\";\nimport {\n bearerTokenAuthenticationPolicy,\n createEmptyPipeline,\n createPipelineRequest,\n} from \"@azure/core-rest-pipeline\";\n\n/**\n * The options to configure the token provider.\n */\nexport interface GetBearerTokenProviderOptions {\n /** The abort signal to abort requests to get tokens */\n abortSignal?: AbortSignal;\n /** The tracing options for the requests to get tokens */\n tracingOptions?: {\n /**\n * Tracing Context for the current request to get a token.\n */\n tracingContext?: TracingContext;\n };\n}\n\n/**\n * Returns a callback that provides a bearer token.\n * For example, the bearer token can be used to authenticate a request as follows:\n * ```ts snippet:token_provider_example\n * import { DefaultAzureCredential, getBearerTokenProvider } from \"@azure/identity\";\n * import { createPipelineRequest } from \"@azure/core-rest-pipeline\";\n *\n * const credential = new DefaultAzureCredential();\n * const scope = \"https://cognitiveservices.azure.com/.default\";\n * const getAccessToken = getBearerTokenProvider(credential, scope);\n * const token = await getAccessToken();\n * // usage\n * const request = createPipelineRequest({ url: \"https://example.com\" });\n * request.headers.set(\"Authorization\", `Bearer ${token}`);\n * ```\n *\n * @param credential - The credential used to authenticate the request.\n * @param scopes - The scopes required for the bearer token.\n * @param options - Options to configure the token provider.\n * @returns a callback that provides a bearer token.\n */\nexport function getBearerTokenProvider(\n credential: TokenCredential,\n scopes: string | string[],\n options?: GetBearerTokenProviderOptions,\n): () => Promise<string> {\n const { abortSignal, tracingOptions } = options || {};\n const pipeline = createEmptyPipeline();\n pipeline.addPolicy(bearerTokenAuthenticationPolicy({ credential, scopes }));\n async function getRefreshedToken(): Promise<string> {\n // Create a pipeline with just the bearer token policy\n // and run a dummy request through it to get the token\n const res = await pipeline.sendRequest(\n {\n sendRequest: (request) =>\n Promise.resolve({\n request,\n status: 200,\n headers: request.headers,\n }),\n },\n createPipelineRequest({\n url: \"https://example.com\",\n abortSignal,\n tracingOptions,\n }),\n );\n const accessToken = res.headers.get(\"authorization\")?.split(\" \")[1];\n if (!accessToken) {\n throw new Error(\"Failed to get access token\");\n }\n return accessToken;\n }\n return getRefreshedToken;\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@azure/identity",
3
3
  "sdk-type": "client",
4
- "version": "4.5.0-alpha.20240916.2",
4
+ "version": "4.5.0-alpha.20240926.2",
5
5
  "description": "Provides credential implementations for Azure SDK libraries that can authenticate with Microsoft Entra ID",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist-esm/src/index.js",
@@ -47,28 +47,29 @@
47
47
  },
48
48
  "scripts": {
49
49
  "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
50
+ "build": "npm run clean && npm run extract-api && tsc -p . && dev-tool run bundle",
50
51
  "build:samples": "echo Obsolete.",
51
52
  "build:test": "echo skipped. actual commands inlined in browser test scripts",
52
- "build": "npm run clean && npm run extract-api && tsc -p . && dev-tool run bundle",
53
+ "check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
53
54
  "clean": "rimraf --glob dist dist-* types *.tgz *.log",
54
55
  "execute:samples": "dev-tool samples run samples-dev",
55
56
  "extract-api": "tsc -p . && dev-tool run extract-api",
56
57
  "format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
57
- "check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
58
+ "integration-test": "npm run integration-test:node && npm run integration-test:browser",
58
59
  "integration-test:browser": "echo skipped",
59
- "integration-test:node": "dev-tool run test:node-ts-input -- --timeout 180000 'test/public/node/*.spec.ts' 'test/internal/node/*.spec.ts'",
60
60
  "integration-test:managed-identity": "dev-tool run test:node-ts-input -- --timeout 180000 'test/integration/**/*.spec.ts'",
61
- "integration-test": "npm run integration-test:node && npm run integration-test:browser",
62
- "lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
61
+ "integration-test:node": "dev-tool run test:node-ts-input -- --timeout 180000 'test/public/node/*.spec.ts' 'test/internal/node/*.spec.ts'",
63
62
  "lint": "eslint package.json api-extractor.json src test",
63
+ "lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
64
64
  "pack": "npm pack 2>&1",
65
+ "test": "npm run clean && npm run build:test && npm run unit-test && npm run integration-test",
65
66
  "test:browser": "npm run clean && tsc -p . && dev-tool run bundle && npm run unit-test:browser && npm run integration-test:browser",
66
67
  "test:node": "npm run clean && npm run unit-test:node && npm run integration-test:node",
67
- "test": "npm run clean && npm run build:test && npm run unit-test && npm run integration-test",
68
+ "unit-test": "npm run unit-test:node && npm run unit-test:browser",
68
69
  "unit-test:browser": "dev-tool run test:browser",
69
- "unit-test:node": "dev-tool run test:node-ts-input -- --timeout 300000 --exclude 'test/**/browser/**/*.spec.ts' --exclude 'test/integration/**/*.spec.ts' 'test/**/**/*.spec.ts'",
70
- "unit-test:node:no-timeouts": "dev-tool run test:node-ts-input -- --timeout Infinite --exclude 'test/**/browser/**/*.spec.ts' 'test/**/**/*.spec.ts'",
71
- "unit-test": "npm run unit-test:node && npm run unit-test:browser"
70
+ "unit-test:node": "dev-tool run test:node-ts-input -- --timeout 300000 --exclude 'test/**/browser/**/*.spec.ts' --exclude 'test/snippets.spec.ts' --exclude 'test/integration/**/*.spec.ts' 'test/**/**/*.spec.ts'",
71
+ "unit-test:node:no-timeouts": "dev-tool run test:node-ts-input -- --timeout Infinite --exclude 'test/snippets.spec.ts' --exclude 'test/**/browser/**/*.spec.ts' 'test/**/**/*.spec.ts'",
72
+ "update-snippets": "dev-tool run update-snippets"
72
73
  },
73
74
  "files": [
74
75
  "dist/",
@@ -115,8 +116,8 @@
115
116
  "@azure/core-tracing": "^1.0.0",
116
117
  "@azure/core-util": "^1.10.0",
117
118
  "@azure/logger": "^1.0.0",
118
- "@azure/msal-node": "^2.9.2",
119
119
  "@azure/msal-browser": "^3.14.0",
120
+ "@azure/msal-node": "^2.9.2",
120
121
  "events": "^3.0.0",
121
122
  "jws": "^4.0.0",
122
123
  "open": "^8.0.0",
@@ -125,10 +126,10 @@
125
126
  },
126
127
  "devDependencies": {
127
128
  "@azure-tools/test-recorder": "^3.0.0",
129
+ "@azure-tools/test-utils": "^1.0.1",
128
130
  "@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
129
131
  "@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
130
132
  "@azure/keyvault-keys": "^4.2.0",
131
- "@azure-tools/test-utils": "^1.0.1",
132
133
  "@microsoft/api-extractor": "^7.31.1",
133
134
  "@types/chai": "^4.1.6",
134
135
  "@types/jsonwebtoken": "^9.0.0",
@@ -160,7 +161,7 @@
160
161
  "rimraf": "^5.0.5",
161
162
  "sinon": "^17.0.0",
162
163
  "ts-node": "^10.0.0",
163
- "typescript": "~5.5.3",
164
+ "typescript": "~5.6.2",
164
165
  "util": "^0.12.1"
165
166
  }
166
167
  }
@@ -540,7 +540,14 @@ export declare class ChainedTokenCredential implements TokenCredential {
540
540
  * @param sources - `TokenCredential` implementations to be tried in order.
541
541
  *
542
542
  * Example usage:
543
- * ```javascript
543
+ * ```ts snippet:chained_token_credential_example
544
+ * import { ClientSecretCredential, ChainedTokenCredential } from "@azure/identity";
545
+ *
546
+ * const tenantId = "<tenant-id>";
547
+ * const clientId = "<client-id>";
548
+ * const clientSecret = "<client-secret>";
549
+ * const anotherClientId = "<another-client-id>";
550
+ * const anotherSecret = "<another-client-secret>";
544
551
  * const firstCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);
545
552
  * const secondCredential = new ClientSecretCredential(tenantId, anotherClientId, anotherSecret);
546
553
  * const credentialChain = new ChainedTokenCredential(firstCredential, secondCredential);
@@ -758,23 +765,14 @@ export declare interface CredentialPersistenceOptions {
758
765
  *
759
766
  * Example:
760
767
  *
761
- * ```javascript
762
- * import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
768
+ * ```ts snippet:credential_persistence_options_example
763
769
  * import { useIdentityPlugin, DeviceCodeCredential } from "@azure/identity";
764
770
  *
765
771
  * useIdentityPlugin(cachePersistencePlugin);
766
- *
767
- * async function main() {
768
- * const credential = new DeviceCodeCredential({
769
- * tokenCachePersistenceOptions: {
770
- * enabled: true
771
- * }
772
- * });
773
- * }
774
- *
775
- * main().catch((error) => {
776
- * console.error("An error occurred:", error);
777
- * process.exit(1);
772
+ * const credential = new DeviceCodeCredential({
773
+ * tokenCachePersistenceOptions: {
774
+ * enabled: true,
775
+ * },
778
776
  * });
779
777
  * ```
780
778
  */
@@ -955,13 +953,15 @@ export declare class DeviceCodeCredential implements TokenCredential {
955
953
  *
956
954
  * Developers can configure how this message is shown by passing a custom `userPromptCallback`:
957
955
  *
958
- * ```js
956
+ * ```ts snippet:device_code_credential_example
957
+ * import { DeviceCodeCredential } from "@azure/identity";
958
+ *
959
959
  * const credential = new DeviceCodeCredential({
960
- * tenantId: env.AZURE_TENANT_ID,
961
- * clientId: env.AZURE_CLIENT_ID,
960
+ * tenantId: process.env.AZURE_TENANT_ID,
961
+ * clientId: process.env.AZURE_CLIENT_ID,
962
962
  * userPromptCallback: (info) => {
963
963
  * console.log("CUSTOMIZED PROMPT CALLBACK", info.message);
964
- * }
964
+ * },
965
965
  * });
966
966
  * ```
967
967
  *
@@ -1133,14 +1133,14 @@ export declare interface ErrorResponse {
1133
1133
  /**
1134
1134
  * Returns a callback that provides a bearer token.
1135
1135
  * For example, the bearer token can be used to authenticate a request as follows:
1136
- * ```js
1137
- * import { DefaultAzureCredential } from "@azure/identity";
1136
+ * ```ts snippet:token_provider_example
1137
+ * import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity";
1138
+ * import { createPipelineRequest } from "@azure/core-rest-pipeline";
1138
1139
  *
1139
1140
  * const credential = new DefaultAzureCredential();
1140
1141
  * const scope = "https://cognitiveservices.azure.com/.default";
1141
1142
  * const getAccessToken = getBearerTokenProvider(credential, scope);
1142
1143
  * const token = await getAccessToken();
1143
- *
1144
1144
  * // usage
1145
1145
  * const request = createPipelineRequest({ url: "https://example.com" });
1146
1146
  * request.headers.set("Authorization", `Bearer ${token}`);
@@ -1441,15 +1441,17 @@ export declare class OnBehalfOfCredential implements TokenCredential {
1441
1441
  *
1442
1442
  * Example using the `KeyClient` from [\@azure/keyvault-keys](https://www.npmjs.com/package/\@azure/keyvault-keys):
1443
1443
  *
1444
- * ```ts
1444
+ * ```ts snippet:on_behalf_of_credential_pem_example
1445
+ * import { OnBehalfOfCredential } from "@azure/identity";
1446
+ * import { KeyClient } from "@azure/keyvault-keys";
1447
+ *
1445
1448
  * const tokenCredential = new OnBehalfOfCredential({
1446
- * tenantId,
1447
- * clientId,
1449
+ * tenantId: "tenant-id",
1450
+ * clientId: "client-id",
1448
1451
  * certificatePath: "/path/to/certificate.pem",
1449
- * userAssertionToken: "access-token"
1452
+ * userAssertionToken: "access-token",
1450
1453
  * });
1451
1454
  * const client = new KeyClient("vault-url", tokenCredential);
1452
- *
1453
1455
  * await client.getKey("key-name");
1454
1456
  * ```
1455
1457
  *
@@ -1463,15 +1465,17 @@ export declare class OnBehalfOfCredential implements TokenCredential {
1463
1465
  *
1464
1466
  * Example using the `KeyClient` from [\@azure/keyvault-keys](https://www.npmjs.com/package/\@azure/keyvault-keys):
1465
1467
  *
1466
- * ```ts
1468
+ * ```ts snippet:on_behalf_of_credential_secret_example
1469
+ * import { OnBehalfOfCredential } from "@azure/identity";
1470
+ * import { KeyClient } from "@azure/keyvault-keys";
1471
+ *
1467
1472
  * const tokenCredential = new OnBehalfOfCredential({
1468
- * tenantId,
1469
- * clientId,
1470
- * clientSecret,
1471
- * userAssertionToken: "access-token"
1473
+ * tenantId: "tenant-id",
1474
+ * clientId: "client-id",
1475
+ * clientSecret: "client-secret",
1476
+ * userAssertionToken: "access-token",
1472
1477
  * });
1473
1478
  * const client = new KeyClient("vault-url", tokenCredential);
1474
- *
1475
1479
  * await client.getKey("key-name");
1476
1480
  * ```
1477
1481
  *
@@ -1485,15 +1489,19 @@ export declare class OnBehalfOfCredential implements TokenCredential {
1485
1489
  *
1486
1490
  * Example using the `KeyClient` from [\@azure/keyvault-keys](https://www.npmjs.com/package/\@azure/keyvault-keys):
1487
1491
  *
1488
- * ```ts
1492
+ * ```ts snippet:on_behalf_of_credential_assertion_example
1493
+ * import { OnBehalfOfCredential } from "@azure/identity";
1494
+ * import { KeyClient } from "@azure/keyvault-keys";
1495
+ *
1489
1496
  * const tokenCredential = new OnBehalfOfCredential({
1490
- * tenantId,
1491
- * clientId,
1492
- * getAssertion: () => { return Promise.resolve("my-jwt")},
1493
- * userAssertionToken: "access-token"
1497
+ * tenantId: "tenant-id",
1498
+ * clientId: "client-id",
1499
+ * getAssertion: () => {
1500
+ * return Promise.resolve("my-jwt");
1501
+ * },
1502
+ * userAssertionToken: "access-token",
1494
1503
  * });
1495
1504
  * const client = new KeyClient("vault-url", tokenCredential);
1496
- *
1497
1505
  * await client.getKey("key-name");
1498
1506
  * ```
1499
1507
  *
@@ -1666,18 +1674,16 @@ export declare interface TokenCredentialOptions extends CommonClientOptions {
1666
1674
  *
1667
1675
  * Example:
1668
1676
  *
1669
- * ```javascript
1670
- * import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
1677
+ * ```ts snippet:consumer_example
1678
+ * import { useIdentityPlugin, DeviceCodeCredential } from "@azure/identity";
1671
1679
  *
1672
- * import { useIdentityPlugin, DefaultAzureCredential } from "@azure/identity";
1673
1680
  * useIdentityPlugin(cachePersistencePlugin);
1674
- *
1675
- * // The plugin has the capability to extend `DefaultAzureCredential` and to
1681
+ * // The plugin has the capability to extend `DeviceCodeCredential` and to
1676
1682
  * // add middleware to the underlying credentials, such as persistence.
1677
- * const credential = new DefaultAzureCredential({
1683
+ * const credential = new DeviceCodeCredential({
1678
1684
  * tokenCachePersistenceOptions: {
1679
- * enabled: true
1680
- * }
1685
+ * enabled: true,
1686
+ * },
1681
1687
  * });
1682
1688
  * ```
1683
1689
  *