Skip to content

Commit b15f3ff

Browse files
committed
Merge branch 'nebharg/MsiAzureArc' of https://github.com/AzureAD/microsoft-authentication-library-for-java into nebharg/MsiAzureArc
2 parents 75f212b + 10c5077 commit b15f3ff

File tree

8 files changed

+19
-4
lines changed

8 files changed

+19
-4
lines changed

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AbstractApplicationBase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public abstract class AbstractApplicationBase implements IApplicationBase {
5959
@Getter
6060
private Integer readTimeoutForDefaultHttpClient;
6161

62+
@Accessors(fluent = true)
63+
@Getter(AccessLevel.PACKAGE)
64+
String tenant;
65+
6266
//The following fields are set in only some applications and/or set internally by the library. To avoid excessive
6367
// type casting throughout the library they are defined here as package-private, but will not be part of this class's Builder
6468
@Accessors(fluent = true)

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ConfidentialClientApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ private ConfidentialClientApplication(Builder builder) {
8787
log = LoggerFactory.getLogger(ConfidentialClientApplication.class);
8888

8989
initClientAuthentication(builder.clientCredential);
90+
91+
this.tenant = this.authenticationAuthority.tenant;
9092
}
9193

9294
private void initClientAuthentication(IClientCredential clientCredential) {

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ final class Constants {
1313

1414
public static final String MANAGED_IDENTITY_CLIENT_ID = "client_id";
1515
public static final String MANAGED_IDENTITY_RESOURCE_ID = "mi_res_id";
16+
public static final String MANAGED_IDENTITY_DEFAULT_TENTANT = "managed_identity";
1617

1718
public static final String IDENTITY_ENDPOINT = "IDENTITY_ENDPOINT";
1819
public static final String IDENTITY_HEADER = "IDENTITY_HEADER";

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityApplication.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ public class ManagedIdentityApplication extends AbstractApplicationBase implemen
2424

2525
private ManagedIdentityApplication(Builder builder) {
2626
super(builder);
27-
this.managedIdentityId = builder.managedIdentityId;
27+
2828
log = LoggerFactory.getLogger(ManagedIdentityApplication.class);
2929
super.tokenCache = sharedTokenCache;
30+
31+
this.managedIdentityId = builder.managedIdentityId;
32+
this.tenant = Constants.MANAGED_IDENTITY_DEFAULT_TENTANT;
3033
}
3134

3235
@Override

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityParameters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public Map<String, String> extraHttpHeaders() {
4646

4747
@Override
4848
public String tenant() {
49-
return "managed_identity";
49+
return Constants.MANAGED_IDENTITY_DEFAULT_TENTANT;
5050
}
5151

5252
@Override

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/PublicClientApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ private PublicClientApplication(Builder builder) {
122122
log = LoggerFactory.getLogger(PublicClientApplication.class);
123123
this.clientAuthentication = new ClientAuthenticationPost(ClientAuthenticationMethod.NONE,
124124
new ClientID(clientId()));
125+
this.tenant = this.authenticationAuthority.tenant;
125126
}
126127

127128
@Override

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private static AccessTokenCacheEntity createAccessTokenCacheEntity(TokenRequestE
252252
at.environment(environmentAlias);
253253
at.clientId(tokenRequestExecutor.getMsalRequest().application().clientId());
254254
at.secret(authenticationResult.accessToken());
255-
at.realm(tokenRequestExecutor.requestAuthority.tenant());
255+
at.realm(tokenRequestExecutor.tenant);
256256

257257
String scopes = !StringHelper.isBlank(authenticationResult.scopes()) ? authenticationResult.scopes() :
258258
tokenRequestExecutor.getMsalRequest().msalAuthorizationGrant().getScopes();
@@ -289,7 +289,7 @@ private static IdTokenCacheEntity createIdTokenCacheEntity(TokenRequestExecutor
289289
idToken.environment(environmentAlias);
290290
idToken.clientId(tokenRequestExecutor.getMsalRequest().application().clientId());
291291
idToken.secret(authenticationResult.idToken());
292-
idToken.realm(tokenRequestExecutor.requestAuthority.tenant());
292+
idToken.realm(tokenRequestExecutor.tenant);
293293

294294
if (tokenRequestExecutor.getMsalRequest() instanceof OnBehalfOfRequest) {
295295
OnBehalfOfRequest onBehalfOfRequest = (OnBehalfOfRequest) tokenRequestExecutor.getMsalRequest();

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenRequestExecutor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ class TokenRequestExecutor {
2323
Logger log = LoggerFactory.getLogger(TokenRequestExecutor.class);
2424

2525
final Authority requestAuthority;
26+
final String tenant;
2627
private final MsalRequest msalRequest;
2728
private final ServiceBundle serviceBundle;
2829

2930
TokenRequestExecutor(Authority requestAuthority, MsalRequest msalRequest, ServiceBundle serviceBundle) {
3031
this.requestAuthority = requestAuthority;
3132
this.serviceBundle = serviceBundle;
3233
this.msalRequest = msalRequest;
34+
this.tenant = msalRequest.requestContext().apiParameters().tenant() == null ?
35+
msalRequest.application().tenant() :
36+
msalRequest.requestContext().apiParameters().tenant() ;
3337
}
3438

3539
AuthenticationResult executeTokenRequest() throws ParseException, IOException {

0 commit comments

Comments
 (0)