@mattbillfred/mgt-msal2-provider
Version:
The Microsoft Graph Toolkit Msal 2.0 Provider
403 lines • 9.92 kB
TypeScript
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { IProvider, LoginType, IProviderAccount, GraphEndpoint } from '@microsoft/mgt-element';
import { Configuration, PublicClientApplication, AccountInfo } from '@azure/msal-browser';
import { AuthenticationProviderOptions } from '@microsoft/microsoft-graph-client';
/**
* base config for MSAL 2.0 authentication
*
* @export
* @interface Msal2ConfigBase
*/
interface Msal2ConfigBase {
/**
* Redirect URI
*
* @type {string}
* @memberof Msal2Config
*/
redirectUri?: string;
/**
* Authority URL
*
* @type {string}
* @memberof Msal2Config
*/
authority?: string;
/**
* Other options
*
* @type {Configuration}
* @memberof Msal2Config
*/
options?: Configuration;
/**
* List of scopes required
*
* @type {string[]}
* @memberof Msal2ConfigBase
*/
scopes?: string[];
/**
* loginType if login uses popup
*
* @type {LoginType}
* @memberof Msal2ConfigBase
*/
loginType?: LoginType;
/**
* login hint value
*
* @type {string}
* @memberof Msal2ConfigBase
*/
loginHint?: string;
/**
* Domain hint value
*
* @type {string}
* @memberof Msal2ConfigBase
*/
domainHint?: string;
/**
* Prompt type
*
* @type {string}
* @memberof Msal2ConfigBase
*/
prompt?: PromptType;
/**
* Session ID
*
* @type {string}
* @memberof Msal2Config
*/
sid?: string;
/**
* Specifies if incremental consent is disabled
*
* @type {boolean}
* @memberof Msal2ConfigBase
*/
isIncrementalConsentDisabled?: boolean;
/**
* Disable multi account functionality
*
* @type {boolean}
* @memberof Msal2Config
*/
isMultiAccountDisabled?: boolean;
}
/**
* Config for MSAL2.0 Authentication
*
* @export
* @interface Msal2Config
*/
export interface Msal2Config extends Msal2ConfigBase {
/**
* Client ID of app registration
*
* @type {boolean}
* @memberof Msal2Config
*/
clientId: string;
/**
* Disable multi account functionality
*
* @type {boolean}
* @memberof Msal2Config
*/
isMultiAccountEnabled?: boolean;
/**
* The base URL for the graph client
*/
baseURL?: GraphEndpoint;
/**
* CustomHosts
*
* @type {string[]}
* @memberof Msal2Config
*/
customHosts?: string[];
}
/**
* Config for MSAL 2.0 Authentication where a PublicClientApplication already exists
*
* @export
* @interface Msal2PublicClientApplicationConfig
*/
export interface Msal2PublicClientApplicationConfig extends Msal2ConfigBase {
/**
* Existing PublicClientApplication instance to use
*
* @type {PublicClientApplication}
* @memberof Msal2PublicClientApplicationConfig
*/
publicClientApplication: PublicClientApplication;
}
/**
* Prompt type enum
*
* @export
* @enum {number}
*/
export declare enum PromptType {
SELECT_ACCOUNT = "select_account",
LOGIN = "login",
CONSENT = "consent"
}
/**
* MSAL2Provider using msal-browser to acquire tokens for authentication
*
* @export
* @class Msal2Provider
* @extends {IProvider}
*/
export declare class Msal2Provider extends IProvider {
private _publicClientApplication;
/**
* Login type, Either Redirect or Popup
*
* @private
* @type {LoginType}
* @memberof Msal2Provider
*/
private _loginType;
/**
* Login hint, if provided
*
* @private
* @memberof Msal2Provider
*/
private _loginHint;
/**
* Domain hint if provided
*
* @private
* @memberof Msal2Provider
*/
private _domainHint;
/**
* Prompt type
*
* @private
* @type {string}
* @memberof Msal2Provider
*/
private _prompt;
/**
* Session ID, if provided
*
* @private
* @memberof Msal2Provider
*/
private _sid;
/**
* Configuration settings for authentication
*
* @private
* @type {Configuration}
* @memberof Msal2Provider
*/
private ms_config;
/**
* Gets the PublicClientApplication Instance
*
* @private
* @type {PublicClientApplication}
* @memberof Msal2Provider
*/
get publicClientApplication(): PublicClientApplication;
/**
* Name used for analytics
*
* @readonly
* @memberof IProvider
*/
get name(): string;
/**
* List of scopes
*
* @type {string[]}
* @memberof Msal2Provider
*/
scopes: string[];
/**
* Enables multi account functionality if true, disables if false
*
* @private
* @type {boolean}
* @memberof Msal2Provider
*/
isMultipleAccountEnabled: boolean;
/**
* Indicates if multi account functionality is disabled
*
* @protected
* @type {boolean}
* @memberof Msal2Provider
*/
protected get isMultiAccountDisabled(): boolean;
/**
* Disables or enables multi account functionality
* Uses isMultipleAccountEnabled as the backing property
* Property provided to ensure adherence to the IProvider interface
*
* @protected
* @memberof Msal2Provider
*/
protected set isMultiAccountDisabled(value: boolean);
/**
* Specifies if Multi account functionality is supported by the provider and enabled.
*
* @readonly
* @type {boolean}
* @memberof IProvider
*/
get isMultiAccountSupportedAndEnabled(): boolean;
private get sessionStorageRequestedScopesKey();
private get sessionStorageDeniedScopesKey();
private get homeAccountKey();
constructor(config: Msal2Config | Msal2PublicClientApplicationConfig);
/**
* Initialize provider with configuration details
*
* @private
* @param {Msal2Config} config
* @memberof Msal2Provider
*/
private initProvider;
/**
* Attempts to sign in user silently
*
* @memberof Msal2Provider
*/
trySilentSignIn(): Promise<void>;
/**
* Log in the user
*
* @return {*} {Promise<void>}
* @memberof Msal2Provider
*/
login(): Promise<void>;
/**
* Get all signed in accounts
*
* @return {*}
* @memberof Msal2Provider
*/
getAllAccounts(): IProviderAccount[];
/**
* Switching between accounts
*
* @param {*} user
* @memberof Msal2Provider
*/
setActiveAccount(user: IProviderAccount): void;
/**
* Gets active account
*
* @return {*}
* @memberof Msal2Provider
*/
getActiveAccount(): IProviderAccount;
/**
* Once a succesful login occurs, set the active account and store it
*
* @param {(AuthenticationResult | null)} account
* @memberof Msal2Provider
*/
handleResponse(account: AccountInfo): void;
private storage;
/**
* Store the currently signed in account in storage
*
* @private
* @memberof Msal2Provider
*/
private setStoredAccount;
/**
* Get the stored account from storage
*
* @private
* @return {*}
* @memberof Msal2Provider
*/
private getStoredAccount;
/**
* Clears the stored account from storage
*
* @private
* @memberof Msal2Provider
*/
private clearStoredAccount;
/**
* Adds scopes that have already been requested to sessionstorage
*
* @protected
* @param {string[]} scopes
* @memberof Msal2Provider
*/
protected setRequestedScopes(scopes: string[]): void;
/**
* Adds denied scopes to session storage
*
* @protected
* @param {string[]} scopes
* @memberof Msal2Provider
*/
protected addDeniedScopes(scopes: string[]): void;
/**
* Gets denied scopes
*
* @protected
* @return {*}
* @memberof Msal2Provider
*/
protected getDeniedScopes(): string[];
/**
* Checks if scopes were denied previously
*
* @protected
* @param {string[]} scopes
* @return {*}
* @memberof Msal2Provider
*/
protected areScopesDenied(scopes: string[]): boolean;
/**
* Clears all requested scopes from session storage
*
* @protected
* @memberof Msal2Provider
*/
protected clearRequestedScopes(): void;
/**
* Gets stored account if available, otherwise fetches the first account in the list of signed in accounts
*
* @private
* @return {*} {(AccountInfo | null)}
* @memberof Msal2Provider
*/
protected getAccount(): AccountInfo | null;
/**
* Logs out user
*
* @memberof Msal2Provider
*/
logout(): Promise<void>;
/**
* Returns access token for scopes
*
* @param {AuthenticationProviderOptions} [options]
* @return {*} {Promise<string>}
* @memberof Msal2Provider
*/
getAccessToken(options?: AuthenticationProviderOptions): Promise<string>;
}
export {};
//# sourceMappingURL=Msal2Provider.d.ts.map