@equinor/fusion-framework-module-msal-node
Version:
Fusion Framework module for secure Azure AD authentication in Node.js using MSAL. Supports interactive, silent, and token-only authentication modes with encrypted token storage.
69 lines (68 loc) • 2.77 kB
TypeScript
import type { DeviceCodeRequest } from '@azure/msal-node';
import type { AuthenticationResult, PublicClientApplication } from '@azure/msal-node';
import { AuthProvider } from './AuthProvider.js';
/**
* Authentication provider that uses the OAuth 2.0 device code flow.
*
* When an access token cannot be acquired silently, the provider calls
* `acquireTokenByDeviceCode` and invokes `deviceCodeCallback` with the
* response containing `userCode`, `verificationUri`, and `message`.
* The user opens the URL on any device, enters the code, and authenticates.
* No local HTTP server is required, making this the recommended mode for CLI tools.
*
* @example
* ```ts
* const provider = new AuthProviderDeviceCode(msalClient, {
* deviceCodeCallback: (response) => console.log(response.message),
* });
* ```
*
* @see AuthProviderInteractive - Browser-based login with a local callback server.
* @see AuthProvider - Silent-only provider (base class).
*/
export declare class AuthProviderDeviceCode extends AuthProvider {
#private;
/**
* Creates an instance of `AuthProviderDeviceCode`.
*
* @param client - The MSAL `PublicClientApplication` to use for token acquisition.
* @param options - Configuration options.
* @param options.deviceCodeCallback - Callback invoked with the device code response.
* Defaults to printing `response.message` to `console.log`.
*/
constructor(client: PublicClientApplication, options?: {
deviceCodeCallback?: DeviceCodeRequest['deviceCodeCallback'];
});
/**
* Acquires an access token for the specified scopes.
*
* First attempts silent acquisition using the cached account.
* If that fails (e.g. no account or new resource requiring consent),
* falls back to the device code flow — invoking `deviceCodeCallback` so
* the user can authenticate on any device.
*
* @param options - Token request options.
* @param options.request.scopes - OAuth 2.0 scopes to request.
* @returns A promise resolving to an `AuthenticationResult`.
* @throws {@link SilentTokenAcquisitionError} If device code acquisition also fails.
*/
acquireToken(options: {
request: {
scopes: string[];
};
}): Promise<AuthenticationResult>;
/**
* Initiates the device code login flow explicitly.
*
* This is equivalent to calling `acquireToken` and is provided to satisfy
* the `IAuthProvider` contract.
*
* @param options - Login options containing the requested scopes.
* @returns A promise resolving to an `AuthenticationResult`.
*/
login(options: {
request: {
scopes: string[];
};
}): Promise<AuthenticationResult>;
}