Skip to content

Commit 1224e47

Browse files
authored
Merge pull request #241862 from MicrosoftDocs/main
6/16/2023 OOB Publishing at 4:45PM
2 parents 2b9b000 + 71f9eb2 commit 1224e47

File tree

69 files changed

+1281
-1153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1281
-1153
lines changed

.openpublishing.redirection.azure-monitor.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6160,6 +6160,11 @@
61606160
"source_path_from_root": "/articles/azure-monitor/logs/api/app-insights-azure-ad-api.md",
61616161
"redirect_url": "/azure/azure-monitor/app/app-insights-azure-ad-api",
61626162
"redirect_document_id": false
6163+
},
6164+
{
6165+
"source_path_from_root": "/articles/azure-monitor/app/javascript-sdk-advanced.md",
6166+
"redirect_url": "/azure/azure-monitor/app/javascript-sdk-configuration",
6167+
"redirect_document_id": false
61636168
}
61646169
]
61656170
}

articles/active-directory/develop/scenario-web-app-call-api-acquire-token.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ public ModelAndView getUserFromGraph(HttpServletRequest httpRequest, HttpServlet
199199
// Code omitted here
200200
```
201201

202+
# [Node.js](#tab/nodejs)
203+
204+
In the Node.js sample, the code that acquires a token is in the *acquireToken* method of the **AuthProvider** class.
205+
206+
:::code language="js" source="~/ms-identity-node/App/auth/AuthProvider.js" range="79-121":::
207+
208+
This access token is then used to handle requests to the `/profile` endpoint:
209+
210+
:::code language="js" source="~/ms-identity-node/App/routes/users.js" range="29-39":::
211+
202212
# [Python](#tab/python)
203213

204214
In the Python sample, the code that calls the API is in `app.py`.
@@ -226,6 +236,11 @@ Move on to the next article in this scenario,
226236
Move on to the next article in this scenario,
227237
[Call a web API](scenario-web-app-call-api-call-api.md?tabs=java).
228238

239+
# [Node.js](#tab/nodejs)
240+
241+
Move on to the next article in this scenario,
242+
[Call a web API](scenario-web-app-call-api-call-api.md?tabs=nodejs).
243+
229244
# [Python](#tab/python)
230245

231246
Move on to the next article in this scenario,

articles/active-directory/develop/scenario-web-app-call-api-app-configuration.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ Code examples in this article and the following one are extracted from the [ASP.
261261
Code examples in this article and the following one are extracted from the [Java web application that calls Microsoft Graph](https://github.com/Azure-Samples/ms-identity-java-webapp), a web-app sample that uses MSAL for Java.
262262
The sample currently lets MSAL for Java produce the authorization-code URL and handles the navigation to the authorization endpoint for the Microsoft identity platform. It's also possible to use Sprint security to sign the user in. You might want to refer to the sample for full implementation details.
263263

264+
# [Node.js](#tab/nodejs)
265+
266+
Code examples in this article and the following one are extracted from the [Node.js & Express.js web application that calls Microsoft Graph](https://github.com/Azure-Samples/ms-identity-node), a web app sample that uses MSAL Node.
267+
268+
The sample currently lets MSAL Node produce the authorization-code URL and handles the navigation to the authorization endpoint for the Microsoft identity platform. This is shown below:
269+
270+
:::code language="js" source="~/ms-identity-node/App/auth/AuthProvider.js" range="187-232":::
271+
264272
# [Python](#tab/python)
265273

266274
Code snippets in this article and the following are extracted from the [Python web application calling Microsoft graph](https://github.com/Azure-Samples/ms-identity-python-webapp) sample using the [identity package](https://pypi.org/project/identity/) (a wrapper around MSAL Python).
@@ -279,6 +287,12 @@ Microsoft.Identity.Web simplifies your code by setting the correct OpenID Connec
279287

280288
*Microsoft.Identity.Web.OWIN* simplifies your code by setting the correct OpenID Connect settings, subscribing to the code received event, and redeeming the code. No extra code is required to redeem the authorization code. See [Microsoft.Identity.Web source code](https://github.com/AzureAD/microsoft-identity-web/blob/9fdcf15c66819b31b1049955eed5d3e5391656f5/src/Microsoft.Identity.Web.OWIN/AppBuilderExtension.cs#L95) for details on how this works.
281289

290+
# [Node.js](#tab/nodejs)
291+
292+
The *handleRedirect* method in **AuthProvider** class processes the authorization code received from Azure AD. This is shown below:
293+
294+
:::code language="js" source="~/ms-identity-node/App/auth/AuthProvider.js" range="123-155":::
295+
282296
# [Java](#tab/java)
283297

284298
See [Web app that signs in users: Code configuration](scenario-web-app-sign-user-app-configuration.md?tabs=java#initialization-code) to understand how the Java sample gets the authorization code. After the app receives the code, the [AuthFilter.java#L51-L56](https://github.com/Azure-Samples/ms-identity-java-webapp/blob/d55ee4ac0ce2c43378f2c99fd6e6856d41bdf144/src/main/java/com/microsoft/azure/msalwebsample/AuthFilter.java#L51-L56):
@@ -468,6 +482,12 @@ IAuthenticationResult getAuthResultBySilentFlow(HttpServletRequest httpRequest,
468482

469483
The detail of the `SessionManagementHelper` class is provided in the [MSAL sample for Java](https://github.com/Azure-Samples/ms-identity-java-webapp/blob/d55ee4ac0ce2c43378f2c99fd6e6856d41bdf144/src/main/java/com/microsoft/azure/msalwebsample/SessionManagementHelper.java).
470484

485+
# [Node.js](#tab/nodejs)
486+
487+
In the Node.js sample, the application session is used to store the token cache. Using MSAL Node cache methods, the token cache in session is read before a token request is made, and then updated once the token request is successfully completed. This is shown below:
488+
489+
:::code language="js" source="~/ms-identity-node/App/auth/AuthProvider.js" range="79-121":::
490+
471491
# [Python](#tab/python)
472492

473493
In the Python sample, the identity package takes care of the token cache, using the global `session` object for storage.
@@ -501,6 +521,11 @@ Move on to the next article in this scenario,
501521
Move on to the next article in this scenario,
502522
[Remove accounts from the cache on global sign out](scenario-web-app-call-api-sign-in.md?tabs=java).
503523

524+
# [Node.js](#tab/nodejs)
525+
526+
Move on to the next article in this scenario,
527+
[Remove accounts from the cache on global sign out](scenario-web-app-call-api-sign-in.md?tabs=nodejs).
528+
504529
# [Python](#tab/python)
505530

506531
Move on to the next article in this scenario,

articles/active-directory/develop/scenario-web-app-call-api-call-api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ private String getUserInfoFromGraph(String accessToken) throws Exception {
295295
}
296296
```
297297

298+
# [Node.js](#tab/nodejs)
299+
300+
After successfully retrieving a token, the code uses the **axios** package to query the API endpoint and retrieve a JSON result.
301+
302+
:::code language="js" source="~/ms-identity-node/App/fetch.js" range="8-28":::
303+
298304
# [Python](#tab/python)
299305

300306
After successfully retrieving a token, the code uses the requests package to query the API endpoint and retrieve a JSON result.

articles/active-directory/develop/scenario-web-app-call-api-sign-in.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ The ASP.NET sample doesn't remove accounts from the cache on global sign-out.
3838

3939
The Java sample doesn't remove accounts from the cache on global sign-out.
4040

41+
# [Node.js](#tab/nodejs)
42+
43+
The Node sample doesn't remove accounts from the cache on global sign-out.
44+
4145
# [Python](#tab/python)
4246

4347
The Python sample doesn't remove accounts from the cache on global sign-out.
@@ -61,6 +65,11 @@ Move on to the next article in this scenario,
6165
Move on to the next article in this scenario,
6266
[Acquire a token for the web app](./scenario-web-app-call-api-acquire-token.md?tabs=java).
6367

68+
# [Node.js](#tab/nodejs)
69+
70+
Move on to the next article in this scenario,
71+
[Acquire a token for the web app](./scenario-web-app-call-api-acquire-token.md?tabs=nodejs).
72+
6473
# [Python](#tab/python)
6574

6675
Move on to the next article in this scenario,

articles/active-directory/develop/scenario-web-app-sign-user-app-configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ In the Azure portal, the reply URIs that you register on the **Authentication**
167167

168168
# [Node.js](#tab/nodejs)
169169

170-
Here, the configuration parameters reside in *.env* as environment variables:
170+
Here, the configuration parameters reside in *.env.dev* as environment variables:
171171

172-
:::code language="text" source="~/ms-identity-node/App/.env":::
172+
:::code language="text" source="~/ms-identity-node/App/.env.dev":::
173173

174174
These parameters are used to create a configuration object in *authConfig.js* file, which will eventually be used to initialize MSAL Node:
175175

articles/active-directory/develop/scenario-web-app-sign-user-sign-in.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public class AuthPageController {
173173

174174
When the user selects the **Sign in** link, which triggers the `/auth/signin` route, the sign-in controller takes over to authenticate the user with Microsoft identity platform.
175175

176-
:::code language="js" source="~/ms-identity-node/App/routes/auth.js" range="27-107, 135-161":::
176+
:::code language="js" source="~/ms-identity-node/App/auth/AuthProvider.js" range="15-77, 195-253":::
177177

178178
# [Python](#tab/python)
179179

@@ -355,7 +355,7 @@ In Java, sign-out is handled by calling the Microsoft identity platform `logout`
355355

356356
When the user selects the **Sign out** button, the app triggers the `/signout` route, which destroys the session and redirects the browser to Microsoft identity platform sign-out endpoint.
357357

358-
:::code language="js" source="~/ms-identity-node/App/routes/auth.js" range="163-174":::
358+
:::code language="js" source="~/ms-identity-node/App/auth/AuthProvider.js" range="157-175":::
359359

360360
# [Python](#tab/python)
361361

articles/active-directory/develop/tutorial-v2-nodejs-webapp-msal.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ The web app sample in this tutorial uses the [express-session](https://www.npmjs
103103

104104
## Add app registration details
105105

106-
1. Create an *.env* file in the root of your project folder. Then add the following code:
106+
1. Create an *.env.dev* file in the root of your project folder. Then add the following code:
107107

108-
:::code language="text" source="~/ms-identity-node/App/.env":::
108+
:::code language="text" source="~/ms-identity-node/App/.env.dev":::
109109

110110
Fill in these details with the values you obtain from Azure app registration portal:
111111

@@ -133,11 +133,15 @@ Fill in these details with the values you obtain from Azure app registration por
133133

134134
## Add code for user sign-in and token acquisition
135135

136-
1. Create a new file named *auth.js* under the *routes* folder and add the following code there:
136+
1. Create a new folder named *auth*, and add a new file named *AuthProvider.js* under it. This will contain the **AuthProvider** class, which encapsulates the necessary authentication logic using MSAL Node. Add the following code there:
137+
138+
:::code language="js" source="~/ms-identity-node/App/auth/AuthProvider.js":::
139+
140+
1. Next, create a new file named *auth.js* under the *routes* folder and add the following code there:
137141

138142
:::code language="js" source="~/ms-identity-node/App/routes/auth.js":::
139143

140-
2. Next, update the *index.js* route by replacing the existing code with the following code snippet:
144+
2. Update the *index.js* route by replacing the existing code with the following code snippet:
141145

142146
:::code language="js" source="~/ms-identity-node/App/routes/index.js":::
143147

0 commit comments

Comments
 (0)