@@ -144,6 +144,7 @@ Run the install commands.
144
144
145
145
``` dotnetcli
146
146
dotnet add package Microsoft.Identity.Web.MicrosoftGraph
147
+ dotnet add package Microsoft.Graph
147
148
```
148
149
149
150
#### Package Manager Console
@@ -153,6 +154,7 @@ Open the project/solution in Visual Studio, and open the console by using the **
153
154
Run the install commands.
154
155
``` powershell
155
156
Install-Package Microsoft.Identity.Web.MicrosoftGraph
157
+ Install-Package Microsoft.Graph
156
158
```
157
159
158
160
### Example
@@ -162,9 +164,9 @@ using System;
162
164
using System .Collections .Generic ;
163
165
using System .Threading .Tasks ;
164
166
using Microsoft .AspNetCore .Mvc .RazorPages ;
165
- using Azure . Identity ;
166
- using Microsoft .Graph . Core ;
167
- using System . Net . Http . Headers ;
167
+ using Microsoft . Extensions . Logging ;
168
+ using Microsoft .Graph ;
169
+ using Azure . Identity ;
168
170
169
171
.. .
170
172
@@ -178,27 +180,18 @@ public async Task OnGetAsync()
178
180
var credential = new ChainedTokenCredential (
179
181
new ManagedIdentityCredential (),
180
182
new EnvironmentCredential ());
181
- var token = credential .GetToken (
182
- new Azure .Core .TokenRequestContext (
183
- new [] { " https://graph.microsoft.com/.default" }));
184
183
185
- var accessToken = token .Token ;
186
- var graphServiceClient = new GraphServiceClient (
187
- new DelegateAuthenticationProvider ((requestMessage ) =>
188
- {
189
- requestMessage
190
- .Headers
191
- .Authorization = new AuthenticationHeaderValue (" bearer" , accessToken );
184
+ string [] scopes = new [] { " https://graph.microsoft.com/.default" };
192
185
193
- return Task . CompletedTask ;
194
- }) );
186
+ var graphServiceClient = new GraphServiceClient (
187
+ credential , scopes );
195
188
196
- // MSGraphUser is a DTO class being used to hold User information from the graph service client call
197
189
List < MSGraphUser > msGraphUsers = new List <MSGraphUser >();
198
190
try
199
191
{
200
- var users = await graphServiceClient .Users .Request ().GetAsync ();
201
- foreach (var u in users )
192
+ // var users = await graphServiceClient.Users.Request().GetAsync();
193
+ var users = await graphServiceClient .Users .GetAsync ();
194
+ foreach (var u in users .Value )
202
195
{
203
196
MSGraphUser user = new MSGraphUser ();
204
197
user .userPrincipalName = u .UserPrincipalName ;
@@ -209,7 +202,7 @@ public async Task OnGetAsync()
209
202
msGraphUsers .Add (user );
210
203
}
211
204
}
212
- catch (Exception ex )
205
+ catch (Exception ex )
213
206
{
214
207
string msg = ex .Message ;
215
208
}
0 commit comments