Skip to content

Commit 690ca4c

Browse files
committed
nodejs examples
1 parent ba47e02 commit 690ca4c

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

articles/app-service/scenario-secure-app-access-microsoft-graph-as-app.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ public async Task OnGetAsync()
206206
```
207207

208208
# [Node.js](#tab/programming-language-nodejs)
209-
The call to Microsoft Graph is performed in the controllers/graphController.js file getUsersPage controller. The `DefaultAzureCredential` class from [@azure/identity](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md) package is used to get a token credential for your code to authorize requests to Azure Storage. Create an instance of the `DefaultAzureCredential` class, which uses the managed identity to fetch tokens and attach them to the service client. The following code example gets the authenticated token credential and uses it to create a service client object, which gets the users in the group.
209+
210+
The `DefaultAzureCredential` class from [@azure/identity](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md) package is used to get a token credential for your code to authorize requests to Azure Storage. Create an instance of the `DefaultAzureCredential` class, which uses the managed identity to fetch tokens and attach them to the service client. The following code example gets the authenticated token credential and uses it to create a service client object, which gets the users in the group.
210211

211212
To see this code as part of a sample application, see the [sample on GitHub](https://github.com/Azure-Samples/ms-identity-easyauth-nodejs-storage-graphapi/tree/main/3-WebApp-graphapi-managed-identity).
212213

@@ -236,7 +237,7 @@ exports.getUsersPage = async(req, res, next) => {
236237
}
237238
```
238239

239-
To query Microsoft Graph, the sample uses the [Microsoft Graph JavaScript SDK](https://github.com/microsoftgraph/msgraph-sdk-javascript). The code for this is located in utils/graphHelper.js:
240+
To query Microsoft Graph, the sample uses the [Microsoft Graph JavaScript SDK](https://github.com/microsoftgraph/msgraph-sdk-javascript). The code for this is located in [utils/graphHelper.js](https://github.com/Azure-Samples/ms-identity-easyauth-nodejs-storage-graphapi/blob/main/3-WebApp-graphapi-managed-identity/controllers/graphController.js) of the full sample:
240241

241242
```nodejs
242243
getAuthenticatedClient = (accessToken) => {

articles/app-service/scenario-secure-app-access-microsoft-graph-as-user.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,15 @@ public class IndexModel : PageModel
274274

275275
# [Node.js](#tab/programming-language-nodejs)
276276

277-
To see this code as part of a sample application, see the [sample on GitHub](https://github.com/Azure-Samples/ms-identity-easyauth-nodejs-storage-graphapi/tree/main/2-WebApp-graphapi-on-behalf).
277+
The web app gets the user's access token from the incoming requests header, which is then passed down to Microsoft Graph client to make an authenticated request to the `/me` endpoint.
278278

279-
The sample app gets the user's access token from the incoming requests header, which is then passed down to Microsoft Graph client to make an authenticated request to the /me endpoint:
279+
To see this code as part of a sample application, see *graphController.js* in the [sample on GitHub](https://github.com/Azure-Samples/ms-identity-easyauth-nodejs-storage-graphapi/tree/main/2-WebApp-graphapi-on-behalf).
280280

281281
```nodejs
282282
const graphHelper = require('../utils/graphHelper');
283283
284+
// Some code omitted for brevity.
285+
284286
exports.getProfilePage = async(req, res, next) => {
285287
286288
try {
@@ -297,9 +299,13 @@ exports.getProfilePage = async(req, res, next) => {
297299
}
298300
```
299301

300-
To query Microsoft Graph, the sample uses the [Microsoft Graph JavaScript SDK](https://github.com/microsoftgraph/msgraph-sdk-javascript). The code for this is located in utils/graphHelper.js:
302+
To query Microsoft Graph, use the [Microsoft Graph JavaScript SDK](https://github.com/microsoftgraph/msgraph-sdk-javascript). The code for this is located in [utils/graphHelper.js](https://github.com/Azure-Samples/ms-identity-easyauth-nodejs-storage-graphapi/blob/main/2-WebApp-graphapi-on-behalf/utils/graphHelper.js):
301303

302304
```nodejs
305+
const graph = require('@microsoft/microsoft-graph-client');
306+
307+
// Some code omitted for brevity.
308+
303309
getAuthenticatedClient = (accessToken) => {
304310
// Initialize Graph client
305311
const client = graph.Client.init({

articles/app-service/scenario-secure-app-access-storage.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,17 @@ static public async Task UploadBlob(string accountName, string containerName, st
282282
# [Node.js](#tab/programming-language-nodejs)
283283
The `DefaultAzureCredential` class from [@azure/identity](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md) package is used to get a token credential for your code to authorize requests to Azure Storage. The `BlobServiceClient` class from [@azure/storage-blob](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob) package is used to upload a new blob to storage. Create an instance of the `DefaultAzureCredential` class, which uses the managed identity to fetch tokens and attach them to the blob service client. The following code example gets the authenticated token credential and uses it to create a service client object, which uploads a new blob.
284284

285-
To see this code as part of a sample application, see the [sample on GitHub](https://github.com/Azure-Samples/ms-identity-easyauth-nodejs-storage-graphapi/tree/main/1-WebApp-storage-managed-identity).
285+
To see this code as part of a sample application, see *StorageHelper.js* in the [sample on GitHub](https://github.com/Azure-Samples/ms-identity-easyauth-nodejs-storage-graphapi/tree/main/1-WebApp-storage-managed-identity).
286286

287287
### Example
288288

289289
```nodejs
290+
const { DefaultAzureCredential } = require("@azure/identity");
291+
const { BlobServiceClient } = require("@azure/storage-blob");
292+
const defaultAzureCredential = new DefaultAzureCredential();
293+
294+
// Some code omitted for brevity.
295+
290296
async function uploadBlob(accountName, containerName, blobName, blobContents) {
291297
const blobServiceClient = new BlobServiceClient(
292298
`https://${accountName}.blob.core.windows.net`,

0 commit comments

Comments
 (0)