Skip to content

Add IConfidentialClientApplicationProvider and CachePartitionKey support#3822

Merged
iNinja merged 6 commits into
masterfrom
iinglese/cca-provider-cache-partition
May 21, 2026
Merged

Add IConfidentialClientApplicationProvider and CachePartitionKey support#3822
iNinja merged 6 commits into
masterfrom
iinglese/cca-provider-cache-partition

Conversation

@iNinja
Copy link
Copy Markdown
Contributor

@iNinja iNinja commented May 20, 2026

Summary

Two additions to Microsoft.Identity.Web.TokenAcquisition:

IConfidentialClientApplicationProvider

New public interface that exposes the managed IConfidentialClientApplication for a given authentication scheme. Enables extensions to call MSAL directly (e.g. for custom token acquisition flows) while reusing the same CCA instance, credentials, and token cache that IdWeb manages.

TokenAcquisition implements the interface. Registered in DI alongside ITokenAcquisition with the same lifetime (scoped or singleton depending on configuration).

TokenAcquisitionOptions.CachePartitionKey

New optional IDictionary<string, string> property. When set, TokenAcquisition threads it to MSAL's AcquireTokenSilent via WithCachePartitionKey() (MSAL 4.84.1). Enables partition-aware silent token lookup for scenarios where cached tokens need isolation (e.g. parallel sessions for the same user with different lifetimes).

The property is cloned in TokenAcquisitionOptions.Clone() to prevent shared state.

Dependencies

  • MSAL 4.84.1 (WithCachePartitionKey API, merged and released)
  • Directory.Build.props bumps MicrosoftIdentityClientVersion from 4.84.0 to 4.84.1

Changes

File Change
IConfidentialClientApplicationProvider.cs New public interface
TokenAcquisition.cs Implements interface + threads CachePartitionKey to MSAL
TokenAcquisitionOptions.cs CachePartitionKey property + Clone support
ServiceCollectionExtensions.cs DI registration for the new interface
PublicAPI/NetCore/PublicAPI.Unshipped.txt API declarations
PublicAPI/NetFramework/PublicAPI.Unshipped.txt API declarations
Directory.Build.props MSAL version bump

Testing

  • 4 unit tests: DI registration, resolution to TokenAcquisition, CachePartitionKey defaults and setter
  • All existing tests pass

iNinja and others added 2 commits May 20, 2026 10:40
IConfidentialClientApplicationProvider: new public interface that exposes
the managed CCA instance for a given authentication scheme. Enables
extensions to call MSAL directly with custom parameters (e.g. cache
partition keys) while reusing IdWeb's CCA lifecycle and configuration.

TokenAcquisitionOptions.CachePartitionKey: new optional field that threads
through to MSAL's WithCachePartitionKey on AcquireTokenSilent calls.
Enables partition-aware silent token lookup for downstream API calls.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update MicrosoftIdentityClientVersion to 4.84.1 which includes
WithReservedScopes and WithCachePartitionKey APIs.

Add PublicAPI.Unshipped.txt entries for IConfidentialClientApplicationProvider
and TokenAcquisitionOptions.CachePartitionKey to NetCore and NetFramework
folders (matching the existing project convention).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@iNinja iNinja requested a review from a team as a code owner May 20, 2026 09:55
Add the new interface to Assert.Collection in the correct sorted
position (after IMsalHttpClientFactory) instead of filtering it out.
Update service count to 14.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds extensibility and cache-partitioning capabilities to Microsoft.Identity.Web.TokenAcquisition by exposing the managed MSAL confidential client and allowing callers to provide MSAL cache partition key components for silent token acquisition.

Changes:

  • Introduces IConfidentialClientApplicationProvider and registers it in DI, implemented by TokenAcquisition.
  • Adds TokenAcquisitionOptions.CachePartitionKey and threads it into MSAL AcquireTokenSilent via WithCachePartitionKey.
  • Updates public API baselines and bumps MSAL dependency to 4.84.1; adds unit tests for DI registration and options defaults.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Microsoft.Identity.Web.Test/TokenAcquisitionTests.cs Adds unit tests for CachePartitionKey default/setter behavior.
tests/Microsoft.Identity.Web.Test/ServiceCollectionExtensionsTests.cs Extends DI registration tests to cover the new provider and updated service counts.
src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisitionOptions.cs Adds CachePartitionKey option and clones it in Clone().
src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs Implements the new provider interface and applies cache partition keys to silent acquisition builder.
src/Microsoft.Identity.Web.TokenAcquisition/ServiceCollectionExtensions.cs Registers IConfidentialClientApplicationProvider in DI (scoped/singleton).
src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/NetFramework/PublicAPI.Unshipped.txt Declares new public API surface for NetFramework builds.
src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/NetCore/PublicAPI.Unshipped.txt Declares new public API surface for NetCore builds.
src/Microsoft.Identity.Web.TokenAcquisition/IConfidentialClientApplicationProvider.cs Adds the new public interface exposing the managed MSAL CCA.
Directory.Build.props Bumps MSAL version from 4.84.0 to 4.84.1.
Comments suppressed due to low confidence (1)

src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisitionOptions.cs:60

  • CachePartitionKey is cloned in TokenAcquisitionOptions.Clone(), but there isn't a unit test asserting the clone is a deep copy (i.e., cloned.CachePartitionKey is not the same instance and is unaffected by subsequent mutations to the original). Adding a test would help prevent regressions since avoiding shared mutable state is part of the new behavior.
                CachePartitionKey = CachePartitionKey != null
                    ? new Dictionary<string, string>(CachePartitionKey)
                    : null

Comment thread src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs Outdated
iNinja and others added 2 commits May 20, 2026 11:33
- Include IConfidentialClientApplicationProvider in the existing-registration
  check and lifetime-mismatch removal in ServiceCollectionExtensions, matching
  the pattern used for ITokenAcquisitionInternal and ICredentialsProvider.

- Preserve dictionary comparer in TokenAcquisitionOptions.Clone() when
  CachePartitionKey is a Dictionary<string, string> with a custom comparer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs Outdated
Comment thread src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisitionOptions.cs Outdated
Comment thread src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisitionOptions.cs Outdated
Comment thread src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisitionOptions.cs Outdated
Comment thread src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisitionOptions.cs Outdated
@bgavrilMS
Copy link
Copy Markdown
Member

Approved with comments

- Move IConfidentialClientApplicationProvider to Microsoft.Identity.Web.Extensibility namespace
- Make CachePartitionKeys internal, expose via extension method in Extensibility namespace
- Rename CachePartitionKey to CachePartitionKeys
- Simplify Clone (drop comparer preservation)
- Remove unnecessary #pragma if applicable

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions Bot pushed a commit to EelcoLos/nx-tinkering that referenced this pull request May 26, 2026
Updated
[Microsoft.Identity.Web](https://github.com/AzureAD/microsoft-identity-web)
from 4.9.0 to 4.10.0.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.Identity.Web's
releases](https://github.com/AzureAD/microsoft-identity-web/releases)._

## 4.10.0

### New features
- Add `WithExtraBodyParameters` fluent API for attaching extra body
parameters to token acquisition requests. See
[#​3819](AzureAD/microsoft-identity-web#3819).
- Add `IConfidentialClientApplicationProvider` extensibility interface
and `CachePartitionKey` support for silent token acquisition. See
[#​3822](AzureAD/microsoft-identity-web#3822).

### Bug fixes
- Redirect URI sanitization in authorization scenarios; centralize
redirect URI validation in a shared helper. See
[#​3825](AzureAD/microsoft-identity-web#3825).
- Reject dSTS-shaped `Authority` values with a clearer exception,
steering users to use `Instance` + `TenantId` instead. See
[#​3805](AzureAD/microsoft-identity-web#3805).
- Improve regex handling and adding length/timeout safeguards for
SameSite User Agent. See
[#​3811](AzureAD/microsoft-identity-web#3811).

### Behavior changes
- **B2C OpenID Connect event handler: LRU cache for issuer address.**
Issuer address lookups in the B2C OIDC event handler are now cached with
an LRU cache, improving performance for repeated lookups. See
[#​3821](AzureAD/microsoft-identity-web#3821).

### Dependencies updates
- Update MSAL.NET to 4.84.1. See
[#​3822](AzureAD/microsoft-identity-web#3822).
- Pin `Microsoft.Kiota.Abstractions` to 1.22.0 for GraphServiceClient.
See
[#​3817](AzureAD/microsoft-identity-web#3817).
- Bump `uuid` and `@​azure/msal-node` in SidecarAdapter TypeScript test
app. See
[#​3826](AzureAD/microsoft-identity-web#3826).
- Bump `qs` in SidecarAdapter TypeScript test app. See
[#​3829](AzureAD/microsoft-identity-web#3829).

Commits viewable in [compare
view](AzureAD/microsoft-identity-web@4.9.0...4.10.0).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Microsoft.Identity.Web&package-manager=nuget&previous-version=4.9.0&new-version=4.10.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Eelco Los <5102501+EelcoLos@users.noreply.github.com>
This was referenced May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants