MSAL Node Electron Sample that integrates MSAL Node Extensions to enable cache persistence
June 16, 2026 ยท View on GitHub
This is a sample that depicts how to integrate the msal-node-extensions library to your electron application that has been bundled by webpack.
How to run the samples
Clone this repository
SSH:
git clone git@github.com:AzureAD/microsoft-authentication-library-for-js.git
HTTP:
git clone https://github.com/AzureAD/microsoft-authentication-library-for-js.git
You can also download the repository as a zip file by selecting "Download ZIP" from the root repository's dropdown "Code" menu. Once you've downloaded the ZIP file, you can decompress it locally and explore the code (see: Register the application).
Pre-requisites
- By using MSAL Node, you are working with the Microsoft Identity ecosystem. Read about App Registrations and register one for use with this code.
- Install Node.js (version
>=22.12.0is required), Electron.js and TypeScript if needed. - Import Electron forge CLI
- Install the MSAL Node package:
npm install @azure/msal-node
npm install @azure/msal-node-extensions
- If you are customizing or building locally, navigate to the
lib/msal-nodedirectory and build it using the following command:
npm run build:package
- From the repository's root directory, navigate to the Electron sample application:
cd extensions/samples/electron-webapp
Register the application
- Navigate to the Azure portal and select the Azure AD service.
- Select the App Registrations blade on the left, then select New registration.
- In the Name section, enter a meaningful application name that will be displayed to users of the app, for example
msal-node-desktop. - In the Supported account types section, select Accounts in this organizational directory only.
- Select Register to create the application.
- In the Name section, enter a meaningful application name that will be displayed to users of the app, for example
- In the list of pages for the app, select Authentication.
- Select Add a platform, select Mobile and desktop applications.
- In the Redirect URIs list, under Suggested Redirect URIs for (mobile, desktop) be sure to add
http://localhostto the list of Redirect URIs. - Select Configure.
Configure the application
- Open the .authConfig.ts file and provide the required configuration values.
- Replace the string
Enter_the_Application_Id_Herewith your app/client ID on Azure AD portal. - Replace the string
Enter_the_Tenant_Info_Herewith your tenant ID on Azure AD portal. - Replace the string
Enter_the_Cloud_Instance_Id_Herewithhttps://login.microsoftonline.com.
- Replace the string
Executing the application
Once you are in the sample application directory and you've configured the sample application to match your App Registration and registered Redirect URI, you can install all of the dependencies by running:
cd extensions/samples/electron-webapp
npm install
npm start