title | description | ROBOTS | author | manager | ms.author | ms.custom | ms.date | ms.service | ms.topic |
---|---|---|---|---|---|---|---|---|---|
Quickstart: Sign in users in JavaScript React single-page apps (SPA) with auth code and call Microsoft Graph |
In this quickstart, learn how a JavaScript React single-page application (SPA) can sign in users of personal accounts, work accounts, and school accounts by using the authorization code flow and call Microsoft Graph. |
NOINDEX |
Dickson-Mwendia |
CelesteDG |
dmwendia |
scenarios:getting-started, languages:JavaScript, devx-track-js, mode-other |
08/16/2022 |
identity-platform |
quickstart |
[!div renderon="docs"] Welcome! This probably isn't the page you were expecting. While we work on a fix, this link should take you to the right article:
We apologize for the inconvenience and appreciate your patience while we work to get this resolved.
[!div renderon="portal" id="display-on-portal" class="sxs-lookup"]
In this quickstart, you download and run a code sample that demonstrates how a JavaScript React single-page application (SPA) can sign in users and call Microsoft Graph using the authorization code flow. The code sample demonstrates how to get an access token to call the Microsoft Graph API or any web API.
See How the sample works for an illustration.
- Azure subscription - Create an Azure subscription for free
- Node.js
- Visual Studio Code or another code editor
This code samples requires a Redirect URI of
http://localhost:3000/
.Make these changes for me
[!div id="appconfigured" class="alert alert-info"] Your application is configured with these attributes.
Run the project with a web server by using Node.js
[!div class="nextstepaction"] Download the code sample
[!div class="sxs-lookup"]
[!NOTE]
Enter_the_Supported_Account_Info_Here
We have configured your project with values of your app's properties.
Run the project with a web server by using Node.js:
To start the server, run the following commands from within the project directory:
npm install npm startBrowse to
http://localhost:3000/
.Select Sign In to start the sign-in process and then call the Microsoft Graph API.
The first time you sign in, you're prompted to provide your consent to allow the application to access your profile and sign you in. After you're signed in successfully, click on the Request Profile Information to display your profile information on the page.
The MSAL.js library signs in users and requests the tokens that are used to access an API that's protected by the Microsoft identity platform.
If you have Node.js installed, you can download the latest version by using the Node.js Package Manager (npm):
npm install @azure/msal-browser @azure/msal-react
Next, try a step-by-step tutorial to learn how to build a React SPA from scratch that signs in users and calls the > Microsoft Graph API to get user profile data:
[!div class="nextstepaction"] Tutorial: Sign in users and call Microsoft Graph from a React single-page app