You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/active-directory/external-identities/customers/how-to-single-page-application-react-prepare-app.md
+9-16Lines changed: 9 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,19 @@
1
1
---
2
-
title: Prepare a React Single Page App (SPA) for authentication
3
-
description: Learn how to prepare a React single-page app (SPA) for authentication and authorization with your Azure Active Directory (AD) for customers tenant.
2
+
title: Prepare a React single-page app (SPA) for authentication
3
+
description: Learn how to prepare a React single-page app (SPA) for authentication with your Azure Active Directory (AD) for customers tenant.
4
4
services: active-directory
5
-
author: godonnell
5
+
author: garrodonnell
6
6
manager: celestedg
7
7
ms.service: active-directory
8
-
ms.workload: identity
9
8
ms.subservice: ciam
10
9
ms.topic: how-to
11
10
ms.date: 05/23/2023
12
11
ms.author: godonnell
13
-
ms.custom: it-pro
14
12
15
-
#Customer intent: As a dev, devops, or IT admin, enable authentication in my own React
13
+
#Customer intent: As a dev, devops, or IT admin, I want to learn how to enable authentication in my own React single-page app
16
14
---
17
-
# Prepare a React Single-page application for authentication
18
-
19
-
After registration is complete, a React project can be created using an integrated development environment (IDE). This tutorial demonstrates how to create a React Single-page application using npm and create files needed for authentication and authorization.
15
+
# Prepare a React single-page app (SPA) for authentication
16
+
After registration is complete, you can create a React project using an integrated development environment (IDE). This tutorial demonstrates how to create a React single-page app using npm and create files needed for authentication and authorization.
20
17
21
18
In this article, you learn how to:
22
19
@@ -27,13 +24,12 @@ In this article, you learn how to:
27
24
> * Add authentication code to the application
28
25
29
26
## Prerequisites
30
-
* Completion of the prerequisites and steps in [Prepare your customer tenant for building a React Single Page App (SPA)](./how-to-single-page-application-react-prepare-tenant.md))
27
+
* Completion of the prerequisites and steps in [Prepare your customer tenant for building a React single-page app (SPA)](./how-to-single-page-application-react-prepare-tenant.md))
31
28
* Although any IDE that supports React applications can be used, Visual Studio Code is used for this guide. This can be downloaded from the [Downloads](https://visualstudio.microsoft.com/downloads/) page.
32
29
*[Node.js](https://nodejs.org/en/download/)
33
30
34
31
## Create a new React project
35
-
36
-
Use the following tabs to create a React project within the IDE.
32
+
Use the following tabs to create a React project within Visual Studio Code.
37
33
38
34
1. Open Visual Studio Code, select **File** > **Open Folder...**. Navigate to and select the location in which to create your project.
39
35
1. Open a new terminal by selecting **Terminal** > **New Terminal**.
@@ -46,7 +42,6 @@ Use the following tabs to create a React project within the IDE.
46
42
```
47
43
48
44
## Install identity and bootstrap packages
49
-
50
45
Identity related **npm** packages must be installed in the project to enable user authentication. For project styling, **Bootstrap** will be used.
51
46
52
47
1. In the **Terminal** bar, select the **+** icon to create a new terminal. A separate terminal window will open with the previous node terminal continuing to run in the background.
@@ -58,7 +53,6 @@ Identity related **npm** packages must be installed in the project to enable use
58
53
```
59
54
60
55
## Creating the authentication configuration file
61
-
62
56
1. In the *src* folder, create a new file called *authConfig.js*.
63
57
1. Open *authConfig.js* and add the following code snippet:
64
58
@@ -135,7 +129,6 @@ Identity related **npm** packages must be installed in the project to enable use
135
129
136
130
137
131
## Modify index.js to include the authentication provider
138
-
139
132
All parts of the app that require authentication must be wrapped in the [`MsalProvider`](/javascript/api/@azure/msal-react/#@azure-msal-react-msalprovider) component. You instantiate a [PublicClientApplication](/javascript/api/@azure/msal-browser/publicclientapplication) then pass it to `MsalProvider`.
140
133
141
134
1. In the *src* folder, open *index.js* and replace the contents of the file with the following code snippet to use the `msal` packages and bootstrap styling:
@@ -146,4 +139,4 @@ All parts of the app that require authentication must be wrapped in the [`MsalPr
146
139
## Next steps
147
140
148
141
> [!div class="nextstepaction"]
149
-
> [Add Sign-in and Sign-out functionality to your app.](./how-to-single-page-application-react-sign-in-out.md)
142
+
> [Add sign-in and sign-out functionality to your app.](./how-to-single-page-application-react-sign-in-out.md)
Copy file name to clipboardExpand all lines: articles/active-directory/external-identities/customers/how-to-single-page-application-react-prepare-tenant.md
+9-10Lines changed: 9 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,28 @@
1
1
---
2
-
title: Prepare your tenant to use a React single-page app for authentication.
2
+
title: Prepare your customer tenant to authenticate users in a React single-page app (SPA)
3
3
description: Learn how to configure your Azure Active Directory (AD) for customers tenant for authentication with a React single-page app (SPA).
4
4
services: active-directory
5
-
author: godonnell
5
+
author: garrodonnell
6
6
manager: celestedg
7
7
ms.service: active-directory
8
8
ms.workload: identity
9
9
ms.subservice: ciam
10
10
ms.topic: how-to
11
11
ms.date: 05/23/2023
12
12
ms.author: godonnell
13
-
ms.custom: it-pro
14
13
15
-
#Customer intent: As a dev I want to prepare my customer tenant for building a Single Page App with React
14
+
#Customer intent: As a dev I want to prepare my customer tenant for building a single-page app (SPA) with React
16
15
---
17
-
# Prepare your customer tenant for building a Single Page App (SPA)
16
+
# Prepare your customer tenant to authenticate users in a React single-page app (SPA)
18
17
19
-
Before your applications can interact with Microsoft Identity Platform they must be registered in a customer tenant that you manage and must be associated with a user flow.
18
+
Before your applications can interact with Microsoft identity platform they must be registered in a customer tenant that you manage and must be associated with a user flow.
20
19
21
20
In this article, you learn how to:
22
21
23
22
> [!div class="checklist"]
24
-
> * Register your application and record identifiers.
25
-
> * Create a user flow to allow sign-up and sign-in.
26
-
> * Associate the user flow with your application.
23
+
> * Register your application and record identifiers
24
+
> * Create a user flow to allow sign-up and sign-in
25
+
> * Associate the user flow with your application
27
26
28
27
## Prerequisites
29
28
@@ -54,4 +53,4 @@ If you haven't already created your own customer tenant, [create one now](https:
54
53
## Next steps
55
54
56
55
> [!div class="nextstepaction"]
57
-
> [Start building your React Single Page Application](./how-to-single-page-application-react-prepare-app.md)
56
+
> [Start building your React single-page app](./how-to-single-page-application-react-prepare-app.md)
Copy file name to clipboardExpand all lines: articles/active-directory/external-identities/customers/how-to-single-page-application-react-sample.md
+6-9Lines changed: 6 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,27 +1,24 @@
1
1
---
2
2
title: Sign in users in a sample React single-page application
3
-
description: Learn how to configure a sample React SPA to sign in and sign out users.
3
+
description: Learn how to configure a sample React single-page app (SPA) to sign in and sign out users.
4
4
services: active-directory
5
5
author: garrodonnell
6
6
manager: celestedg
7
7
ms.author: godonnell
8
8
ms.service: active-directory
9
-
ms.workload: identity
10
9
ms.subservice: ciam
11
10
ms.topic: how-to
12
11
ms.date: 05/23/2023
13
-
ms.custom: developer
14
12
15
-
#Customer intent: As a dev, devops, I want to learn about how to configure a sample React Single Page Application to sign in and sign out users with my Azure Active Directory (Azure AD) for customers tenant
13
+
#Customer intent: As a dev, devops, I want to learn about how to configure a sample React single-page app to sign in and sign out users with my Azure Active Directory (Azure AD) for customers tenant
16
14
---
17
15
18
-
# Sign in users in a sample React single-page application
16
+
# Sign in users in a sample React single-page app (SPA)
19
17
20
18
This how-to guide uses a sample React single-page application (SPA) to demonstrate how to add authentication to a SPA. This SPA enables users to sign in and sign out by using you Azure Active Directory (Azure AD) for customers tenant. The sample uses the [Microsoft Authentication Library for JavaScript (MSAL.js)](https://github.com/AzureAD/microsoft-authentication-library-for-js) to handle authentication.
21
19
22
20
## Prerequisites
23
-
24
-
* Although any IDE that supports vanilla JS applications can be used, **Visual Studio Code** is used for this guide. It can be downloaded from the [Downloads](https://visualstudio.microsoft.com/downloads) page.
21
+
* Although any IDE that supports React applications can be used, **Visual Studio Code** is used for this guide. It can be downloaded from the [Downloads](https://visualstudio.microsoft.com/downloads) page.
25
22
*[Node.js](https://nodejs.org/en/download/).
26
23
* Azure AD for customers tenant. If you don't already have one, [sign up for a free trial](https://aka.ms/ciam-free-trial?wt.mc_id=ciamcustomertenantfreetrial_linkclick_content_cnl).
27
24
@@ -98,5 +95,5 @@ All the required code snippets have been added, so the application can now be ca
98
95
1. Once signed in the display name is shown next to the **Sign out** button.
99
96
100
97
## Next steps
101
-
102
-
Learn how to use the Microsoft Authentication Library (MSAL) for JavaScript to sign in users and acquire tokens to call Microsoft Graph.
Copy file name to clipboardExpand all lines: articles/active-directory/external-identities/customers/how-to-single-page-application-react-sign-in-out.md
+5-16Lines changed: 5 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Sign in users with a React single-page-application
2
+
title: Add sign-in to a React single-page app (SPA)
3
3
description: Learn how to configure a React single-page app (SPA) to sign in and sign out users with your Azure Active Directory (AD) for customers tenant.
4
4
services: active-directory
5
5
author: godonnell
@@ -12,11 +12,10 @@ ms.date: 05/23/2023
12
12
ms.author: godonnell
13
13
ms.custom: it-pro
14
14
15
-
#Customer intent: As a developer I want to add sign-in and sign-out functionality to my React Single Page App
15
+
#Customer intent: As a developer I want to add sign-in and sign-out functionality to my React single-page app
16
16
---
17
17
18
-
# Create components for sign in and sign out in a React single page app
19
-
18
+
# Add sign-in to a React single-page app (SPA)
20
19
Functional components are the building blocks of React apps. This tutorial demonstrates how functional components can be used to build the sign in and sign out experience in a React single-page app (SPA). The `useMsal` hook is used to retrieve an access token to allow user sign in.
21
20
22
21
In this tutorial:
@@ -30,7 +29,7 @@ In this tutorial:
30
29
31
30
## Prerequisites
32
31
33
-
* Completion of the prerequisites and steps in [Prepare an Single Page Application for authentication](how-to-single-page-application-react-prepare-app.md).
32
+
* Completion of the prerequisites and steps in [Prepare an single-page app for authentication](how-to-single-page-application-react-prepare-app.md).
34
33
35
34
36
35
## Adding components to the application
@@ -42,8 +41,6 @@ In this tutorial:
42
41
-*SignInButton.jsx*
43
42
-*SignOutButton.jsx*
44
43
45
-
---
46
-
47
44
Once complete, you should have the following folder structure.
48
45
49
46
```txt
@@ -58,7 +55,6 @@ reactspalocal/
58
55
```
59
56
60
57
### Adding the page layout
61
-
62
58
1. Open *PageLayout.jsx* and add the following code to render the page layout. The [useIsAuthenticated](/javascript/api/@azure/msal-react) hook returns whether or not a user is currently signed-in.
63
59
64
60
```javascript
@@ -110,7 +106,6 @@ reactspalocal/
110
106
1. Save the file.
111
107
112
108
### Adding the sign in experience
113
-
114
109
1. Open *SignInButton.jsx* and add the following code, which creates a button that signs in the user using either a pop-up or redirect.
115
110
116
111
```javascript
@@ -163,7 +158,6 @@ reactspalocal/
163
158
1. Save the file.
164
159
165
160
### Adding the sign out experience
166
-
167
161
1. Open *SignOutButton.jsx* and add the following code, which creates a button that signs out the user using either a pop-up or redirect.
168
162
169
163
```javascript
@@ -210,7 +204,6 @@ reactspalocal/
210
204
```
211
205
212
206
## Change filename and add required imports
213
-
214
207
By default, the application runs via a JavaScript file called *App.js*. It needs to be renamed to *App.jsx*, which is an extension that allows a developer to write HTML in React.
215
208
216
209
1. Rename App.js to App.jsx.
@@ -230,7 +223,6 @@ By default, the application runs via a JavaScript file called *App.js*. It needs
230
223
```
231
224
232
225
### Replacing the default function to render authenticated information
233
-
234
226
The following code will render based on whether the user is authenticated or not. Replace the default function `App()` to render authenticated information with the following code:
235
227
236
228
```javascript
@@ -267,7 +259,6 @@ export default function App() {
267
259
```
268
260
269
261
## Run your project and sign in
270
-
271
262
All the required code snippets have been added, so the application can now be called and tested in a web browser.
272
263
273
264
1. Open a new terminal by selecting **Terminal** > **New Terminal**.
@@ -277,20 +268,18 @@ All the required code snippets have been added, so the application can now be ca
277
268
npm start
278
269
```
279
270
280
-
1. Open a web browser and navigate to the port specified in [Prepare a Single-page application for authentication](./how-to-single-page-application-react-prepare-app.md). For example, http://localhost:3000/.
271
+
1. Open a web browser and navigate to the port specified in [Prepare a single-page application for authentication](./how-to-single-page-application-react-prepare-app.md). For example, http://localhost:3000/.
281
272
1. For the purposes of this how-to, choose the **Sign in using Popup** option.
282
273
1. After the popup window appears with the sign-in options, select the account with which to sign-in.
283
274
1. A second window may appear indicating that a code will be sent to your email address. If this happens, select **Send code**. Open the email from the sender Microsoft account team, and enter the 7-digit single-use code. Once entered, select **Sign in**.
284
275
1. For **Stay signed in**, you can select either **No** or **Yes**.
285
276
1. The app will now ask for permission to sign-in and access data. Select **Accept** to continue.
286
277
287
278
## Sign out of the application
288
-
289
279
1. To sign out of the application, select **Sign out** in the navigation bar.
290
280
1. A window appears asking which account to sign out of.
291
281
1. Upon successful sign out, a final window appears advising you to close all browser windows.
0 commit comments