An Electron desktop application authenticating users and calling Microsoft Graph API via OAuth 2.0 authorization code flow using MSAL Node
page_type: sample
languages:
This sample demonstrates how to use MSAL Node to sign-in a user and acquire an access token for a protected resource such as Microsoft Graph in an Electron desktop application using the authorization code grant with PKCE flow.
This sample backs the following articles on Microsoft Docs:
Looking for a TypeScript implementation? See: ElectronTestApp
Looking for an Electron with React implementation? See: ElectronSystemBrowserTestApp
This sample does not implement persistent caching. See Caching with MSAL Node for more information.
This sample demonstrates the following MSAL Node concepts:
File/folder | Description |
---|---|
AppCreationScripts/ |
Contains Powershell scripts for automating app registration. |
App/authProvider.js |
Main authentication logic resides here. |
App/main.js |
Application main process. |
App/graph.js |
Instantiates Graph SDK client. |
App/renderer.js |
Renderer processes and UI methods. |
App/constants.js |
Example user accounts in JSON . |
App/preload.js |
Give the Renderer process controlled access to some Node API. |
App/authConfig.js |
Configuration objects to be passed to MSAL instance. |
msal-node-desktop
.http://localhost
An opaque, reliable login hint claim. This claim is the best value to use for the login_hint OAuth parameter in all flows to get SSO. See $optional claims for more details.
Clone this repository git clone https://github.com/Azure-Samples/ms-identity-javascript-nodejs-desktop.git
Enter_the_Application_Id_Here
with your app/client ID on Microsoft Entra admin center.Enter_the_Tenant_Info_Here
with your tenant ID on Microsoft Entra admin center.Enter_the_Cloud_Instance_Id_Here
with https://login.microsoftonline.com/
(include the trailing slash).Enter_the_Graph_Endpoint_Here
. with https://graph.microsoft.com/
(include the trailing slash).
cd ms-identity-javascript-nodejs-desktop
npm install
npm start
If you’d like to contribute to this sample, see CONTRIBUTING.MD.
This project has adopted the Microsoft Open Source Code of Conduct.
For more information see the Code of Conduct FAQ or
contact opencode@microsoft.com with any additional questions or comments.