@@ -40,6 +40,7 @@ Run the install commands.
40
40
41
41
``` dotnetcli
42
42
dotnet add package Microsoft.Identity.Web.MicrosoftGraph
43
+ dotnet add package Microsoft.Graph
43
44
```
44
45
45
46
#### Package Manager Console
@@ -49,6 +50,7 @@ Open the project/solution in Visual Studio, and open the console by using the **
49
50
Run the install commands.
50
51
``` powershell
51
52
Install-Package Microsoft.Identity.Web.MicrosoftGraph
53
+ Install-Package Microsoft.Graph
52
54
```
53
55
54
56
### .NET Example
@@ -58,9 +60,9 @@ using System;
58
60
using System .Collections .Generic ;
59
61
using System .Threading .Tasks ;
60
62
using Microsoft .AspNetCore .Mvc .RazorPages ;
61
- using Azure . Identity ;
62
- using Microsoft .Graph . Core ;
63
- using System . Net . Http . Headers ;
63
+ using Microsoft . Extensions . Logging ;
64
+ using Microsoft .Graph ;
65
+ using Azure . Identity ;
64
66
65
67
.. .
66
68
@@ -74,27 +76,18 @@ public async Task OnGetAsync()
74
76
var credential = new ChainedTokenCredential (
75
77
new ManagedIdentityCredential (),
76
78
new EnvironmentCredential ());
77
- var token = credential .GetToken (
78
- new Azure .Core .TokenRequestContext (
79
- new [] { " https://graph.microsoft.com/.default" }));
80
79
81
- var accessToken = token .Token ;
82
- var graphServiceClient = new GraphServiceClient (
83
- new DelegateAuthenticationProvider ((requestMessage ) =>
84
- {
85
- requestMessage
86
- .Headers
87
- .Authorization = new AuthenticationHeaderValue (" bearer" , accessToken );
80
+ string [] scopes = new [] { " https://graph.microsoft.com/.default" };
88
81
89
- return Task . CompletedTask ;
90
- }) );
82
+ var graphServiceClient = new GraphServiceClient (
83
+ credential , scopes );
91
84
92
- // MSGraphUser is a DTO class being used to hold User information from the graph service client call
93
85
List < MSGraphUser > msGraphUsers = new List <MSGraphUser >();
94
86
try
95
87
{
96
- var users = await graphServiceClient .Users .Request ().GetAsync ();
97
- foreach (var u in users )
88
+ // var users = await graphServiceClient.Users.Request().GetAsync();
89
+ var users = await graphServiceClient .Users .GetAsync ();
90
+ foreach (var u in users .Value )
98
91
{
99
92
MSGraphUser user = new MSGraphUser ();
100
93
user .userPrincipalName = u .UserPrincipalName ;
@@ -105,7 +98,7 @@ public async Task OnGetAsync()
105
98
msGraphUsers .Add (user );
106
99
}
107
100
}
108
- catch (Exception ex )
101
+ catch (Exception ex )
109
102
{
110
103
string msg = ex .Message ;
111
104
}
0 commit comments