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
+4-10Lines changed: 4 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,20 @@
1
1
---
2
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.
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
15
# Prepare a React single-page app (SPA) for authentication
18
16
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 app using npm and create files needed for authentication and authorization.
17
+
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
18
21
19
In this article, you learn how to:
22
20
@@ -32,7 +30,6 @@ In this article, you learn how to:
32
30
*[Node.js](https://nodejs.org/en/download/)
33
31
34
32
## Create a new React project
35
-
36
33
Use the following tabs to create a React project within the IDE.
37
34
38
35
1. Open Visual Studio Code, select **File** > **Open Folder...**. Navigate to and select the location in which to create your project.
@@ -46,7 +43,6 @@ Use the following tabs to create a React project within the IDE.
46
43
```
47
44
48
45
## Install identity and bootstrap packages
49
-
50
46
Identity related **npm** packages must be installed in the project to enable user authentication. For project styling, **Bootstrap** will be used.
51
47
52
48
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 +54,6 @@ Identity related **npm** packages must be installed in the project to enable use
58
54
```
59
55
60
56
## Creating the authentication configuration file
61
-
62
57
1. In the *src* folder, create a new file called *authConfig.js*.
63
58
1. Open *authConfig.js* and add the following code snippet:
64
59
@@ -135,7 +130,6 @@ Identity related **npm** packages must be installed in the project to enable use
135
130
136
131
137
132
## Modify index.js to include the authentication provider
138
-
139
133
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
134
141
135
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:
Copy file name to clipboardExpand all lines: articles/active-directory/external-identities/customers/how-to-single-page-application-react-prepare-tenant.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
---
2
-
title: Prepare your tenant to use a React single-page app (SPA) 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
@@ -14,7 +14,7 @@ ms.custom: it-pro
14
14
15
15
#Customer intent: As a dev I want to prepare my customer tenant for building a single-page app (SPA) with React
16
16
---
17
-
# Prepare your customer tenant for building a single-page app (SPA)
17
+
# Prepare your customer tenant to authenticate users in a React single-page app (SPA)
18
18
19
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.
Copy file name to clipboardExpand all lines: articles/active-directory/external-identities/customers/how-to-single-page-application-react-sign-in-out.md
+2-13Lines changed: 2 additions & 13 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
@@ -15,8 +15,7 @@ ms.custom: it-pro
15
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:
@@ -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**.
@@ -285,12 +276,10 @@ All the required code snippets have been added, so the application can now be ca
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