12
12
import java .net .MalformedURLException ;
13
13
import java .net .URI ;
14
14
import java .util .Collections ;
15
+ import java .util .Map ;
16
+ import java .util .HashMap ;
15
17
import java .util .Set ;
16
18
import java .util .concurrent .BlockingQueue ;
17
19
import java .util .concurrent .LinkedBlockingQueue ;
@@ -27,7 +29,22 @@ public void acquireTokenWithAuthorizationCode_ManagedUser(String environment){
27
29
cfg = new Config (environment );
28
30
29
31
User user = labUserProvider .getDefaultUser (cfg .azureEnvironment );
30
- assertAcquireTokenAAD (user );
32
+ assertAcquireTokenAAD (user , null );
33
+ }
34
+
35
+ //TODO: Re-enable test once list of claims/capabilities and their expected behavior is known
36
+ //@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
37
+ public void acquireTokenWithAuthorizationCode_ManagedUserWithClaimsAndCapabilities (String environment ){
38
+ cfg = new Config (environment );
39
+
40
+ User user = labUserProvider .getDefaultUser (cfg .azureEnvironment );
41
+
42
+ Map <String , Set <String >> claimsAndCapabilities = new HashMap <>();
43
+
44
+ claimsAndCapabilities .put ("claims" , Collections .singleton (TestConstants .CLAIMS ));
45
+ claimsAndCapabilities .put ("clientCapabilities" , TestConstants .CLIENT_CAPABILITIES_EMPTY );
46
+
47
+ assertAcquireTokenAAD (user , claimsAndCapabilities );
31
48
}
32
49
33
50
@ Test
@@ -41,7 +58,7 @@ public void acquireTokenWithAuthorizationCode_ADFSv2019_Federated(String environ
41
58
cfg = new Config (environment );
42
59
43
60
User user = labUserProvider .getFederatedAdfsUser (cfg .azureEnvironment , FederationProvider .ADFS_2019 );
44
- assertAcquireTokenAAD (user );
61
+ assertAcquireTokenAAD (user , null );
45
62
}
46
63
47
64
@ Test (dataProvider = "environments" , dataProviderClass = EnvironmentsProvider .class )
@@ -50,23 +67,23 @@ public void acquireTokenWithAuthorizationCode_ADFSv4_Federated(String environmen
50
67
51
68
User user = labUserProvider .getFederatedAdfsUser (cfg .azureEnvironment , FederationProvider .ADFS_4 );
52
69
53
- assertAcquireTokenAAD (user );
70
+ assertAcquireTokenAAD (user , null );
54
71
}
55
72
56
73
@ Test (dataProvider = "environments" , dataProviderClass = EnvironmentsProvider .class )
57
74
public void acquireTokenWithAuthorizationCode_ADFSv3_Federated (String environment ){
58
75
cfg = new Config (environment );
59
76
60
77
User user = labUserProvider .getFederatedAdfsUser (cfg .azureEnvironment , FederationProvider .ADFS_3 );
61
- assertAcquireTokenAAD (user );
78
+ assertAcquireTokenAAD (user , null );
62
79
}
63
80
64
81
@ Test (dataProvider = "environments" , dataProviderClass = EnvironmentsProvider .class )
65
82
public void acquireTokenWithAuthorizationCode_ADFSv2_Federated (String environment ){
66
83
cfg = new Config (environment );
67
84
68
85
User user = labUserProvider .getFederatedAdfsUser (cfg .azureEnvironment , FederationProvider .ADFS_2 );
69
- assertAcquireTokenAAD (user );
86
+ assertAcquireTokenAAD (user , null );
70
87
}
71
88
72
89
@ Test (dataProvider = "environments" , dataProviderClass = EnvironmentsProvider .class )
@@ -119,7 +136,7 @@ private void assertAcquireTokenADFS2019(User user){
119
136
throw new RuntimeException (ex .getMessage ());
120
137
}
121
138
122
- String authCode = acquireAuthorizationCodeAutomated (user , pca );
139
+ String authCode = acquireAuthorizationCodeAutomated (user , pca , null );
123
140
IAuthenticationResult result = acquireTokenAuthorizationCodeFlow (
124
141
pca ,
125
142
authCode ,
@@ -131,19 +148,24 @@ private void assertAcquireTokenADFS2019(User user){
131
148
Assert .assertEquals (user .getUpn (), result .account ().username ());
132
149
}
133
150
134
- private void assertAcquireTokenAAD (User user ){
151
+ private void assertAcquireTokenAAD (User user , Map < String , Set < String >> parameters ){
135
152
136
153
PublicClientApplication pca ;
154
+ Set <String > clientCapabilities = null ;
155
+ if (parameters != null ) {
156
+ clientCapabilities = parameters .getOrDefault ("clientCapabilities" , null );
157
+ }
137
158
try {
138
- pca = PublicClientApplication .builder (
139
- user .getAppId ()).
140
- authority (cfg .organizationsAuthority ()).
141
- build ();
159
+ pca = PublicClientApplication .builder (
160
+ user .getAppId ()).
161
+ authority (cfg .organizationsAuthority ()).
162
+ clientCapabilities (clientCapabilities ).
163
+ build ();
142
164
} catch (MalformedURLException ex ){
143
165
throw new RuntimeException (ex .getMessage ());
144
166
}
145
167
146
- String authCode = acquireAuthorizationCodeAutomated (user , pca );
168
+ String authCode = acquireAuthorizationCodeAutomated (user , pca , parameters );
147
169
IAuthenticationResult result = acquireTokenAuthorizationCodeFlow (
148
170
pca ,
149
171
authCode ,
@@ -158,7 +180,7 @@ private void assertAcquireTokenAAD(User user){
158
180
private void assertAcquireTokenB2C (User user ){
159
181
160
182
String appId = LabService .getSecret (TestConstants .B2C_CONFIDENTIAL_CLIENT_LAB_APP_ID );
161
- String appSecret = LabService .getSecret (TestConstants .B2C_CONFIDENTIAL_CLIENT_APP_SECRET );
183
+ String appSecret = LabService .getSecret (TestConstants .B2C_CONFIDENTIAL_CLIENT_APP_SECRETID );
162
184
163
185
ConfidentialClientApplication cca ;
164
186
try {
@@ -171,7 +193,7 @@ private void assertAcquireTokenB2C(User user){
171
193
throw new RuntimeException (ex .getMessage ());
172
194
}
173
195
174
- String authCode = acquireAuthorizationCodeAutomated (user , cca );
196
+ String authCode = acquireAuthorizationCodeAutomated (user , cca , null );
175
197
IAuthenticationResult result = acquireTokenInteractiveB2C (cca , authCode );
176
198
177
199
Assert .assertNotNull (result );
@@ -218,7 +240,8 @@ private IAuthenticationResult acquireTokenInteractiveB2C(ConfidentialClientAppli
218
240
219
241
private String acquireAuthorizationCodeAutomated (
220
242
User user ,
221
- AbstractClientApplicationBase app ){
243
+ AbstractClientApplicationBase app ,
244
+ Map <String , Set <String >> parameters ){
222
245
223
246
BlockingQueue <AuthorizationResult > authorizationCodeQueue = new LinkedBlockingQueue <>();
224
247
@@ -231,7 +254,7 @@ private String acquireAuthorizationCodeAutomated(
231
254
232
255
AuthorizationResult result = null ;
233
256
try {
234
- String url = buildAuthenticationCodeURL (app );
257
+ String url = buildAuthenticationCodeURL (app , parameters );
235
258
seleniumDriver .navigate ().to (url );
236
259
runSeleniumAutomatedLogin (user , app );
237
260
@@ -256,9 +279,15 @@ private String acquireAuthorizationCodeAutomated(
256
279
}
257
280
return result .code ();
258
281
}
259
- private String buildAuthenticationCodeURL (AbstractClientApplicationBase app ) {
282
+
283
+ private String buildAuthenticationCodeURL (AbstractClientApplicationBase app , Map <String , Set <String >> parameters ) {
260
284
String scope ;
261
285
286
+ String claims = null ;
287
+ if (parameters != null ) {
288
+ claims = String .valueOf (parameters .getOrDefault ("claims" , Collections .singleton ("" )).toArray ()[0 ]);
289
+ }
290
+
262
291
AuthorityType authorityType = app .authenticationAuthority .authorityType ;
263
292
if (authorityType == AuthorityType .AAD ){
264
293
scope = TestConstants .GRAPH_DEFAULT_SCOPE ;
@@ -272,12 +301,13 @@ else if (authorityType == AuthorityType.ADFS){
272
301
throw new RuntimeException ("Authority type not recognized" );
273
302
}
274
303
275
- AuthorizationRequestUrlParameters parameters =
304
+ AuthorizationRequestUrlParameters authParameters =
276
305
AuthorizationRequestUrlParameters
277
306
.builder (TestConstants .LOCALHOST + httpListener .port (),
278
307
Collections .singleton (scope ))
308
+ .claimsChallenge (claims )
279
309
.build ();
280
310
281
- return app .getAuthorizationRequestUrl (parameters ).toString ();
311
+ return app .getAuthorizationRequestUrl (authParameters ).toString ();
282
312
}
283
313
}
0 commit comments