Skip to content

Commit 5fa453b

Browse files
RyAuldCopilot
andcommitted
Migrate OBO tests from AppWebApi/client secret to AppOBOService/certificate
- Replace APP_WEBAPI with APP_OBO_SERVICE (MSAL-APP-TodoListService-JSON) for the CCA - Replace APP_WEBAPI PCA with APP_OBO_CLIENT (MSAL-APP-TodoListClient-JSON) - Switch from client secret credential to LabAuth certificate - Add defaultScopes field to AppConfig for OBO scope resolution - Add APP_OBO_SERVICE and APP_OBO_CLIENT constants to KeyVaultSecrets This mirrors the migration done in MSAL.NET PR #6021, moving from old lab4 apps to ID4SLAB1 tenant apps with certificate-based auth. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d4f3d07 commit 5fa453b

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.microsoft.aad.msal4j.labapi.*;
77
import static com.microsoft.aad.msal4j.labapi.KeyVaultSecrets.*;
8+
import org.junit.jupiter.api.BeforeAll;
89
import org.junit.jupiter.api.Test;
910
import org.junit.jupiter.api.TestInstance;
1011
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -16,16 +17,21 @@
1617
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1718
class OnBehalfOfIT {
1819

20+
private IClientCertificate certificate;
21+
22+
@BeforeAll
23+
void init() throws Exception {
24+
certificate = CertificateHelper.getClientCertificate();
25+
}
26+
1927
@Test
2028
void acquireTokenWithOBO_Managed() throws Exception {
2129
String accessToken = this.getAccessToken();
22-
AppConfig app = LabResponseHelper.getAppConfig(APP_WEBAPI);
30+
AppConfig oboService = LabResponseHelper.getAppConfig(APP_OBO_SERVICE);
2331
UserConfig user = LabResponseHelper.getUserConfig(USER_PUBLIC_CLOUD);
2432

25-
String password = KeyVaultRegistry.getMsalTeamProvider().getSecretByName(app.getClientSecret()).getValue();
26-
2733
ConfidentialClientApplication cca =
28-
ConfidentialClientApplication.builder(app.getAppId(), ClientCredentialFactory.createFromSecret(password)).
34+
ConfidentialClientApplication.builder(oboService.getAppId(), certificate).
2935
authority(TestConstants.MICROSOFT_AUTHORITY_HOST + user.getTenantId()).
3036
build();
3137

@@ -42,13 +48,11 @@ void acquireTokenWithOBO_Managed() throws Exception {
4248
void acquireTokenWithOBO_testCache() throws Exception {
4349
String accessToken = this.getAccessToken();
4450

45-
AppConfig app = LabResponseHelper.getAppConfig(APP_WEBAPI);
51+
AppConfig oboService = LabResponseHelper.getAppConfig(APP_OBO_SERVICE);
4652
UserConfig user = LabResponseHelper.getUserConfig(USER_PUBLIC_CLOUD);
4753

48-
String password = KeyVaultRegistry.getMsalTeamProvider().getSecretByName(app.getClientSecret()).getValue();
49-
5054
ConfidentialClientApplication cca =
51-
ConfidentialClientApplication.builder(app.getAppId(), ClientCredentialFactory.createFromSecret(password)).
55+
ConfidentialClientApplication.builder(oboService.getAppId(), certificate).
5256
authority(TestConstants.MICROSOFT_AUTHORITY_HOST + user.getTenantId()).
5357
build();
5458

@@ -125,13 +129,15 @@ private void assertResultNotNull(IAuthenticationResult result) {
125129
}
126130

127131
private String getAccessToken() throws Exception {
128-
129-
AppConfig app = LabResponseHelper.getAppConfig(APP_WEBAPI);
132+
AppConfig oboService = LabResponseHelper.getAppConfig(APP_OBO_SERVICE);
133+
AppConfig oboClient = LabResponseHelper.getAppConfig(APP_OBO_CLIENT);
130134
UserConfig user = LabResponseHelper.getUserConfig(USER_PUBLIC_CLOUD);
131135

132-
String apiReadScope = "api://" + app.getAppId() + "/access_as_user";
136+
String apiReadScope = oboService.getDefaultScopes() != null
137+
? oboService.getDefaultScopes()
138+
: "api://" + oboService.getAppId() + "/access_as_user";
133139

134-
PublicClientApplication pca = PublicClientApplication.builder(app.getAppId()).
140+
PublicClientApplication pca = PublicClientApplication.builder(oboClient.getAppId()).
135141
authority("https://login.microsoftonline.com/organizations").
136142
build();
137143

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/labapi/AppConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class AppConfig implements JsonSerializable<AppConfig> {
2323
private String labName;
2424
private String clientSecret;
2525
private String secretName;
26+
private String defaultScopes;
2627

2728
static AppConfig fromJson(JsonReader jsonReader) throws IOException {
2829
AppConfig app = new AppConfig();
@@ -57,6 +58,10 @@ static AppConfig fromJson(JsonReader jsonReader) throws IOException {
5758
case "secretName":
5859
app.secretName = reader.getString();
5960
break;
61+
case "defaultscopes":
62+
case "defaultScopes":
63+
app.defaultScopes = reader.getString();
64+
break;
6065
default:
6166
reader.skipChildren();
6267
break;
@@ -98,4 +103,8 @@ public String getClientSecret() {
98103
public String getSecretName() {
99104
return secretName;
100105
}
106+
107+
public String getDefaultScopes() {
108+
return defaultScopes;
109+
}
101110
}

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/labapi/KeyVaultSecrets.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ private KeyVaultSecrets() {
2626
public static final String APP_WEBAPI = "App-WebAPI-Config";
2727
public static final String APP_S2S = "App-S2S-Config";
2828

29+
// OBO App Configuration Secrets (ID4SLAB1 tenant, certificate-based auth)
30+
public static final String APP_OBO_SERVICE = "MSAL-APP-TodoListService-JSON";
31+
public static final String APP_OBO_CLIENT = "MSAL-APP-TodoListClient-JSON";
32+
2933
// TODO: Consolidate with others or following naming convention in key vault
3034
public static final String APP_B2C = "MSAL-App-B2C-JSON";
3135
public static final String APP_ARLINGTON = "MSAL-App-Arlington-JSON";

0 commit comments

Comments
 (0)