Skip to content

Commit

Permalink
Merge pull request #1055 from gautamdsheth/feature/improv-msal
Browse files Browse the repository at this point in the history
Feature: improve performance of MSAL for token caching by disabling legacy ADAL.NET cache
  • Loading branch information
gautamdsheth authored Aug 29, 2024
2 parents a2587ba + 4de3d15 commit 4f48009
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/lib/PnP.Framework/AuthenticationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,23 +361,23 @@ public AuthenticationManager(string endpoint, string identityHeader, ManagedIden
{
case ManagedIdentityType.UserAssignedByClientId:
Diagnostics.Log.Debug(Constants.LOGGING_SOURCE, $"Using the user assigned managed identity with client ID: {managedIdentityUserAssignedIdentifier}");
mi = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.WithUserAssignedClientId(managedIdentityUserAssignedIdentifier)).Build();
mi = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.WithUserAssignedClientId(managedIdentityUserAssignedIdentifier)).WithHttpClientFactory(HttpClientFactory).Build();
break;

case ManagedIdentityType.UserAssignedByObjectId:
Diagnostics.Log.Debug(Constants.LOGGING_SOURCE, $"Using the user assigned managed identity with object/principal ID: {managedIdentityUserAssignedIdentifier}");
mi = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.WithUserAssignedObjectId(managedIdentityUserAssignedIdentifier)).Build();
mi = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.WithUserAssignedObjectId(managedIdentityUserAssignedIdentifier)).WithHttpClientFactory(HttpClientFactory).Build();
break;


case ManagedIdentityType.UserAssignedByResourceId:
Diagnostics.Log.Debug(Constants.LOGGING_SOURCE, $"Using the user assigned managed identity with Azure Resource ID: {managedIdentityUserAssignedIdentifier}");
mi = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.WithUserAssignedResourceId(managedIdentityUserAssignedIdentifier)).Build();
mi = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.WithUserAssignedResourceId(managedIdentityUserAssignedIdentifier)).WithHttpClientFactory(HttpClientFactory).Build();
break;

case ManagedIdentityType.SystemAssigned:
Diagnostics.Log.Debug(Constants.LOGGING_SOURCE, "Using the system assigned managed identity");
mi = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.SystemAssigned).Build();
mi = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.SystemAssigned).WithHttpClientFactory(HttpClientFactory).Build();
break;
}

Expand Down Expand Up @@ -412,7 +412,8 @@ public AuthenticationManager(string clientId, string username, SecureString pass
if (!string.IsNullOrEmpty(redirectUrl))
{
builder = builder.WithRedirectUri(redirectUrl);
}
}
builder.WithLegacyCacheCompatibility(false);
this.username = username;
this.password = password;
publicClientApplication = builder.Build();
Expand Down Expand Up @@ -471,6 +472,7 @@ public AuthenticationManager(string clientId, string redirectUrl = null, string
{
builder = builder.WithTenantId(tenantId);
}
builder.WithLegacyCacheCompatibility(false);
publicClientApplication = builder.Build();

this.customWebUi = customWebUi;
Expand Down Expand Up @@ -519,7 +521,7 @@ public AuthenticationManager(string clientId, string tenantId, Func<DeviceCodeRe
}

builder = builder.WithHttpClientFactory(HttpClientFactory);

builder.WithLegacyCacheCompatibility(false);
publicClientApplication = builder.Build();

// register tokencache if callback provided
Expand Down Expand Up @@ -555,7 +557,7 @@ public AuthenticationManager(string clientId, X509Certificate2 certificate, stri
{
builder = builder.WithRedirectUri(redirectUrl);
}

builder.WithLegacyCacheCompatibility(false);
confidentialClientApplication = builder.Build();

// register tokencache if callback provided
Expand Down Expand Up @@ -608,7 +610,7 @@ public AuthenticationManager(string clientId, string certificatePath, string cer
{
builder = builder.WithRedirectUri(redirectUrl);
}

builder.WithLegacyCacheCompatibility(false);
confidentialClientApplication = builder.Build();

// register tokencache if callback provided. ApptokenCache as AcquireTokenForClient is beind called to acquire tokens.
Expand Down Expand Up @@ -653,7 +655,7 @@ public AuthenticationManager(string clientId, StoreName storeName, StoreLocation
{
builder = builder.WithTenantId(tenantId);
}

builder.WithLegacyCacheCompatibility(false);
confidentialClientApplication = builder.Build();

// register tokencache if callback provided. ApptokenCache as AcquireTokenForClient is beind called to acquire tokens.
Expand Down Expand Up @@ -694,6 +696,7 @@ public AuthenticationManager(string clientId, string clientSecret, UserAssertion
}
}
this.assertion = userAssertion;
builder.WithLegacyCacheCompatibility(false);
confidentialClientApplication = builder.Build();

// register tokencache if callback provided
Expand Down

0 comments on commit 4f48009

Please sign in to comment.