15
15
import org .junit .jupiter .params .provider .MethodSource ;
16
16
import static org .junit .jupiter .api .Assertions .assertEquals ;
17
17
import static org .junit .jupiter .api .Assertions .assertNotEquals ;
18
- import static org .junit .jupiter .api .Assertions .assertNotNull ;
19
18
20
19
import java .net .MalformedURLException ;
21
20
import java .net .URI ;
@@ -53,7 +52,7 @@ void acquireTokenInteractive_ManagedUser(String environment) {
53
52
cfg = new Config (environment );
54
53
55
54
User user = labUserProvider .getDefaultUser (cfg .azureEnvironment );
56
- assertAcquireTokenCommon (user , cfg .organizationsAuthority (), cfg .graphDefaultScope ());
55
+ assertAcquireTokenCommon (user , cfg .commonAuthority (), cfg .graphDefaultScope ());
57
56
}
58
57
59
58
@ Test ()
@@ -146,27 +145,19 @@ void acquireTokenInteractive_Ciam() {
146
145
throw new RuntimeException ("Error acquiring token with authCode: " + e .getMessage ());
147
146
}
148
147
149
- assertTokenResultNotNull (result );
148
+ IntegrationTestHelper . assertAccessAndIdTokensNotNull (result );
150
149
assertEquals (user .getUpn (), result .account ().username ());
151
150
}
152
151
153
152
private void assertAcquireTokenCommon (User user , String authority , String scope ) {
154
- PublicClientApplication pca ;
155
- try {
156
- pca = PublicClientApplication .builder (
157
- user .getAppId ()).
158
- authority (authority ).
159
- build ();
160
- } catch (MalformedURLException ex ) {
161
- throw new RuntimeException (ex .getMessage ());
162
- }
153
+ PublicClientApplication pca = IntegrationTestHelper .createPublicApp (user .getAppId (), authority );
163
154
164
155
IAuthenticationResult result = acquireTokenInteractive (
165
156
user ,
166
157
pca ,
167
158
scope );
168
159
169
- assertTokenResultNotNull (result );
160
+ IntegrationTestHelper . assertAccessAndIdTokensNotNull (result );
170
161
assertEquals (user .getUpn (), result .account ().username ());
171
162
}
172
163
@@ -183,23 +174,15 @@ private void assertAcquireTokenB2C(User user, String authority) {
183
174
}
184
175
185
176
IAuthenticationResult result = acquireTokenInteractive (user , pca , user .getAppId ());
186
- assertTokenResultNotNull (result );
177
+ IntegrationTestHelper . assertAccessAndIdTokensNotNull (result );
187
178
}
188
179
189
180
private void assertAcquireTokenInstanceAware (User user ) {
190
- PublicClientApplication pca ;
191
- try {
192
- pca = PublicClientApplication .builder (
193
- user .getAppId ()).
194
- authority (cfg .organizationsAuthority ()).
195
- build ();
196
- } catch (MalformedURLException ex ) {
197
- throw new RuntimeException (ex .getMessage ());
198
- }
181
+ PublicClientApplication pca = IntegrationTestHelper .createPublicApp (user .getAppId (), TestConstants .MICROSOFT_AUTHORITY_HOST + user .getTenantID ());
199
182
200
183
IAuthenticationResult result = acquireTokenInteractive_instanceAware (user , pca , cfg .graphDefaultScope ());
201
184
202
- assertTokenResultNotNull (result );
185
+ IntegrationTestHelper . assertAccessAndIdTokensNotNull (result );
203
186
assertEquals (user .getUpn (), result .account ().username ());
204
187
205
188
//This test is using a client app with the login.microsoftonline.com config to get tokens for a login.microsoftonline.us user,
@@ -253,7 +236,7 @@ public void afterCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext)
253
236
build ();
254
237
255
238
IAuthenticationResult result = acquireTokenInteractive (user , publicCloudPca , TestConstants .USER_READ_SCOPE );
256
- assertTokenResultNotNull (result );
239
+ IntegrationTestHelper . assertAccessAndIdTokensNotNull (result );
257
240
assertEquals (user .getHomeUPN (), result .account ().username ());
258
241
259
242
publicCloudPca .removeAccount (publicCloudPca .getAccounts ().join ().iterator ().next ()).join ();
@@ -291,12 +274,6 @@ private IAuthenticationResult acquireTokenInteractive(
291
274
return result ;
292
275
}
293
276
294
- private void assertTokenResultNotNull (IAuthenticationResult result ) {
295
- assertNotNull (result );
296
- assertNotNull (result .accessToken ());
297
- assertNotNull (result .idToken ());
298
- }
299
-
300
277
private IAuthenticationResult acquireTokenInteractive_instanceAware (
301
278
User user ,
302
279
PublicClientApplication pca ,
0 commit comments