Skip to content

Commit

Permalink
Add auth code integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Avery-Dunn committed Aug 10, 2024
1 parent ba03f5a commit 87ef350
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,45 @@ public void acquireTokenWithAuthorizationCode_B2C_Local(String environment) {
assertAcquireTokenB2C(user);
}

@Test
public void acquireTokenWithAuthorizationCode_CiamCud() throws Exception {
String authorityCud = "https://login.msidlabsciam.com/fe362aec-5d43-45d1-b730-9755e60dc3b9/v2.0/";
User user = labUserProvider.getCiamCudUser();

ConfidentialClientApplication cca = ConfidentialClientApplication
.builder(user.getAppId(), CertificateHelper.getClientCertificate())
.oidcAuthority(authorityCud)
.build();

assertEquals("https://login.msidlabsciam.com/fe362aec-5d43-45d1-b730-9755e60dc3b9/v2.0/.well-known/openid-configuration",
cca.authenticationAuthority.canonicalAuthorityUrl.toString());
assertEquals("https://login.msidlabsciam.com/fe362aec-5d43-45d1-b730-9755e60dc3b9/oauth2/v2.0/authorize",
cca.authenticationAuthority.authorizationEndpoint);

String authCode = acquireAuthorizationCodeAutomated(user, cca, null);

IAuthenticationResult result = cca.acquireToken(AuthorizationCodeParameters
.builder(authCode,
new URI(TestConstants.LOCALHOST + httpListener.port()))
.scopes(Collections.singleton("user.read"))
.build())
.get();

assertNotNull(result);
assertNotNull(result.accessToken());
assertNotNull(result.idToken());
assertEquals(user.getUpn(), result.account().username());

IAuthenticationResult resultSilent = cca.acquireTokenSilently(SilentParameters
.builder(Collections.singleton("user.read"), result.account())
.build())
.get();

assertNotNull(resultSilent);
assertEquals(resultSilent.accessToken(), result.accessToken());
assertEquals(resultSilent.account().username(), result.account().username());
}

private void assertAcquireTokenADFS2019(User user) {
PublicClientApplication pca;
try {
Expand Down Expand Up @@ -261,6 +300,8 @@ private String buildAuthenticationCodeURL(AbstractClientApplicationBase app, Map
scope = TestConstants.B2C_LAB_SCOPE;
} else if (authorityType == AuthorityType.ADFS) {
scope = TestConstants.ADFS_SCOPE;
} else if (authorityType == AuthorityType.OIDC) {
scope = TestConstants.USER_READ_SCOPE;
} else {
throw new RuntimeException("Authority type not recognized");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void runSeleniumAutomatedLogin(User user, AbstractClientApplicationBase app) {
SeleniumExtensions.performADOrCiamLogin(seleniumDriver, user);
} else if (authorityType == AuthorityType.ADFS) {
SeleniumExtensions.performADFS2019Login(seleniumDriver, user);
} else if (authorityType == AuthorityType.CIAM || authorityType == AuthorityType.GENERIC) {
} else if (authorityType == AuthorityType.CIAM || authorityType == AuthorityType.OIDC) {
SeleniumExtensions.performADOrCiamLogin(seleniumDriver, user);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class FederationProvider {
public static final String ADFS_4 = "adfsv4";
public static final String ADFS_2019 = "adfsv2019";
public static final String CIAM = "ciam";
public static final String CIAMCUD = "ciamcud";

}

Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public User getCiamUser() {
return getLabUser(query);
}

public User getCiamCudUser() {
UserQueryParameters query = new UserQueryParameters();
query.parameters.put(UserQueryParameters.FEDERATION_PROVIDER, FederationProvider.CIAMCUD);
query.parameters.put(UserQueryParameters.SIGN_IN_AUDIENCE, "azureadmyorg");

return getLabUser(query);
}

public User getLabUser(UserQueryParameters userQuery) {
if (userCache.containsKey(userQuery)) {
return userCache.get(userQuery);
Expand Down

0 comments on commit 87ef350

Please sign in to comment.