17
17
using Microsoft . Azure . Graph . RBAC ;
18
18
using Microsoft . Azure . Graph . RBAC . Models ;
19
19
using Microsoft . Rest . Azure ;
20
+ using Microsoft . Rest . Azure . OData ;
20
21
using System ;
21
22
using System . Collections . Generic ;
22
23
using System . Diagnostics ;
@@ -39,9 +40,10 @@ public ActiveDirectoryClient(IAuthenticationFactory authenticationFactory, IClie
39
40
{
40
41
AccessTokenCredential creds = ( AccessTokenCredential ) authenticationFactory . GetSubscriptionCloudCredentials ( context ) ;
41
42
GraphClient = clientFactory . CreateCustomArmClient < GraphRbacManagementClient > (
42
- creds . TenantID ,
43
- creds ,
44
- context . Environment . GetEndpointAsUri ( AzureEnvironment . Endpoint . Graph ) ) ;
43
+ context . Environment . GetEndpointAsUri ( AzureEnvironment . Endpoint . Graph ) ,
44
+ creds ) ;
45
+ GraphClient . TenantID = creds . TenantID ;
46
+ GraphClient . SubscriptionId = creds . SubscriptionId ;
45
47
}
46
48
47
49
public PSADObject GetADObject ( ADObjectFilterOptions options )
@@ -101,7 +103,7 @@ public List<PSADServicePrincipal> FilterServicePrincipals(ADObjectFilterOptions
101
103
try
102
104
{
103
105
servicePrincipal = GraphClient . ServicePrincipal
104
- . List ( item => item . ServicePrincipalNames . Contains ( options . SPN ) )
106
+ . List ( new ODataQuery < ServicePrincipal > ( item => item . ServicePrincipalNames . Contains ( options . SPN ) ) )
105
107
. FirstOrDefault ( ) ;
106
108
}
107
109
catch { /* The user does not exist, ignore the exception. */ }
@@ -120,7 +122,7 @@ public List<PSADServicePrincipal> FilterServicePrincipals(ADObjectFilterOptions
120
122
if ( string . IsNullOrEmpty ( options . NextLink ) )
121
123
{
122
124
result = GraphClient . ServicePrincipal
123
- . List ( item => item . DisplayName . StartsWith ( options . SearchString ) ) ;
125
+ . List ( new ODataQuery < ServicePrincipal > ( item => item . DisplayName . StartsWith ( options . SearchString ) ) ) ;
124
126
}
125
127
else
126
128
{
@@ -132,7 +134,7 @@ public List<PSADServicePrincipal> FilterServicePrincipals(ADObjectFilterOptions
132
134
}
133
135
else
134
136
{
135
- result = GraphClient . ServicePrincipal . List ( item => item . DisplayName . StartsWith ( options . SearchString ) ) ;
137
+ result = GraphClient . ServicePrincipal . List ( new ODataQuery < ServicePrincipal > ( item => item . DisplayName . StartsWith ( options . SearchString ) ) ) ;
136
138
servicePrincipals . AddRange ( result . Select ( u => u . ToPSADServicePrincipal ( ) ) ) ;
137
139
138
140
while ( ! string . IsNullOrEmpty ( result . NextPageLink ) )
@@ -175,7 +177,7 @@ public List<PSADUser> FilterUsers(ADObjectFilterOptions options)
175
177
try
176
178
{
177
179
user = GraphClient . User
178
- . List ( item => item . SignInName == ( Normalize ( options . Mail ) ?? Normalize ( options . SignInName ) ) )
180
+ . List ( new ODataQuery < User > ( item => item . SignInName == ( Normalize ( options . Mail ) ?? Normalize ( options . SignInName ) ) ) )
179
181
. FirstOrDefault ( ) ;
180
182
}
181
183
catch { /* The user does not exist, ignore the exception. */ }
@@ -191,7 +193,7 @@ public List<PSADUser> FilterUsers(ADObjectFilterOptions options)
191
193
{
192
194
if ( string . IsNullOrEmpty ( options . NextLink ) )
193
195
{
194
- result = GraphClient . User . List ( item => item . DisplayName . StartsWith ( options . SearchString ) ) ;
196
+ result = GraphClient . User . List ( new ODataQuery < User > ( item => item . DisplayName . StartsWith ( options . SearchString ) ) ) ;
195
197
}
196
198
else
197
199
{
@@ -203,7 +205,7 @@ public List<PSADUser> FilterUsers(ADObjectFilterOptions options)
203
205
}
204
206
else
205
207
{
206
- result = GraphClient . User . List ( item => item . DisplayName . StartsWith ( options . SearchString ) ) ;
208
+ result = GraphClient . User . List ( new ODataQuery < User > ( item => item . DisplayName . StartsWith ( options . SearchString ) ) ) ;
207
209
users . AddRange ( result . Select ( u => u . ToPSADUser ( ) ) ) ;
208
210
209
211
while ( ! string . IsNullOrEmpty ( result . NextPageLink ) )
@@ -273,8 +275,8 @@ public List<PSADGroup> FilterGroups(ADObjectFilterOptions options)
273
275
{
274
276
if ( string . IsNullOrEmpty ( options . NextLink ) )
275
277
{
276
- result = GraphClient . Group . List (
277
- item => item . Mail == options . Mail && item . DisplayName . StartsWith ( options . SearchString ) ) ;
278
+ result = GraphClient . Group . List ( new ODataQuery < ADGroup > (
279
+ item => item . Mail == options . Mail && item . DisplayName . StartsWith ( options . SearchString ) ) ) ;
278
280
}
279
281
else
280
282
{
@@ -286,8 +288,8 @@ public List<PSADGroup> FilterGroups(ADObjectFilterOptions options)
286
288
}
287
289
else
288
290
{
289
- result = GraphClient . Group . List (
290
- item => item . Mail == options . Mail && item . DisplayName . StartsWith ( options . SearchString ) ) ;
291
+ result = GraphClient . Group . List ( new ODataQuery < ADGroup > (
292
+ item => item . Mail == options . Mail && item . DisplayName . StartsWith ( options . SearchString ) ) ) ;
291
293
groups . AddRange ( result . Select ( g => g . ToPSADGroup ( ) ) ) ;
292
294
293
295
while ( ! string . IsNullOrEmpty ( result . NextPageLink ) )
0 commit comments