page_type | languages | products | description | urlFragment | |||||
---|---|---|---|---|---|---|---|---|---|
sample |
|
|
Demonstrates how to use MSAL Node to sign-in users and acquire access tokens for a protected resource such as Microsoft Graph in an Electron desktop application using the OAuth 2.0 authorization code flow with PKCE. |
ms-identity-javascript-nodejs-desktop |
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.
ℹ️ Looking for a TypeScript implementation? See: ElectronTestApp
This sample demonstrates the following MSAL Node concepts:
- Configuration
- Login and logout
- Acquiring an access token
- Calling a web API
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/fetch.js |
Axios HTTP client for calling endpoints with a bearer token. |
App/renderer.js |
Renderer processes and UI methods. |
App/constants.js |
Example user accounts in JSON . |
App/CustomProtocolListener.js |
Register and unregister a custom typed protocol. |
App/UIManager.js |
Application UI and elements. |
App/preload.js |
Give the Renderer process controlled access to some Node API. |
App/authConfig.js |
Configuration objects to be passed to MSAL instanc. |
- Node.js must be installed to run this sample.
- Visual Studio Code is recommended for running and editing this sample.
- 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 any organizational directory and personal Microsoft accounts (e.g. Skype, Xbox, Outlook.com).
- 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
msal{Your_Application/Client_Id}}://auth
. - Select Configure.
Clone this repository git clone https://github.com/Azure-Samples/ms-identity-javascript-nodejs-desktop.git
- Open the .authConfig.js file and provide the required configuration values.
- Replace the string
Enter_the_Application_Id_Here
with your app/client ID on Azure AD portal. - Replace the string
Enter_the_Tenant_Info_Here
with your tenant ID on Azure AD portal. - Replace the string
Enter_the_Redirect_Uri_Here
with the default redirect uri generated by portalmsal{Your_Application/Client_Id}://auth
- Replace the string
Enter_the_Cloud_Instance_Id_Here
withhttps://login.microsoftonline.com/
(see note below). - Replace the string
Enter_the_Graph_Endpoint_Here
. withhttps://graph.microsoft.com/
(see note below).
- Replace the string
ℹ️ note: This is for multi-tenant applications located on the Global Azure cloud. For more information, see: Use MSAL in a national cloud environment
ℹ️ note: This is for MS Graph instance located on the Global Azure cloud. For more information, see: Use Microsoft Graph in a national cloud environment
-
You'll need to install the dependencies of this sample once:
cd ms-identity-javascript-nodejs-desktop npm install
-
Then, run the application via command prompt or console:
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 [email protected] with any additional questions or comments.