### Install Dependencies and Start Application Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/extensions/samples/electron-webpack/README.md Install all project dependencies and start the Electron application. Ensure the application is configured correctly before running. ```bash cd extensions/samples/electron-webapp npm install npm start ``` -------------------------------- ### Install Dependencies and Run Development Server Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/OfficeAddin/README.md Navigate to the OfficeAddin sample directory and install dependencies using npm. Then, start the development server to host the add-in. ```bash # Navigate to the OfficeAddin sample directory cd samples/msal-browser-samples/OfficeAddin # Install sample dependencies npm install ``` ```bash npm run dev-server ``` -------------------------------- ### Install Dependencies Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/auth-code/README.md This command installs all the necessary dependencies for the Node.js application. It should be run once before starting the application. ```bash $ npm install ``` -------------------------------- ### Start the Application Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/auth-code-with-certs/README.md Execute this command to start the local server on port 3000. ```console npm start ``` -------------------------------- ### Start Electron Sample App (Redirect) Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/ElectronSystemBrowserTestApp/README.md Navigate to the redirect directory and start the Electron sample application. ```bash cd samples/msal-node-samples/standalone-samples/ElectronSystemBrowserTestApp/redirect $ npm start ``` -------------------------------- ### Core Flow Configuration Examples Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/NativeAuthSample/context/APP_FLOW_REFERENCE.md These examples demonstrate how to configure the application for different authentication flows using URL query parameters. ```html ?usePwdConfig=true ``` ```html ?useOtpConfig=true ``` ```html ?usePwdConfig=true&useMFA=true ``` ```html ?useOtpConfig=true&useRedirectConfig=true ``` -------------------------------- ### Install and Build MSAL.js Next.js Sample Dependencies Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-react-samples/nextjs-sample/README.md Commands to install dependencies and build the required packages from the repository root. ```bash # Install dev dependencies for msal-react and msal-browser from root of repo npm install # Change directory to sample directory cd samples/msal-react-samples/nextjs-sample # Build packages locally npm run build:package ``` -------------------------------- ### Start Electron Sample App (Root) Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/ElectronSystemBrowserTestApp/README.md Start the Electron sample application from the app's root directory. ```bash cd samples/msal-node-samples/ElectronSystemBrowserTestApp npm start ``` -------------------------------- ### Install Dependencies Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/auth-code-with-certs/README.md Run this command in the project root to install required packages. ```console npm install ``` -------------------------------- ### Start Development Server Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/NativeAuthSample/README.md Start the development server to run the application. The default URL is http://localhost:30670. ```bash npm start ``` -------------------------------- ### Install Dependencies for Web API Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/on-behalf-of/README.md Navigate to the 'web-api' folder and run this command to install project dependencies. ```bash cd ../web-api npm install ``` -------------------------------- ### Start the Application Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/auth-code/README.md This command starts the Node.js sample application. After running this, navigate to the specified local host address in your browser to interact with the application. ```bash $ npm start ``` -------------------------------- ### Install and Build MSAL React Sample Dependencies Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-react-samples/react17-sample/README.md Commands to install dependencies, navigate to the sample directory, and build the required packages locally. ```bash # Install dev dependencies for msal-react and msal-browser from root of repo npm install # Change directory to sample directory cd samples/msal-react-samples/react17-sample # Build packages locally npm run build:package ``` -------------------------------- ### Install Vite and React Plugin Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-react/docs/migration-guide-v4-v5.md Remove react-scripts and install Vite with the React plugin for a modern build setup. ```bash npm uninstall react-scripts npm install --save-dev vite @vitejs/plugin-react ``` -------------------------------- ### Install npm dependencies for MSAL.js Express Sample Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/ExpressSample/README.md Install development dependencies from the root of the repository, then navigate to the sample directory and install its specific dependencies. Finally, build local packages. ```bash # Install dev dependencies for msal-browser from root of repo npm install # Change directory to sample directory cd samples/msal-browser-samples/ExpressSample # Install sample dependencies npm install # Build packages locally npm run build:package ``` -------------------------------- ### Install Dependencies with npm Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/auth-code-cli-brokered-app/README.md Run this command in the project directory to install necessary packages. ```console npm install ``` -------------------------------- ### Start Web App Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/on-behalf-of/README.md Navigate to the web app directory and run this command to start the web application. Ensure you are in the correct directory before executing. ```bash cd ../web-app npm start ``` -------------------------------- ### Start Web API Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/on-behalf-of/README.md Run this command in the terminal to start the web API application. ```bash npm start ``` -------------------------------- ### Install MSAL.js Dependencies and Build Sample Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-react-samples/b2c-sample/README.md Commands to install development dependencies, navigate to the sample directory, and build local packages for MSAL.js. ```bash npm install cd samples/msal-react-samples/b2c-sample npm run build:package ``` -------------------------------- ### Example URLs for Authentication Flows Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/NativeAuthSample/README.md Examples of URLs to test different authentication flows by appending query parameters to the base URL. ```bash http://localhost:30670/?usePwdConfig=true # Email + Password http://localhost:30670/?useOtpConfig=true # Email + OTP http://localhost:30670/?usePwdConfig=true&useMFA=true # With MFA ``` -------------------------------- ### v3 Request Example: GET with Extra Parameters Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/v4-migration.md Shows the previous method of configuring extra parameters for a GET request in v3, including parameters for both query strings and token request bodies. ```javascript // Example of a GET request with extra parameters const authRequest = { scopes: ["SAMPLE_SCOPE"], extraQueryParamters: { "dc": "DC_VALUE" // This was sent on the query string on GET /authorize }, tokenBodyParameters: { "extra_parameters_assertion": "ASSERTION_VALUE" // This was sent on the POST body to /token }, tokenQueryParamters: { "slice": "SLICE_VALUE" // This was sent on the query string on POST /token } } ``` -------------------------------- ### Install Dependencies and Run Tests Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/TestingSample/Readme.md Install project dependencies and run the Playwright tests. ```bash # Install dependencies npm install # Run tests using Playwright npm test ``` -------------------------------- ### Install Dependencies for Electron App Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/ElectronSystemBrowserTestApp/README.md Install all project dependencies for the Electron sample application. ```bash npm install ``` -------------------------------- ### Install Dependencies Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/NativeAuthSample/README.md Install project dependencies using npm. ```bash npm install ``` -------------------------------- ### Clone and configure the repository Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/contributing.md Initial setup commands to clone the repository and configure the upstream remote. ```bash $ git clone git@github.com:username/microsoft-authentication-library-for-js.git $ cd microsoft-authentication-library-for-js $ git remote add upstream git@github.com:AzureAD/microsoft-authentication-library-for-js.git ``` -------------------------------- ### Run Development Server Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/client-credentials-distributed-cache/README.md Start the application in development mode. ```console npm run dev ``` -------------------------------- ### Build the library Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/contributing.md Commands to install dependencies and build the library packages. ```bash // Change to the root of the msal repo cd microsoft-authentication-library-for-js/ // Install npm dependencies and bootstrap packages npm install // Navigate to package you would like to build cd lib/ // Build library npm run build:all // To run build only for a single package (not its dependencies) npm run build ``` -------------------------------- ### Install npm dependencies for MSAL React sample Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-react-samples/react16-sample/README.md Installs development dependencies for msal-react and msal-browser from the repository root, then builds local packages. ```bash npm install cd samples/msal-react-samples/react16-sample npm run build:package ``` -------------------------------- ### Run the MSAL.js Express Sample Development Server Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/ExpressSample/README.md Start the development server for the MSAL.js Express sample using npm start or npm run dev for auto-restart. Access the application at http://localhost:3000. ```bash npm start # or npm run dev (for auto-restart on changes) ``` -------------------------------- ### Install npm dependencies for MSAL React sample Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-react-samples/react-router-sample/README.md Installs development dependencies for msal-react and msal-browser from the root of the repository, then builds local packages. ```bash npm install cd samples/msal-react-samples/react-router-sample npm run build:package ``` -------------------------------- ### Install and Build MSAL Node Dependencies Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/README.md Commands to install dependencies, navigate to the msal-node package, and build the project. Use `build:all` for common and node packages, or `build` for only the node package. ```javascript npm install ``` ```javascript cd lib/msal-node ``` ```javascript npm run build:all ``` ```javascript npm run build ``` ```javascript npm run test ``` -------------------------------- ### Install @azure/msal-react and @azure/msal-browser Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-react/docs/migration-guide.md Install the necessary MSAL v2 packages using npm. Uninstall the old 'msal' package to avoid conflicts. ```bash npm install @azure/msal-react @azure/msal-browser npm uninstall msal ``` -------------------------------- ### Set Up Environment Variables for E2E Tests Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/NativeAuthSample/README.md Execute the environment setup script for end-to-end testing. ```powershell ./gen_env_native_auth.ps1 ``` -------------------------------- ### Server Running Confirmation Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/on-behalf-of-distributed-cache/README.md This message indicates that the server has successfully started and is accessible at the specified local address. ```bash Server is running at http://localhost:5000 ``` -------------------------------- ### v4 Request Example: GET with Extra Parameters Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/v4-migration.md Illustrates how to configure extra query parameters for a GET request in v4. These parameters are sent in the query string to both /authorize and /token endpoints. ```javascript // Example of a GET request with extra parameters const authRequest = { scopes: ["SAMPLE_SCOPE"], extraQueryParamters: { // Will be sent in query string to /authorize and /token "dc": "DC_VALUE", "slice": "SLICE_VALUE" }, extraParameters: { "extra_parameters_assertion": "ASSERTION_VALUE", // Will be sent in query string to /authorize and in body to /token }, }; ``` -------------------------------- ### Configure Mixed Scopes for HTTP Methods Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-angular/docs/msal-interceptor.md This example demonstrates how to combine string scopes with method-specific scopes. A GET request will have 'all.scope' and 'read.scope', while a PUT request will only have 'all.scope'. ```javascript { interactionType: InteractionType.Redirect, protectedResourceMap: new Map | null>([ ["http://myapplication.com", [ "all.scope", { httpMethod: "GET", scopes: ["read.scope"] }, { httpMethod: "POST", scopes: ["info.scope"] } ]] ]) } ``` -------------------------------- ### Navigate to Sample Directory Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/README.md Change the working directory to a specific sample application folder. ```bash cd samples/msal-node-samples/auth-code ``` -------------------------------- ### Get Interaction Status from Events Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/events.md Determine the current interaction status from an `EventMessage` using the `getInteractionStatusFromEvent` utility. This can be used to update the UI, for example, to show a message when no interactions are in progress. ```javascript const callbackId = msalInstance.addEventCallback((message: EventMessage) => { const status = EventMessageUtils.getInteractionStatusFromEvent(message); // Update UI or interact with EventMessage here if (status === InteractionStatus.None) { console.log(message.payload); } }); ``` -------------------------------- ### Get Account by Home ID and Acquire Token Silently Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/accounts.md This example shows how to retrieve a specific account from the cache using its `homeAccountId` (or `localAccountId`) and then use that account object to acquire a token silently for resource API calls. ```javascript async function getResource() { // Find account using homeAccountId or localAccountId built after receiving auth code token response const account = await msalTokenCache.getAccountByHomeId( app.locals.homeAccountId ); // alternativley: await msalTokenCache.getAccountByLocalId(localAccountId) if using localAccountId // Build silent request const silentRequest = { account: account, scopes: scopes, }; // Acquire Token Silently to be used in Resource API calll pca.acquireTokenSilent(silentRequest) .then((response) => { // Handle successful resource API response }) .catch((error) => { // Handle resource API request error }); } ``` -------------------------------- ### Acquire Token Silently within MsalProvider using useMsal hook Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-react/docs/migration-guide.md When using `@azure/msal-react` and `@azure/msal-browser` within a component under `MsalProvider`, use the `useMsal` hook to get the `PublicClientApplication` instance and accounts. This example demonstrates acquiring a token silently and falling back to a popup interaction if required. ```javascript import { useState } from "react"; import { useMsal } from "@azure/msal-react"; import { InteractionRequiredAuthError } from "@azure/msal-browser"; function useAccessToken() { const { instance, accounts } = useMsal(); const [accessToken, setAccessToken] = useState(null); if (accounts.length > 0) { const request = { scopes: ["User.Read"], account: accounts[0] }; instance.acquireTokenSilent(request).then(response => { setAccessToken(response.accessToken); }).catch(error => { // acquireTokenSilent can fail for a number of reasons, fallback to interaction if (error instanceof InteractionRequiredAuthError) { instance.acquireTokenPopup(request).then(response => { setAccessToken(response.accessToken); }); } }); } return accessToken; } ``` -------------------------------- ### Cypress Test Setup with MSAL Token Loading Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/testing.md Demonstrates how to use the custom `loadMsalTokens` command within a Cypress `beforeEach` hook to pre-populate MSAL tokens before visiting the application. This allows tests to start from an authenticated state. Replace placeholder tokens with actual test data. ```typescript // cypress/e2e/app.cy.ts const msalConfig = { auth: { clientId: "your-client-id", authority: "https://login.microsoftonline.com/your-tenant-id", }, cache: { cacheLocation: "sessionStorage" }, }; beforeEach(() => { cy.visit("http://localhost:3000/"); // Obtain a server response (see ROPC helper in the Playwright section), // or use pre-obtained / hardcoded test tokens. // NOTE: The values below are illustrative placeholders only. Replace them // with tokens obtained via the ROPC helper or another token acquisition // method before running real tests. const serverResponse: ExternalTokenResponse = { token_type: "Bearer", scope: "User.Read", expires_in: 3600, access_token: "test-access-token", id_token: "test-id-token", client_info: "test-client-info", }; cy.loadMsalTokens( msalConfig, { scopes: ["User.Read"], authority: msalConfig.auth.authority }, serverResponse ); cy.reload(); }); ``` -------------------------------- ### Install MSAL Node Packages Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/extensions/samples/electron-webpack/README.md Install the necessary MSAL Node packages for your project. Ensure Node.js is installed. ```bash npm install @azure/msal-node npm install @azure/msal-node-extensions ``` -------------------------------- ### Run MSAL React sample production server Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-react-samples/react16-sample/README.md Builds the MSAL React sample for production and starts a preview server using Vite. ```bash npm run build npx vite preview --port 3000 --strictPort ``` -------------------------------- ### Install MSAL Node Package Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/ElectronSystemBrowserTestApp/README.md Install the MSAL Node package using npm. ```bash npm install @azure/msal-node ``` -------------------------------- ### Example .env File Configuration Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/HybridSample/README.md Configure environment variables for MSAL authentication, including client secret, client ID, and authority. ```env MSAL_CLIENT_SECRET= MSAL_CLIENT_ID= MSAL_AUTHORITY=https://login.microsoftonline.com/common ``` -------------------------------- ### Run MSAL.js Sample Production Server Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-react-samples/typescript-sample/README.md Builds the MSAL.js React sample for production and serves it using the 'serve' package. The application will be available at http://localhost:5000. ```bash npm run build serve -s build ``` -------------------------------- ### Complete Sign-Up Test Example Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/NativeAuthSample/context/TEST_IMPLEMENTATION_GUIDE.md A full test case for a user completing a sign-up flow, including email verification and successful authentication. ```typescript it("User completes sign-up successfully", async () => { const testName = "signUpSuccess"; const screenshot = new Screenshot(`${SCREENSHOT_BASE_FOLDER_NAME}/${testName}`); // Step 1: Create new email account const { client: emailClient, address: signUpEmail } = await MailTmClient.createAuthenticatedAccount(emailProviderPwd); // Step 2: Fill form fields await UIInteractionUtils.typeIntoElement(page, "#firstName", "John", "First name field"); await UIInteractionUtils.typeIntoElement(page, "#lastName", "Doe", "Last name field"); await UIInteractionUtils.typeIntoElement(page, "#email", signUpEmail, "Email field"); // Step 3: Submit form await UIInteractionUtils.waitAndClick(page, "#signUpBtn", "Sign up button", STANDARD_TIMEOUT); await screenshot.takeScreenshot(page, "formSubmitted"); // Step 4: Handle OTP verification await page.waitForSelector("#otpCard", { visible: true, timeout: STANDARD_TIMEOUT }); const otpCode = await emailClient.readOtpCode(); await UIInteractionUtils.typeIntoElement(page, "#otpField", otpCode, "OTP field", true); await UIInteractionUtils.waitAndClick(page, "#submitOtpBtn", "Submit OTP button", STANDARD_TIMEOUT); // Step 5: Verify success await BrowserStateUtils.waitForAuthenticationComplete(page, AUTH_TIMEOUT); await TokenVerificationUtils.verifySuccessfulAuthentication(BrowserCache); await screenshot.takeScreenshot(page, "success"); }, AUTH_TIMEOUT); ``` -------------------------------- ### Install MSAL React dependencies Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-react/README.md Use npm to install the required React and MSAL packages for your project. ```sh npm install react react-dom npm install @azure/msal-react @azure/msal-browser ``` -------------------------------- ### Example: Decode with Verbose Output Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/scripts/README.md Shows how to decode logs with verbose output enabled, specifying the input log file and indicating the output file location. ```bash node scripts/decode-logs.cjs --verbose /Users/user/Downloads/browser-console.log # Output: /Users/user/Downloads/browser-console-decoded.log ``` -------------------------------- ### View CLI Usage Help Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/client-credentials-distributed-cache/README.md Displays the command-line interface usage instructions for the application. ```console Usage: --tenant --operation Options: --help Show help [boolean] --version Show version number [boolean] -i, --instance cloud instance [string] -t, --tenant tenant id [string] [required] -o, --operation operation name [string] [required] ``` -------------------------------- ### Install Dev Dependencies Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/extensions/msal-node-extensions/README.md Install development dependencies for MSAL Node extensions and MSAL common libraries from the root of the repository. ```bash // Install dev dependencies from root of repo npm install ``` -------------------------------- ### Install MSAL Angular dependencies Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-angular/README.md Use this command to install the required MSAL browser and Angular packages via NPM. ```bash npm install @azure/msal-browser @azure/msal-angular@latest ``` -------------------------------- ### Start CORS Proxy Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/NativeAuthSample/README.md Start the CORS proxy if needed, providing your tenant subdomain and tenant ID. The default port is 30001. ```bash node cors.js --tenantSubdomain YOUR_SUBDOMAIN --tenantId YOUR_TENANT_ID --port 30001 ``` -------------------------------- ### Initialize and Handle Redirect Promise Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/docs/errors.md This example demonstrates the correct order of operations for initializing MSAL and handling redirect promises to avoid 'uninitialized_public_client_application' errors. ```javascript const msalInstance = new PublicClientApplication({ auth: { clientId: "your-client-id", }, system: { allowPlatformBroker: true, }, }); await msalInstance.handleRedirectPromise(); // This will throw msalInstance.acquireTokenSilent(); // This will also throw ``` ```javascript const msalInstance = new PublicClientApplication({ auth: { clientId: "your-client-id", }, system: { allowPlatformBroker: true, }, }); await msalInstance.initialize(); await msalInstance.handleRedirectPromise(); // This will no longer throw this error since initialize completed before this was invoked msalInstance.acquireTokenSilent(); // This will also no longer throw this error ``` -------------------------------- ### Initialize ConfidentialClientApplication and Acquire Token Silently Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/caching.md Demonstrates configuring a ConfidentialClientApplication using environment variables and retrieving a token from the cache using an account's homeAccountId. ```javascript const msal = require("@azure/msal-node"); require("dotenv").config(); // process.env now has the values defined in a .env file // Create msal application object const cca = new msal.ConfidentialClientApplication({ auth: { clientId: "Enter_the_Application_Id_Here", // e.g. "b1b60dca-c49d-496e-9851-xxxxxxxxxxxx" (guid) authority: "https://login.microsoftonline.com/Enter_the_Tenant_Info_Here", // e.g. "common" or your tenantId (guid) clientSecret: process.env.clientSecret, // obtained during app registration }, }); /** * acquireToken* APIs return an account object containing the "homeAccountId" * you should keep a record of this in your app and use it later on when calling acquireTokenSilent * For more, see: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/accounts.md */ const someUserHomeAccountId = "Enter_User_Home_Account_Id"; const msalTokenCache = cca.getTokenCache(); const account = await msalTokenCache.getAccountByHomeId(someUserHomeAccountId); const silentTokenRequest = { account: account, scopes: ["User.Read"], }; cca.acquireTokenSilent(silentTokenRequest) .then((response) => { // do something with response }) .catch((error) => { // catch and handle errors }); ``` -------------------------------- ### Run Sample with Specific Name Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/VanillaJSTestApp2.0/Readme.md Use this command to run the sample, specifying a particular sample name. Defaults to the 'vanilla' sample if none is provided. ```javascript npm start -- -sample // defaults to vanilla sample in `default` folder ``` -------------------------------- ### Initialize PublicClientApplication Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/initialize-public-client-application.md Instantiate the PublicClientApplication object using the required client configuration. ```javascript import * as msal from "@azure/msal-node"; const clientConfig = { auth: { clientId: "your_client_id", authority: "your_authority", }, }; const pca = new msal.PublicClientApplication(clientConfig); ``` -------------------------------- ### Initialize ConfidentialClientApplication Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/b2c-user-flows/README.md Set up the configuration object and instantiate the MSAL ConfidentialClientApplication class. ```javascript const confidentialClientConfig = { auth: { clientId: config.authOptions.clientId, authority: config.policies.authorities.signUpSignIn.authority, clientSecret: process.env.CLIENT_SECRET, knownAuthorities: [config.policies.authorityDomain], }, }; // Create an MSAL PublicClientApplication object const confidentialClientApp = new msal.ConfidentialClientApplication( confidentialClientConfig ); ``` -------------------------------- ### Navigate to Electron Sample App Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/ElectronSystemBrowserTestApp/README.md Change directory to the Electron System Browser Test App within the MSAL Node samples. ```bash cd samples/msal-node-samples/standalone-samples/ElectronSystemBrowserTestApp ``` -------------------------------- ### Run the MSAL Node Application Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/auth-code-cli-brokered-app/README.md Execute this command in the project directory to start the application and initiate the authentication flow. ```console npm start ``` -------------------------------- ### Build @azure/msal-react and @azure/msal-browser Locally Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-react/README.md Install dev dependencies, navigate to the msal-react package directory, and run the build:all command to build both react and browser packages. ```bash // Install dev dependencies from root of repo npm install // Change to the msal-react package directory cd lib/msal-react/ // To run build for react and browser packages npm run build:all ``` -------------------------------- ### Install MSAL.js Browser via NPM Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/README.md Install the MSAL.js browser package using npm. This is the recommended method for integrating MSAL.js into your Single-Page Application. ```bash npm install @azure/msal-browser ``` -------------------------------- ### Install MSAL Browser and React Packages Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-react/docs/migration-guide-v4-v5.md Install the necessary MSAL packages for browser and React integration, supporting either React 18 or React 19. ```bash # React 19 (recommended) npm install react@^19.2.1 react-dom@^19.2.1 # OR React 18 (also supported) npm install react@^18.0.0 react-dom@^18.0.0 # Then install MSAL npm install @azure/msal-browser@^5 @azure/msal-react@^5 ``` -------------------------------- ### Install MSAL.js Browser via Yarn Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/README.md Install the MSAL.js browser package using Yarn. This is an alternative package manager for integrating MSAL.js into your Single-Page Application. ```bash yarn add @azure/msal-browser ``` -------------------------------- ### Initialize PublicClientApplication and MsalProvider Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-react/docs/getting-started.md Initialize MSAL with configuration and wrap your app with MsalProvider. This setup is required for all components needing authentication. ```javascript import React from "react"; import { createRoot } from "react-dom/client"; import { MsalProvider } from "@azure/msal-react"; import { Configuration, PublicClientApplication } from "@azure/msal-browser"; import App from "./app.jsx"; // MSAL configuration const configuration: Configuration = { auth: { clientId: "client-id" } }; const pca = new PublicClientApplication(configuration); // Component const AppProvider = () => ( ); // React 18+ rendering const root = createRoot(document.getElementById("root")); root.render(); ``` ```javascript import React from "react"; import ReactDOM from "react-dom"; ReactDOM.render(, document.getElementById("root")); ``` -------------------------------- ### Install Angular and RxJS Dependencies Source: https://github.com/azuread/microsoft-authentication-library-for-js/blob/dev/lib/msal-angular/docs/v1-v2-upgrade-guide.md Install the required versions of Angular core and common, and RxJS for MSAL Angular v2 compatibility. Ensure rxjs-compat is uninstalled if not needed by other libraries. ```bash npm install @angular/core @angular/common rxjs ``` ```bash npm uninstall rxjs-compat ```