UNPKG

51.5 kBTypeScriptView Raw
1import { AccessToken } from '@azure/core-auth';
2import { AzureLogger } from '@azure/logger';
3import { CommonClientOptions } from '@azure/core-client';
4import { GetTokenOptions } from '@azure/core-auth';
5import { TokenCredential } from '@azure/core-auth';
6
7export { AccessToken }
8
9/**
10 * Provides an `errors` array containing {@link AuthenticationError} instance
11 * for authentication failures from credentials in a {@link ChainedTokenCredential}.
12 */
13export declare class AggregateAuthenticationError extends Error {
14 /**
15 * The array of error objects that were thrown while trying to authenticate
16 * with the credentials in a {@link ChainedTokenCredential}.
17 */
18 errors: any[];
19 constructor(errors: any[], errorMessage?: string);
20}
21
22/**
23 * The Error.name value of an AggregateAuthenticationError
24 */
25export declare const AggregateAuthenticationErrorName = "AggregateAuthenticationError";
26
27/**
28 * Provides details about a failure to authenticate with Azure Active
29 * Directory. The `errorResponse` field contains more details about
30 * the specific failure.
31 */
32export declare class AuthenticationError extends Error {
33 /**
34 * The HTTP status code returned from the authentication request.
35 */
36 readonly statusCode: number;
37 /**
38 * The error response details.
39 */
40 readonly errorResponse: ErrorResponse;
41 constructor(statusCode: number, errorBody: object | string | undefined | null);
42}
43
44/**
45 * The Error.name value of an AuthenticationError
46 */
47export declare const AuthenticationErrorName = "AuthenticationError";
48
49/**
50 * The record to use to find the cached tokens in the cache.
51 */
52export declare interface AuthenticationRecord {
53 /**
54 * The associated authority, if used.
55 */
56 authority: string;
57 /**
58 * The home account Id.
59 */
60 homeAccountId: string;
61 /**
62 * The associated client ID.
63 */
64 clientId: string;
65 /**
66 * The associated tenant ID.
67 */
68 tenantId: string;
69 /**
70 * The username of the logged in account.
71 */
72 username: string;
73}
74
75/**
76 * Error used to enforce authentication after trying to retrieve a token silently.
77 */
78export declare class AuthenticationRequiredError extends Error {
79 /**
80 * The list of scopes for which the token will have access.
81 */
82 scopes: string[];
83 /**
84 * The options passed to the getToken request.
85 */
86 getTokenOptions?: GetTokenOptions;
87 constructor(
88 /**
89 * Optional parameters. A message can be specified. The {@link GetTokenOptions} of the request can also be specified to more easily associate the error with the received parameters.
90 */
91 options: AuthenticationRequiredErrorOptions);
92}
93
94/**
95 * Optional parameters to the {@link AuthenticationRequiredError}
96 */
97export declare interface AuthenticationRequiredErrorOptions {
98 /**
99 * The list of scopes for which the token will have access.
100 */
101 scopes: string[];
102 /**
103 * The options passed to the getToken request.
104 */
105 getTokenOptions?: GetTokenOptions;
106 /**
107 * The message of the error.
108 */
109 message?: string;
110}
111
112/**
113 * Enables authentication to Azure Active Directory using an authorization code
114 * that was obtained through the authorization code flow, described in more detail
115 * in the Azure Active Directory documentation:
116 *
117 * https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
118 */
119export declare class AuthorizationCodeCredential implements TokenCredential {
120 private msalFlow;
121 private disableAutomaticAuthentication?;
122 private authorizationCode;
123 private redirectUri;
124 /**
125 * Creates an instance of CodeFlowCredential with the details needed
126 * to request an access token using an authentication that was obtained
127 * from Azure Active Directory.
128 *
129 * It is currently necessary for the user of this credential to initiate
130 * the authorization code flow to obtain an authorization code to be used
131 * with this credential. A full example of this flow is provided here:
132 *
133 * https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/v2/manual/authorizationCodeSample.ts
134 *
135 * @param tenantId - The Azure Active Directory tenant (directory) ID or name.
136 * 'common' may be used when dealing with multi-tenant scenarios.
137 * @param clientId - The client (application) ID of an App Registration in the tenant.
138 * @param clientSecret - A client secret that was generated for the App Registration
139 * @param authorizationCode - An authorization code that was received from following the
140 authorization code flow. This authorization code must not
141 have already been used to obtain an access token.
142 * @param redirectUri - The redirect URI that was used to request the authorization code.
143 Must be the same URI that is configured for the App Registration.
144 * @param options - Options for configuring the client which makes the access token request.
145 */
146 constructor(tenantId: string | "common", clientId: string, clientSecret: string, authorizationCode: string, redirectUri: string, options?: TokenCredentialOptions);
147 /**
148 * Creates an instance of CodeFlowCredential with the details needed
149 * to request an access token using an authentication that was obtained
150 * from Azure Active Directory.
151 *
152 * It is currently necessary for the user of this credential to initiate
153 * the authorization code flow to obtain an authorization code to be used
154 * with this credential. A full example of this flow is provided here:
155 *
156 * https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/v2/manual/authorizationCodeSample.ts
157 *
158 * @param tenantId - The Azure Active Directory tenant (directory) ID or name.
159 * 'common' may be used when dealing with multi-tenant scenarios.
160 * @param clientId - The client (application) ID of an App Registration in the tenant.
161 * @param authorizationCode - An authorization code that was received from following the
162 authorization code flow. This authorization code must not
163 have already been used to obtain an access token.
164 * @param redirectUri - The redirect URI that was used to request the authorization code.
165 Must be the same URI that is configured for the App Registration.
166 * @param options - Options for configuring the client which makes the access token request.
167 */
168 constructor(tenantId: string | "common", clientId: string, authorizationCode: string, redirectUri: string, options?: TokenCredentialOptions);
169 /**
170 * Authenticates with Azure Active Directory and returns an access token if successful.
171 * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
172 *
173 * @param scopes - The list of scopes for which the token will have access.
174 * @param options - The options used to configure any requests this
175 * TokenCredential implementation might make.
176 */
177 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
178}
179
180/**
181 * A list of known Azure authority hosts
182 */
183export declare enum AzureAuthorityHosts {
184 /**
185 * China-based Azure Authority Host
186 */
187 AzureChina = "https://login.chinacloudapi.cn",
188 /**
189 * Germany-based Azure Authority Host
190 */
191 AzureGermany = "https://login.microsoftonline.de",
192 /**
193 * US Government Azure Authority Host
194 */
195 AzureGovernment = "https://login.microsoftonline.us",
196 /**
197 * Public Cloud Azure Authority Host
198 */
199 AzurePublicCloud = "https://login.microsoftonline.com"
200}
201
202/**
203 * This credential will use the currently logged-in user login information
204 * via the Azure CLI ('az') commandline tool.
205 * To do so, it will read the user access token and expire time
206 * with Azure CLI command "az account get-access-token".
207 */
208export declare class AzureCliCredential implements TokenCredential {
209 private tenantId?;
210 /**
211 * Creates an instance of the {@link AzureCliCredential}.
212 *
213 * To use this credential, ensure that you have already logged
214 * in via the 'az' tool using the command "az login" from the commandline.
215 *
216 * @param options - Options, to optionally allow multi-tenant requests.
217 */
218 constructor(options?: AzureCliCredentialOptions);
219 /**
220 * Authenticates with Azure Active Directory and returns an access token if successful.
221 * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
222 *
223 * @param scopes - The list of scopes for which the token will have access.
224 * @param options - The options used to configure any requests this
225 * TokenCredential implementation might make.
226 */
227 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
228}
229
230/**
231 * Options for the {@link AzureCliCredential}
232 */
233export declare interface AzureCliCredentialOptions extends TokenCredentialOptions {
234 /**
235 * Allows specifying a tenant ID
236 */
237 tenantId?: string;
238}
239
240/**
241 * This credential will use the currently logged-in user information from the
242 * Azure PowerShell module. To do so, it will read the user access token and
243 * expire time with Azure PowerShell command `Get-AzAccessToken -ResourceUrl {ResourceScope}`
244 */
245export declare class AzurePowerShellCredential implements TokenCredential {
246 private tenantId?;
247 /**
248 * Creates an instance of the {@link AzurePowerShellCredential}.
249 *
250 * To use this credential:
251 * - Install the Azure Az PowerShell module with:
252 * `Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force`.
253 * - You have already logged in to Azure PowerShell using the command
254 * `Connect-AzAccount` from the command line.
255 *
256 * @param options - Options, to optionally allow multi-tenant requests.
257 */
258 constructor(options?: AzurePowerShellCredentialOptions);
259 /**
260 * Gets the access token from Azure PowerShell
261 * @param resource - The resource to use when getting the token
262 */
263 private getAzurePowerShellAccessToken;
264 /**
265 * Authenticates with Azure Active Directory and returns an access token if successful.
266 * If the authentication cannot be performed through PowerShell, a {@link CredentialUnavailableError} will be thrown.
267 *
268 * @param scopes - The list of scopes for which the token will have access.
269 * @param options - The options used to configure any requests this TokenCredential implementation might make.
270 */
271 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
272}
273
274/**
275 * Options for the {@link AzurePowerShellCredential}
276 */
277export declare interface AzurePowerShellCredentialOptions extends TokenCredentialOptions {
278 /**
279 * Allows specifying a tenant ID
280 */
281 tenantId?: string;
282}
283
284/**
285 * (Browser-only feature)
286 * The "login style" to use in the authentication flow:
287 * - "redirect" redirects the user to the authentication page and then
288 * redirects them back to the page once authentication is completed.
289 * - "popup" opens a new browser window through with the redirect flow
290 * is initiated. The user's existing browser window does not leave
291 * the current page
292 */
293export declare type BrowserLoginStyle = "redirect" | "popup";
294
295/**
296 * Enables multiple `TokenCredential` implementations to be tried in order
297 * until one of the getToken methods returns an access token.
298 */
299export declare class ChainedTokenCredential implements TokenCredential {
300 /**
301 * The message to use when the chained token fails to get a token
302 */
303 protected UnavailableMessage: string;
304 private _sources;
305 /**
306 * Creates an instance of ChainedTokenCredential using the given credentials.
307 *
308 * @param sources - `TokenCredential` implementations to be tried in order.
309 *
310 * Example usage:
311 * ```javascript
312 * const firstCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);
313 * const secondCredential = new ClientSecretCredential(tenantId, anotherClientId, anotherSecret);
314 * const credentialChain = new ChainedTokenCredential(firstCredential, secondCredential);
315 * ```
316 */
317 constructor(...sources: TokenCredential[]);
318 /**
319 * Returns the first access token returned by one of the chained
320 * `TokenCredential` implementations. Throws an {@link AggregateAuthenticationError}
321 * when one or more credentials throws an {@link AuthenticationError} and
322 * no credentials have returned an access token.
323 *
324 * This method is called automatically by Azure SDK client libraries. You may call this method
325 * directly, but you must also handle token caching and token refreshing.
326 *
327 * @param scopes - The list of scopes for which the token will have access.
328 * @param options - The options used to configure any requests this
329 * `TokenCredential` implementation might make.
330 */
331 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
332}
333
334/**
335 * Enables authentication to Azure Active Directory using a PEM-encoded
336 * certificate that is assigned to an App Registration. More information
337 * on how to configure certificate authentication can be found here:
338 *
339 * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-certificate-credentials#register-your-certificate-with-azure-ad
340 *
341 */
342export declare class ClientCertificateCredential implements TokenCredential {
343 private msalFlow;
344 /**
345 * Creates an instance of the ClientCertificateCredential with the details
346 * needed to authenticate against Azure Active Directory with a certificate.
347 *
348 * @param tenantId - The Azure Active Directory tenant (directory) ID.
349 * @param clientId - The client (application) ID of an App Registration in the tenant.
350 * @param certificatePath - The path to a PEM-encoded public/private key certificate on the filesystem.
351 * @param options - Options for configuring the client which makes the authentication request.
352 */
353 constructor(tenantId: string, clientId: string, certificatePath: string, options?: ClientCertificateCredentialOptions);
354 /**
355 * Creates an instance of the ClientCertificateCredential with the details
356 * needed to authenticate against Azure Active Directory with a certificate.
357 *
358 * @param tenantId - The Azure Active Directory tenant (directory) ID.
359 * @param clientId - The client (application) ID of an App Registration in the tenant.
360 * @param configuration - Other parameters required, including the PEM-encoded certificate as a string, or as a path on the filesystem.
361 * If the type is ignored, we will throw if both the value of the PEM certificate and the path to a PEM certificate are provided at the same time.
362 * @param options - Options for configuring the client which makes the authentication request.
363 */
364 constructor(tenantId: string, clientId: string, configuration: ClientCertificateCredentialPEMConfiguration, options?: ClientCertificateCredentialOptions);
365 /**
366 * Authenticates with Azure Active Directory and returns an access token if successful.
367 * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
368 *
369 * @param scopes - The list of scopes for which the token will have access.
370 * @param options - The options used to configure any requests this
371 * TokenCredential implementation might make.
372 */
373 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
374}
375
376/**
377 * Optional parameters for the {@link ClientCertificateCredential} class.
378 */
379export declare interface ClientCertificateCredentialOptions extends TokenCredentialOptions, CredentialPersistenceOptions {
380 /**
381 * Option to include x5c header for SubjectName and Issuer name authorization.
382 * Set this option to send base64 encoded public certificate in the client assertion header as an x5c claim
383 */
384 sendCertificateChain?: boolean;
385}
386
387/**
388 * Required configuration options for the {@link ClientCertificateCredential}, with either the string contents of a PEM certificate, or the path to a PEM certificate.
389 */
390export declare type ClientCertificateCredentialPEMConfiguration = {
391 /**
392 * The PEM-encoded public/private key certificate on the filesystem.
393 */
394 certificate: string;
395 /**
396 * The PEM-encoded public/private key certificate on the filesystem should not be provided if `certificate` is provided.
397 */
398 certificatePath?: never;
399} | {
400 /**
401 * The PEM-encoded public/private key certificate on the filesystem should not be provided if `certificatePath` is provided.
402 */
403 certificate?: never;
404 /**
405 * The path to the PEM-encoded public/private key certificate on the filesystem.
406 */
407 certificatePath: string;
408};
409
410/**
411 * Enables authentication to Azure Active Directory using a client secret
412 * that was generated for an App Registration. More information on how
413 * to configure a client secret can be found here:
414 *
415 * https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-configure-app-access-web-apis#add-credentials-to-your-web-application
416 *
417 */
418export declare class ClientSecretCredential implements TokenCredential {
419 private msalFlow;
420 /**
421 * Creates an instance of the ClientSecretCredential with the details
422 * needed to authenticate against Azure Active Directory with a client
423 * secret.
424 *
425 * @param tenantId - The Azure Active Directory tenant (directory) ID.
426 * @param clientId - The client (application) ID of an App Registration in the tenant.
427 * @param clientSecret - A client secret that was generated for the App Registration.
428 * @param options - Options for configuring the client which makes the authentication request.
429 */
430 constructor(tenantId: string, clientId: string, clientSecret: string, options?: ClientSecretCredentialOptions);
431 /**
432 * Authenticates with Azure Active Directory and returns an access token if successful.
433 * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
434 *
435 * @param scopes - The list of scopes for which the token will have access.
436 * @param options - The options used to configure any requests this
437 * TokenCredential implementation might make.
438 */
439 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
440}
441
442/**
443 * Optional parameters for the {@link ClientSecretCredential} class.
444 */
445export declare interface ClientSecretCredentialOptions extends TokenCredentialOptions, CredentialPersistenceOptions {
446}
447
448/**
449 * Shared configuration options for credentials that support persistent token
450 * caching.
451 */
452export declare interface CredentialPersistenceOptions {
453 /**
454 * Options to provide to the persistence layer (if one is available) when
455 * storing credentials.
456 *
457 * You must first register a persistence provider plugin. See the
458 * `@azure/identity-cache-persistence` package on NPM.
459 *
460 * Example:
461 *
462 * ```javascript
463 * import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
464 * import { useIdentityPlugin, DeviceCodeCredential } from "@azure/identity";
465 *
466 * useIdentityPlugin(cachePersistencePlugin);
467 *
468 * async function main() {
469 * const credential = new DeviceCodeCredential({
470 * tokenCachePersistenceOptions: {
471 * enabled: true
472 * }
473 * });
474 * }
475 *
476 * main().catch((error) => {
477 * console.error("An error occurred:", error);
478 * process.exit(1);
479 * });
480 * ```
481 */
482 tokenCachePersistenceOptions?: TokenCachePersistenceOptions;
483}
484
485/**
486 * This signifies that the credential that was tried in a chained credential
487 * was not available to be used as the credential. Rather than treating this as
488 * an error that should halt the chain, it's caught and the chain continues
489 */
490export declare class CredentialUnavailableError extends Error {
491 constructor(message?: string);
492}
493
494/**
495 * The Error.name value of an CredentialUnavailable
496 */
497export declare const CredentialUnavailableErrorName = "CredentialUnavailableError";
498
499/**
500 * Provides a default {@link ChainedTokenCredential} configuration that should
501 * work for most applications that use the Azure SDK.
502 */
503export declare class DefaultAzureCredential extends ChainedTokenCredential {
504 /**
505 * Creates an instance of the DefaultAzureCredential class.
506 *
507 * This credential provides a default {@link ChainedTokenCredential} configuration that should
508 * work for most applications that use the Azure SDK.
509 *
510 * The following credential types will be tried, in order:
511 *
512 * - {@link EnvironmentCredential}
513 * - {@link ManagedIdentityCredential}
514 * - {@link VisualStudioCodeCredential}
515 * - {@link AzureCliCredential}
516 * - {@link AzurePowerShellCredential}
517 *
518 * Consult the documentation of these credential types for more information
519 * on how they attempt authentication.
520 *
521 * **Note**: `VisualStudioCodeCredential` is provided by a plugin package:
522 * `@azure/identity-vscode`. If this package is not installed and registered
523 * using the plugin API (`useIdentityPlugin`), then authentication using
524 * `VisualStudioCodeCredential` will not be available.
525 *
526 * @param options - Optional parameters. See {@link DefaultAzureCredentialOptions}.
527 */
528 constructor(options?: DefaultAzureCredentialOptions);
529}
530
531/**
532 * Provides options to configure the {@link DefaultAzureCredential} class.
533 */
534export declare interface DefaultAzureCredentialOptions extends TokenCredentialOptions {
535 /**
536 * Optionally pass in a Tenant ID to be used as part of the credential.
537 * By default it may use a generic tenant ID depending on the underlying credential.
538 */
539 tenantId?: string;
540 /**
541 * Optionally pass in a user assigned client ID to be used by the {@link ManagedIdentityCredential}.
542 * This client ID can also be passed through to the {@link ManagedIdentityCredential} through the environment variable: AZURE_CLIENT_ID.
543 */
544 managedIdentityClientId?: string;
545}
546
547/**
548 * Deserializes a previously serialized authentication record from a string into an object.
549 *
550 * The input string must contain the following properties:
551 *
552 * - "authority"
553 * - "homeAccountId"
554 * - "clientId"
555 * - "tenantId"
556 * - "username"
557 * - "version"
558 *
559 * If the version we receive is unsupported, an error will be thrown.
560 *
561 * At the moment, the only available version is: "1.0", which is always set when the authentication record is serialized.
562 *
563 * @param serializedRecord - Authentication record previously serialized into string.
564 * @returns AuthenticationRecord.
565 */
566export declare function deserializeAuthenticationRecord(serializedRecord: string): AuthenticationRecord;
567
568/**
569 * Enables authentication to Azure Active Directory using a device code
570 * that the user can enter into https://microsoft.com/devicelogin.
571 */
572export declare class DeviceCodeCredential implements TokenCredential {
573 private msalFlow;
574 private disableAutomaticAuthentication?;
575 /**
576 * Creates an instance of DeviceCodeCredential with the details needed
577 * to initiate the device code authorization flow with Azure Active Directory.
578 *
579 * A message will be logged, giving users a code that they can use to authenticate once they go to https://microsoft.com/devicelogin
580 *
581 * Developers can configure how this message is shown by passing a custom `userPromptCallback`:
582 *
583 * ```js
584 * const credential = new DeviceCodeCredential({
585 * tenantId: env.AZURE_TENANT_ID,
586 * clientId: env.AZURE_CLIENT_ID,
587 * userPromptCallback: (info) => {
588 * console.log("CUSTOMIZED PROMPT CALLBACK", info.message);
589 * }
590 * });
591 * ```
592 *
593 * @param options - Options for configuring the client which makes the authentication requests.
594 */
595 constructor(options?: DeviceCodeCredentialOptions);
596 /**
597 * Authenticates with Azure Active Directory and returns an access token if successful.
598 * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
599 *
600 * If the user provided the option `disableAutomaticAuthentication`,
601 * once the token can't be retrieved silently,
602 * this method won't attempt to request user interaction to retrieve the token.
603 *
604 * @param scopes - The list of scopes for which the token will have access.
605 * @param options - The options used to configure any requests this
606 * TokenCredential implementation might make.
607 */
608 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
609 /**
610 * Authenticates with Azure Active Directory and returns an access token if successful.
611 * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
612 *
613 * If the token can't be retrieved silently, this method will require user interaction to retrieve the token.
614 *
615 * @param scopes - The list of scopes for which the token will have access.
616 * @param options - The options used to configure any requests this
617 * TokenCredential implementation might make.
618 */
619 authenticate(scopes: string | string[], options?: GetTokenOptions): Promise<AuthenticationRecord | undefined>;
620}
621
622/**
623 * Defines options for the InteractiveBrowserCredential class for Node.js.
624 */
625export declare interface DeviceCodeCredentialOptions extends InteractiveCredentialOptions, CredentialPersistenceOptions {
626 /**
627 * The Azure Active Directory tenant (directory) ID.
628 */
629 tenantId?: string;
630 /**
631 * The client (application) ID of an App Registration in the tenant.
632 */
633 clientId?: string;
634 /**
635 * A callback function that will be invoked to show {@link DeviceCodeInfo} to the user.
636 * If left unassigned, we will automatically log the device code information
637 * and the authentication instructions in the console.
638 */
639 userPromptCallback?: DeviceCodePromptCallback;
640}
641
642/**
643 * Provides the user code and verification URI where the code must be
644 * entered. Also provides a message to display to the user which
645 * contains an instruction with these details.
646 */
647export declare interface DeviceCodeInfo {
648 /**
649 * The device code that the user must enter into the verification page.
650 */
651 userCode: string;
652 /**
653 * The verification URI to which the user must navigate to enter the device
654 * code.
655 */
656 verificationUri: string;
657 /**
658 * A message that may be shown to the user to instruct them on how to enter
659 * the device code in the page specified by the verification URI.
660 */
661 message: string;
662}
663
664/**
665 * Defines the signature of a callback which will be passed to
666 * DeviceCodeCredential for the purpose of displaying authentication
667 * details to the user.
668 */
669export declare type DeviceCodePromptCallback = (deviceCodeInfo: DeviceCodeInfo) => void;
670
671/**
672 * Enables authentication to Azure Active Directory using client secret
673 * details configured in environment variables
674 */
675export declare class EnvironmentCredential implements TokenCredential {
676 private _credential?;
677 /**
678 * Creates an instance of the EnvironmentCredential class and decides what credential to use depending on the available environment variables.
679 *
680 * Required environment variables:
681 * - `AZURE_TENANT_ID`: The Azure Active Directory tenant (directory) ID.
682 * - `AZURE_CLIENT_ID`: The client (application) ID of an App Registration in the tenant.
683 *
684 * Environment variables used for client credential authentication:
685 * - `AZURE_CLIENT_SECRET`: A client secret that was generated for the App Registration.
686 * - `AZURE_CLIENT_CERTIFICATE_PATH`: The path to a PEM certificate to use during the authentication, instead of the client secret.
687 *
688 * Alternatively, users can provide environment variables for username and password authentication:
689 * - `AZURE_USERNAME`: Username to authenticate with.
690 * - `AZURE_PASSWORD`: Password to authenticate with.
691 *
692 * If the environment variables required to perform the authentication are missing, a {@link CredentialUnavailableError} will be thrown.
693 * If the authentication fails, or if there's an unknown error, an {@link AuthenticationError} will be thrown.
694 *
695 * @param options - Options for configuring the client which makes the authentication request.
696 */
697 constructor(options?: EnvironmentCredentialOptions);
698 /**
699 * Authenticates with Azure Active Directory and returns an access token if successful.
700 *
701 * @param scopes - The list of scopes for which the token will have access.
702 * @param options - Optional parameters. See {@link GetTokenOptions}.
703 */
704 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
705}
706
707/**
708 * Enables authentication to Azure Active Directory depending on the available environment variables.
709 * Defines options for the EnvironmentCredential class.
710 */
711export declare interface EnvironmentCredentialOptions extends TokenCredentialOptions {
712}
713
714/**
715 * See the official documentation for more details:
716 *
717 * https://docs.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-oauth-code#error-response-1
718 *
719 * NOTE: This documentation is for v1 OAuth support but the same error
720 * response details still apply to v2.
721 */
722export declare interface ErrorResponse {
723 /**
724 * The string identifier for the error.
725 */
726 error: string;
727 /**
728 * The error's description.
729 */
730 errorDescription: string;
731 /**
732 * An array of codes pertaining to the error(s) that occurred.
733 */
734 errorCodes?: number[];
735 /**
736 * The timestamp at which the error occurred.
737 */
738 timestamp?: string;
739 /**
740 * The trace identifier for this error occurrence.
741 */
742 traceId?: string;
743 /**
744 * The correlation ID to be used for tracking the source of the error.
745 */
746 correlationId?: string;
747}
748
749/**
750 * Returns a new instance of the {@link DefaultAzureCredential}.
751 */
752export declare function getDefaultAzureCredential(): TokenCredential;
753
754export { GetTokenOptions }
755
756/**
757 * The type of an Azure Identity plugin, a function accepting a plugin
758 * context.
759 */
760export declare type IdentityPlugin = (context: unknown) => void;
761
762/**
763 * Enables authentication to Azure Active Directory inside of the web browser
764 * using the interactive login flow.
765 */
766export declare class InteractiveBrowserCredential implements TokenCredential {
767 private msalFlow;
768 private disableAutomaticAuthentication?;
769 /**
770 * Creates an instance of InteractiveBrowserCredential with the details needed.
771 *
772 * This credential uses the [Authorization Code Flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-auth-code-flow).
773 * On Node.js, it will open a browser window while it listens for a redirect response from the authentication service.
774 * On browsers, it authenticates via popups. The `loginStyle` optional parameter can be set to `redirect` to authenticate by redirecting the user to an Azure secure login page, which then will redirect the user back to the web application where the authentication started.
775 *
776 * For Node.js, if a `clientId` is provided, the Azure Active Directory application will need to be configured to have a "Mobile and desktop applications" redirect endpoint.
777 * Follow our guide on [setting up Redirect URIs for Desktop apps that calls to web APIs](https://docs.microsoft.com/azure/active-directory/develop/scenario-desktop-app-registration#redirect-uris).
778 *
779 * @param options - Options for configuring the client which makes the authentication requests.
780 */
781 constructor(options?: InteractiveBrowserCredentialNodeOptions | InteractiveBrowserCredentialInBrowserOptions);
782 /**
783 * Authenticates with Azure Active Directory and returns an access token if successful.
784 * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
785 *
786 * If the user provided the option `disableAutomaticAuthentication`,
787 * once the token can't be retrieved silently,
788 * this method won't attempt to request user interaction to retrieve the token.
789 *
790 * @param scopes - The list of scopes for which the token will have access.
791 * @param options - The options used to configure any requests this
792 * TokenCredential implementation might make.
793 */
794 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
795 /**
796 * Authenticates with Azure Active Directory and returns an access token if successful.
797 * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
798 *
799 * If the token can't be retrieved silently, this method will require user interaction to retrieve the token.
800 *
801 * On Node.js, this credential has [Proof Key for Code Exchange (PKCE)](https://datatracker.ietf.org/doc/html/rfc7636) enabled by default.
802 * PKCE is a security feature that mitigates authentication code interception attacks.
803 *
804 * @param scopes - The list of scopes for which the token will have access.
805 * @param options - The options used to configure any requests this
806 * TokenCredential implementation might make.
807 */
808 authenticate(scopes: string | string[], options?: GetTokenOptions): Promise<AuthenticationRecord | undefined>;
809}
810
811/**
812 * Defines the common options for the InteractiveBrowserCredential class.
813 */
814export declare interface InteractiveBrowserCredentialInBrowserOptions extends InteractiveCredentialOptions {
815 /**
816 * Gets the redirect URI of the application. This should be same as the value
817 * in the application registration portal. Defaults to `window.location.href`.
818 */
819 redirectUri?: string | (() => string);
820 /**
821 * The Azure Active Directory tenant (directory) ID.
822 */
823 tenantId?: string;
824 /**
825 * The client (application) ID of an App Registration in the tenant.
826 * This parameter is required on the browser.
827 */
828 clientId: string;
829 /**
830 * Specifies whether a redirect or a popup window should be used to
831 * initiate the user authentication flow. Possible values are "redirect"
832 * or "popup" (default) for browser and "popup" (default) for node.
833 *
834 */
835 loginStyle?: BrowserLoginStyle;
836 /**
837 * loginHint allows a user name to be pre-selected for interactive logins.
838 * Setting this option skips the account selection prompt and immediately attempts to login with the specified account.
839 */
840 loginHint?: string;
841}
842
843/**
844 * Defines the common options for the InteractiveBrowserCredential class.
845 */
846export declare interface InteractiveBrowserCredentialNodeOptions extends InteractiveCredentialOptions, CredentialPersistenceOptions {
847 /**
848 * Gets the redirect URI of the application. This should be same as the value
849 * in the application registration portal. Defaults to `window.location.href`.
850 */
851 redirectUri?: string | (() => string);
852 /**
853 * The Azure Active Directory tenant (directory) ID.
854 */
855 tenantId?: string;
856 /**
857 * The client (application) ID of an App Registration in the tenant.
858 */
859 clientId?: string;
860 /**
861 * loginHint allows a user name to be pre-selected for interactive logins.
862 * Setting this option skips the account selection prompt and immediately attempts to login with the specified account.
863 */
864 loginHint?: string;
865}
866
867/**
868 * Common constructor options for the Identity credentials that requires user interaction.
869 */
870export declare interface InteractiveCredentialOptions extends TokenCredentialOptions {
871 /**
872 * Result of a previous authentication that can be used to retrieve the cached credentials of each individual account.
873 * This is necessary to provide in case the application wants to work with more than one account per
874 * Client ID and Tenant ID pair.
875 *
876 * This record can be retrieved by calling to the credential's `authenticate()` method, as follows:
877 *
878 * const authenticationRecord = await credential.authenticate();
879 *
880 */
881 authenticationRecord?: AuthenticationRecord;
882 /**
883 * Makes getToken throw if a manual authentication is necessary.
884 * Developers will need to call to `authenticate()` to control when to manually authenticate.
885 */
886 disableAutomaticAuthentication?: boolean;
887}
888
889/**
890 * The AzureLogger used for all clients within the identity package
891 */
892export declare const logger: AzureLogger;
893
894/**
895 * Attempts authentication using a managed identity available at the deployment environment.
896 * This authentication type works in Azure VMs, App Service instances, Azure Functions applications,
897 * Azure Kubernetes Services, Azure Service Fabric instances and inside of the Azure Cloud Shell.
898 *
899 * More information about configuring managed identities can be found here:
900 * https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview
901 */
902export declare class ManagedIdentityCredential implements TokenCredential {
903 private identityClient;
904 private clientId;
905 private isEndpointUnavailable;
906 private isAvailableIdentityClient;
907 /**
908 * Creates an instance of ManagedIdentityCredential with the client ID of a
909 * user-assigned identity, or app registration (when working with AKS pod-identity).
910 *
911 * @param clientId - The client ID of the user-assigned identity, or app registration (when working with AKS pod-identity).
912 * @param options - Options for configuring the client which makes the access token request.
913 */
914 constructor(clientId: string, options?: TokenCredentialOptions);
915 /**
916 * Creates an instance of ManagedIdentityCredential
917 *
918 * @param options - Options for configuring the client which makes the access token request.
919 */
920 constructor(options?: TokenCredentialOptions);
921 private cachedMSI;
922 private cachedAvailableMSI;
923 private authenticateManagedIdentity;
924 /**
925 * Authenticates with Azure Active Directory and returns an access token if successful.
926 * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
927 * If an unexpected error occurs, an {@link AuthenticationError} will be thrown with the details of the failure.
928 *
929 * @param scopes - The list of scopes for which the token will have access.
930 * @param options - The options used to configure any requests this
931 * TokenCredential implementation might make.
932 */
933 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
934}
935
936/**
937 * Enables authentication to Azure Active Directory using the [On Behalf Of flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow).
938 */
939export declare class OnBehalfOfCredential implements TokenCredential {
940 private options;
941 private msalFlow;
942 /**
943 * Creates an instance of the {@link OnBehalfOfCredential} with the details
944 * needed to authenticate against Azure Active Directory with a client
945 * secret or a path to a PEM certificate, and an user assertion.
946 *
947 * Example using the `KeyClient` from [\@azure/keyvault-keys](https://www.npmjs.com/package/\@azure/keyvault-keys):
948 *
949 * ```ts
950 * const tokenCredential = new OnBehalfOfCredential({
951 * tenantId,
952 * clientId,
953 * clientSecret, // or `certificatePath: "/path/to/certificate.pem"
954 * userAssertionToken: "access-token"
955 * });
956 * const client = new KeyClient("vault-url", tokenCredential);
957 *
958 * await client.getKey("key-name");
959 * ```
960 *
961 * @param options - Optional parameters, generally common across credentials.
962 */
963 constructor(options: OnBehalfOfCredentialOptions);
964 /**
965 * Authenticates with Azure Active Directory and returns an access token if successful.
966 * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
967 *
968 * @param scopes - The list of scopes for which the token will have access.
969 * @param options - The options used to configure the underlying network requests.
970 */
971 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
972}
973
974/**
975 * Defines the parameters to authenticate the {@link OnBehalfOfCredential} with a certificate.
976 */
977export declare interface OnBehalfOfCredentialCertificateOptions {
978 /**
979 * The Azure Active Directory tenant (directory) ID.
980 */
981 tenantId: string;
982 /**
983 * The client (application) ID of an App Registration in the tenant.
984 */
985 clientId: string;
986 /**
987 * The path to a PEM-encoded public/private key certificate on the filesystem.
988 */
989 certificatePath: string;
990 /**
991 * Option to include x5c header for SubjectName and Issuer name authorization.
992 * Set this option to send base64 encoded public certificate in the client assertion header as an x5c claim
993 */
994 sendCertificateChain?: boolean;
995 /**
996 * The user assertion for the On-Behalf-Of flow.
997 */
998 userAssertionToken: string;
999 /**
1000 * Client secret should not be provided when certificate options are provided.
1001 */
1002 clientSecret?: never;
1003}
1004
1005/**
1006 * Optional parameters for the {@link OnBehalfOfCredential} class.
1007 */
1008export declare type OnBehalfOfCredentialOptions = (OnBehalfOfCredentialSecretOptions | OnBehalfOfCredentialCertificateOptions) & TokenCredentialOptions & CredentialPersistenceOptions;
1009
1010/**
1011 * Defines the parameters to authenticate the {@link OnBehalfOfCredential} with a secret.
1012 */
1013export declare interface OnBehalfOfCredentialSecretOptions {
1014 /**
1015 * The Azure Active Directory tenant (directory) ID.
1016 */
1017 tenantId: string;
1018 /**
1019 * The client (application) ID of an App Registration in the tenant.
1020 */
1021 clientId: string;
1022 /**
1023 * A client secret that was generated for the App Registration.
1024 */
1025 clientSecret: string;
1026 /**
1027 * The user assertion for the On-Behalf-Of flow.
1028 */
1029 userAssertionToken: string;
1030 /**
1031 * The path to a PEM-encoded certificate should not be provided when the secret options are provided.
1032 */
1033 certificatePath?: never;
1034 /**
1035 * Option to include x5c header should not be provided when the secret options are provided.
1036 */
1037 sendCertificateChain?: never;
1038}
1039
1040/**
1041 * Serializes an `AuthenticationRecord` into a string.
1042 *
1043 * The output of a serialized authentication record will contain the following properties:
1044 *
1045 * - "authority"
1046 * - "homeAccountId"
1047 * - "clientId"
1048 * - "tenantId"
1049 * - "username"
1050 * - "version"
1051 *
1052 * To later convert this string to a serialized `AuthenticationRecord`, please use the exported function `deserializeAuthenticationRecord()`.
1053 */
1054export declare function serializeAuthenticationRecord(record: AuthenticationRecord): string;
1055
1056/**
1057 * Parameters that enable token cache persistence in the Identity credentials.
1058 */
1059export declare interface TokenCachePersistenceOptions {
1060 /**
1061 * If set to true, persistent token caching will be enabled for this credential instance.
1062 */
1063 enabled: boolean;
1064 /**
1065 * Unique identifier for the persistent token cache.
1066 *
1067 * Based on this identifier, the persistence file will be located in any of the following places:
1068 * - Darwin: '/Users/user/.IdentityService/<name>'
1069 * - Windows 8+: 'C:\\Users\\user\\AppData\\Local\\.IdentityService\\<name>'
1070 * - Linux: '/home/user/.IdentityService/<name>'
1071 */
1072 name?: string;
1073 /**
1074 * If set to true, the cache will be stored without encryption if no OS level user encryption is available.
1075 * When set to false, the PersistentTokenCache will throw an error if no OS level user encryption is available.
1076 */
1077 unsafeAllowUnencryptedStorage?: boolean;
1078}
1079
1080export { TokenCredential }
1081
1082/**
1083 * Provides options to configure how the Identity library makes authentication
1084 * requests to Azure Active Directory.
1085 */
1086export declare interface TokenCredentialOptions extends CommonClientOptions {
1087 /**
1088 * The authority host to use for authentication requests.
1089 * Possible values are available through {@link AzureAuthorityHosts}.
1090 * The default is "https://login.microsoftonline.com".
1091 */
1092 authorityHost?: string;
1093}
1094
1095/**
1096 * Extend Azure Identity with additional functionality. Pass a plugin from
1097 * a plugin package, such as:
1098 *
1099 * - `@azure/identity-cache-persistence`: provides persistent token caching
1100 * - `@azure/identity-vscode`: provides the dependencies of
1101 * `VisualStudioCodeCredential` and enables it
1102 *
1103 * Example:
1104 *
1105 * ```javascript
1106 * import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
1107 *
1108 * import { useIdentityPlugin, DefaultAzureCredential } from "@azure/identity";
1109 * useIdentityPlugin(cachePersistencePlugin);
1110 *
1111 * // The plugin has the capability to extend `DefaultAzureCredential` and to
1112 * // add middleware to the underlying credentials, such as persistence.
1113 * const credential = new DefaultAzureCredential({
1114 * tokenCachePersistenceOptions: {
1115 * enabled: true
1116 * }
1117 * });
1118 * ```
1119 *
1120 * @param plugin - the plugin to register
1121 */
1122export declare function useIdentityPlugin(plugin: IdentityPlugin): void;
1123
1124/**
1125 * Enables authentication to Azure Active Directory with a user's
1126 * username and password. This credential requires a high degree of
1127 * trust so you should only use it when other, more secure credential
1128 * types can't be used.
1129 */
1130export declare class UsernamePasswordCredential implements TokenCredential {
1131 private msalFlow;
1132 /**
1133 * Creates an instance of the UsernamePasswordCredential with the details
1134 * needed to authenticate against Azure Active Directory with a username
1135 * and password.
1136 *
1137 * @param tenantId - The Azure Active Directory tenant (directory).
1138 * @param clientId - The client (application) ID of an App Registration in the tenant.
1139 * @param username - The user account's e-mail address (user name).
1140 * @param password - The user account's account password
1141 * @param options - Options for configuring the client which makes the authentication request.
1142 */
1143 constructor(tenantId: string, clientId: string, username: string, password: string, options?: UsernamePasswordCredentialOptions);
1144 /**
1145 * Authenticates with Azure Active Directory and returns an access token if successful.
1146 * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
1147 *
1148 * If the user provided the option `disableAutomaticAuthentication`,
1149 * once the token can't be retrieved silently,
1150 * this method won't attempt to request user interaction to retrieve the token.
1151 *
1152 * @param scopes - The list of scopes for which the token will have access.
1153 * @param options - The options used to configure any requests this
1154 * TokenCredential implementation might make.
1155 */
1156 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
1157}
1158
1159/**
1160 * Defines options for the {@link UsernamePasswordCredential} class.
1161 */
1162export declare interface UsernamePasswordCredentialOptions extends TokenCredentialOptions, CredentialPersistenceOptions {
1163}
1164
1165/**
1166 * Connects to Azure using the credential provided by the VSCode extension 'Azure Account'.
1167 * Once the user has logged in via the extension, this credential can share the same refresh token
1168 * that is cached by the extension.
1169 */
1170export declare class VisualStudioCodeCredential implements TokenCredential {
1171 private identityClient;
1172 private tenantId;
1173 private cloudName;
1174 /**
1175 * Creates an instance of VisualStudioCodeCredential to use for automatically authenticating via VSCode.
1176 *
1177 * **Note**: `VisualStudioCodeCredential` is provided by a plugin package:
1178 * `@azure/identity-vscode`. If this package is not installed and registered
1179 * using the plugin API (`useIdentityPlugin`), then authentication using
1180 * `VisualStudioCodeCredential` will not be available.
1181 *
1182 * @param options - Options for configuring the client which makes the authentication request.
1183 */
1184 constructor(options?: VisualStudioCodeCredentialOptions);
1185 /**
1186 * Runs preparations for any further getToken request.
1187 */
1188 private prepare;
1189 /**
1190 * The promise of the single preparation that will be executed at the first getToken request for an instance of this class.
1191 */
1192 private preparePromise;
1193 /**
1194 * Runs preparations for any further getToken, but only once.
1195 */
1196 private prepareOnce;
1197 /**
1198 * Returns the token found by searching VSCode's authentication cache or
1199 * returns null if no token could be found.
1200 *
1201 * @param scopes - The list of scopes for which the token will have access.
1202 * @param options - The options used to configure any requests this
1203 * `TokenCredential` implementation might make.
1204 */
1205 getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
1206}
1207
1208/**
1209 * Provides options to configure the Visual Studio Code credential.
1210 */
1211export declare interface VisualStudioCodeCredentialOptions extends TokenCredentialOptions {
1212 /**
1213 * Optionally pass in a Tenant ID to be used as part of the credential
1214 */
1215 tenantId?: string;
1216}
1217
1218export { }
1219
\No newline at end of file