Skip to content

Commit 7ef0518

Browse files
committed
Fix tests
1 parent dd8c51a commit 7ef0518

1 file changed

Lines changed: 31 additions & 8 deletions

File tree

  • msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/AgenticIT.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ class AgenticIT {
4444

4545
// Lab test configuration
4646
private static final String BLUEPRINT_CLIENT_ID = "aab5089d-e764-47e3-9f28-cc11c2513821";
47+
private static final String RMA_CLIENT_ID = "3bf56293-fbb5-42bd-a407-248ba7431a8c";
4748
private static final String TENANT_ID = "10c419d4-4a50-45b2-aa4e-919fb84df24f";
4849
private static final String AGENT_APP_ID = "ab18ca07-d139-4840-8b3b-4be9610c6ed5";
4950
private static final String TOKEN_EXCHANGE_SCOPE = "api://AzureADTokenExchange/.default";
51+
private static final String FMI_EXCHANGE_SCOPE = "api://AzureFMITokenExchange/.default";
5052
private static final String GRAPH_SCOPE = "https://graph.microsoft.com/.default";
5153
private static final String AZURE_REGION = "westus3";
5254

@@ -117,7 +119,7 @@ void assertionCallback_ReceivesFmiPathContext() throws Exception {
117119
Function<AssertionRequestOptions, String> assertionProvider = options -> {
118120
capturedOptions.set(options);
119121
try {
120-
return acquireFmiCredentialForAgent(options.fmiPath());
122+
return acquireFmiCredentialFromRma();
121123
} catch (Exception e) {
122124
throw new RuntimeException("Failed to acquire FMI credential", e);
123125
}
@@ -132,7 +134,7 @@ void assertionCallback_ReceivesFmiPathContext() throws Exception {
132134
.build();
133135

134136
ClientCredentialParameters params = ClientCredentialParameters
135-
.builder(Collections.singleton(TOKEN_EXCHANGE_SCOPE))
137+
.builder(Collections.singleton(FMI_EXCHANGE_SCOPE))
136138
.fmiPath(AGENT_APP_ID)
137139
.skipCache(true)
138140
.build();
@@ -194,9 +196,7 @@ void agentAppToken_CacheHit() throws Exception {
194196
void agentFmiToken_CacheIsolation_DifferentFmiPaths() throws Exception {
195197
Function<AssertionRequestOptions, String> assertionProvider = options -> {
196198
try {
197-
// Use the fmiPath from the context if available, otherwise use default agent ID
198-
String targetPath = options.fmiPath() != null ? options.fmiPath() : AGENT_APP_ID;
199-
return acquireFmiCredentialForAgent(targetPath);
199+
return acquireFmiCredentialFromRma();
200200
} catch (Exception e) {
201201
throw new RuntimeException("Failed to acquire FMI credential", e);
202202
}
@@ -212,14 +212,14 @@ void agentFmiToken_CacheIsolation_DifferentFmiPaths() throws Exception {
212212

213213
// Acquire with first fmi_path
214214
ClientCredentialParameters params1 = ClientCredentialParameters
215-
.builder(Collections.singleton(TOKEN_EXCHANGE_SCOPE))
215+
.builder(Collections.singleton(FMI_EXCHANGE_SCOPE))
216216
.fmiPath(AGENT_APP_ID)
217217
.build();
218218
IAuthenticationResult result1 = cca.acquireToken(params1).get();
219219

220220
// Acquire with different fmi_path
221221
ClientCredentialParameters params2 = ClientCredentialParameters
222-
.builder(Collections.singleton(TOKEN_EXCHANGE_SCOPE))
222+
.builder(Collections.singleton(FMI_EXCHANGE_SCOPE))
223223
.fmiPath("SomeFmiPath/DifferentAgent")
224224
.build();
225225
IAuthenticationResult result2 = cca.acquireToken(params2).get();
@@ -233,7 +233,7 @@ void agentFmiToken_CacheIsolation_DifferentFmiPaths() throws Exception {
233233

234234
/**
235235
* Helper: acquires an FMI credential from the blueprint app for the given agent app ID.
236-
* This is Leg 1 of the agent identity flow.
236+
* Uses the agent token exchange scope (api://AzureADTokenExchange).
237237
*/
238238
private String acquireFmiCredentialForAgent(String agentAppId) throws Exception {
239239
IClientCertificate clientCert = ClientCredentialFactory.createFromCertificate(privateKey, certificate);
@@ -253,4 +253,27 @@ private String acquireFmiCredentialForAgent(String agentAppId) throws Exception
253253
IAuthenticationResult result = blueprintCca.acquireToken(params).get();
254254
return result.accessToken();
255255
}
256+
257+
/**
258+
* Helper: acquires an FMI credential from the RMA using a certificate.
259+
* Uses the FMI-specific exchange scope (api://AzureFMITokenExchange).
260+
*/
261+
private String acquireFmiCredentialFromRma() throws Exception {
262+
IClientCertificate clientCert = ClientCredentialFactory.createFromCertificate(privateKey, certificate);
263+
264+
ConfidentialClientApplication rmaCca = ConfidentialClientApplication.builder(
265+
RMA_CLIENT_ID, clientCert)
266+
.authority(AUTHORITY)
267+
.sendX5c(true)
268+
.azureRegion(AZURE_REGION)
269+
.build();
270+
271+
ClientCredentialParameters params = ClientCredentialParameters
272+
.builder(Collections.singleton(FMI_EXCHANGE_SCOPE))
273+
.fmiPath("SomeFmiPath/FmiCredentialPath")
274+
.build();
275+
276+
IAuthenticationResult result = rmaCca.acquireToken(params).get();
277+
return result.accessToken();
278+
}
256279
}

0 commit comments

Comments
 (0)