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/app-service/scenario-secure-app-access-microsoft-graph-as-app.md
+55-6Lines changed: 55 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ manager: CelesteDG
8
8
ms.service: app-service-web
9
9
ms.topic: tutorial
10
10
ms.workload: identity
11
-
ms.date: 01/28/2021
11
+
ms.date: 11/02/2021
12
12
ms.author: ryanwi
13
13
ms.reviewer: stsoneff
14
14
ms.custom: azureday1, devx-track-azurepowershell
@@ -116,7 +116,9 @@ In **Overview**, select **Permissions**, and you'll see the added permissions fo
116
116
117
117
:::image type="content" alt-text="Screenshot that shows the Permissions pane." source="./media/scenario-secure-app-access-microsoft-graph/enterprise-apps-permissions.png":::
118
118
119
-
## Call Microsoft Graph (.NET)
119
+
## Call Microsoft Graph
120
+
121
+
# [C#](#tab/programming-language-csharp)
120
122
121
123
The [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) class is used to get a token credential for your code to authorize requests to Microsoft Graph. Create an instance of the [DefaultAzureCredential](/dotnet/api/azure.identity.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.
122
124
@@ -126,7 +128,7 @@ To see this code as part of a sample application, see the [sample on GitHub](htt
126
128
127
129
Install the [Microsoft.Identity.Web.MicrosoftGraph NuGet package](https://www.nuget.org/packages/Microsoft.Identity.Web.MicrosoftGraph) in your project by using the .NET Core command-line interface or the Package Manager Console in Visual Studio.
128
130
129
-
#[Command line](#tab/command-line)
131
+
#### .NET Core command-line
130
132
131
133
Open a command line, and switch to the directory that contains your project file.
Open the project/solution in Visual Studio, and open the console by using the **Tools** > **NuGet Package Manager** > **Package Manager Console** command.
@@ -205,6 +205,55 @@ public async Task OnGetAsync()
205
205
}
206
206
```
207
207
208
+
# [Node.js](#tab/programming-language-nodejs)
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.
211
+
212
+
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).
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:
241
+
242
+
```nodejs
243
+
getAuthenticatedClient = (accessToken) => {
244
+
// Initialize Graph client
245
+
const client = graph.Client.init({
246
+
// Use the provided access token to authenticate requests
247
+
authProvider: (done) => {
248
+
done(null, accessToken);
249
+
}
250
+
});
251
+
252
+
return client;
253
+
}
254
+
```
255
+
---
256
+
208
257
## Clean up resources
209
258
210
259
If you're finished with this tutorial and no longer need the web app or associated resources, [clean up the resources you created](scenario-secure-app-clean-up-resources.md).
Copy file name to clipboardExpand all lines: articles/app-service/scenario-secure-app-access-microsoft-graph-as-user.md
+56-7Lines changed: 56 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ manager: CelesteDG
8
8
ms.service: app-service-web
9
9
ms.topic: tutorial
10
10
ms.workload: identity
11
-
ms.date: 09/23/2021
11
+
ms.date: 11/02/2021
12
12
ms.author: ryanwi
13
13
ms.reviewer: stsoneff
14
14
ms.custom: azureday1
@@ -119,9 +119,12 @@ az rest --method PUT --url '/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RES
119
119
```
120
120
---
121
121
122
-
## Call Microsoft Graph (.NET)
122
+
## Call Microsoft Graph
123
123
124
-
Your web app now has the required permissions and also adds Microsoft Graph's client ID to the login parameters. Using the [Microsoft.Identity.Web library](https://github.com/AzureAD/microsoft-identity-web/), the web app gets an access token for authentication with Microsoft Graph. In version 1.2.0 and later, the Microsoft.Identity.Web library integrates with and can run alongside the App Service authentication/authorization module. Microsoft.Identity.Web detects that the web app is hosted in App Service and gets the access token from the App Service authentication/authorization module. The access token is then passed along to authenticated requests with the Microsoft Graph API.
124
+
Your web app now has the required permissions and also adds Microsoft Graph's client ID to the login parameters.
125
+
126
+
# [C#](#tab/programming-language-csharp)
127
+
Using the [Microsoft.Identity.Web library](https://github.com/AzureAD/microsoft-identity-web/), the web app gets an access token for authentication with Microsoft Graph. In version 1.2.0 and later, the Microsoft.Identity.Web library integrates with and can run alongside the App Service authentication/authorization module. Microsoft.Identity.Web detects that the web app is hosted in App Service and gets the access token from the App Service authentication/authorization module. The access token is then passed along to authenticated requests with the Microsoft Graph API.
125
128
126
129
To see this code as part of a sample application, see the [sample on GitHub](https://github.com/Azure-Samples/ms-identity-easyauth-dotnet-storage-graphapi/tree/main/2-WebApp-graphapi-on-behalf).
127
130
@@ -134,7 +137,7 @@ To see this code as part of a sample application, see the [sample on GitHub](htt
134
137
135
138
Install the [Microsoft.Identity.Web](https://www.nuget.org/packages/Microsoft.Identity.Web/) and [Microsoft.Identity.Web.MicrosoftGraph](https://www.nuget.org/packages/Microsoft.Identity.Web.MicrosoftGraph) NuGet packages in your project by using the .NET Core command-line interface or the Package Manager Console in Visual Studio.
136
139
137
-
#[Command line](#tab/command-line)
140
+
#### .NET Core commandline
138
141
139
142
Open a command line, and switch to the directory that contains your project file.
Open the project/solution in Visual Studio, and open the console by using the **Tools** > **NuGet Package Manager** > **Package Manager Console** command.
In the *Startup.cs* file, the ```AddMicrosoftIdentityWebApp``` method adds Microsoft.Identity.Web to your web app. The ```AddMicrosoftGraph``` method adds Microsoft Graph support.
@@ -271,6 +272,54 @@ public class IndexModel : PageModel
271
272
}
272
273
```
273
274
275
+
# [Node.js](#tab/programming-language-nodejs)
276
+
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.
278
+
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).
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):
// Use the provided access token to authenticate requests
313
+
authProvider: (done) => {
314
+
done(null, accessToken);
315
+
}
316
+
});
317
+
318
+
return client;
319
+
}
320
+
```
321
+
---
322
+
274
323
## Clean up resources
275
324
276
325
If you're finished with this tutorial and no longer need the web app or associated resources, [clean up the resources you created](scenario-secure-app-clean-up-resources.md).
@@ -203,8 +202,8 @@ az role assignment create --assignee $spID --role 'Storage Blob Data Contributor
203
202
204
203
---
205
204
206
-
## Access Blob Storage (.NET)
207
-
205
+
## Access Blob Storage
206
+
# [C#](#tab/programming-language-csharp)
208
207
The [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) class is used to get a token credential for your code to authorize requests to Azure Storage. Create an instance of the [DefaultAzureCredential](/dotnet/api/azure.identity.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 uploads a new blob.
209
208
210
209
To see this code as part of a sample application, see the [sample on GitHub](https://github.com/Azure-Samples/ms-identity-easyauth-dotnet-storage-graphapi/tree/main/1-WebApp-storage-managed-identity).
@@ -213,7 +212,7 @@ To see this code as part of a sample application, see the [sample on GitHub](htt
213
212
214
213
Install the [Blob Storage NuGet package](https://www.nuget.org/packages/Azure.Storage.Blobs/) to work with Blob Storage and the [Azure Identity client library for .NET NuGet package](https://www.nuget.org/packages/Azure.Identity/) to authenticate with Azure AD credentials. Install the client libraries by using the .NET Core command-line interface or the Package Manager Console in Visual Studio.
215
214
216
-
#[Command line](#tab/command-line)
215
+
#### .NET Core command-line
217
216
218
217
Open a command line, and switch to the directory that contains your project file.
Open the project or solution in Visual Studio, and open the console by using the **Tools** > **NuGet Package Manager** > **Package Manager Console** command.
@@ -283,6 +279,40 @@ static public async Task UploadBlob(string accountName, string containerName, st
283
279
}
284
280
```
285
281
282
+
# [Node.js](#tab/programming-language-nodejs)
283
+
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.
284
+
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).
If you're finished with this tutorial and no longer need the web app or associated resources, [clean up the resources you created](scenario-secure-app-clean-up-resources.md).
0 commit comments