Configuration in ./src/authConfig.js.
./src/App.tsx- Shows implementation ofMsalProvider, all children will have access to@azure/msal-reactcontext, hooks and components../src/index.tsx- Shows intialization of thePublicClientApplicationthat is passed toApp.tsx./src/pages/Home.tsx- Homepage, shows how to conditionally render content usingAuthenticatedTemplateandUnauthenticatedTemplatedepending on whether or not a user is signed in../src/pages/Profile.tsx- Example of a protected route usingMsalAuthenticationTemplate. If a user is not yet signed in, signin will be invoked automatically. If a user is signed in it will acquire an access token and make a call to MS Graph to fetch user profile data../src/authConfig.ts- Configuration options forPublicClientApplicationand token requests../src/ui-components/SignInSignOutButton.tsx- Example of how to conditionally render a Sign In or Sign Out button using theuseIsAuthenticatedhook../src/ui-components/SignInButton.tsx- Example of how to get thePublicClientApplicationinstance using theuseMsalhook and invoking a login function../src/ui-components/SignOutButton.tsx- Example of how to get thePublicClientApplicationinstance using theuseMsalhook and invoking a logout function../src/utils/MsGraphApiCall.ts- Example of how to call the MS Graph API with an access token../src/utils/NavigationClient.ts- Example implementation ofINavigationClientwhich can be used to override the default navigation functions MSAL.js uses
- Ensure all pre-requisites have been completed to run
@azure/msal-react. - Install node.js if needed (https://nodejs.org/en/).
- Open
./src/authConfig.tsin an editor. - Replace client id with the Application (client) ID from the portal registration, or use the currently configured lab registration.
- Optionally, you may replace any of the other parameters, or you can remove them and use the default values.
- In a command prompt, run
npm start. - Open http://localhost:3000 to view it in the browser.
- Open http://localhost:3000/profile to see an example of a protected route. If you are not yet signed in, signin will be invoked automatically.
npm run buildto create a production build (buil;d folder created).npm run serveto serve it at http://localhost:3000.