Skip to content

Added support for WithArributeTokens #5888

Merged
4gust merged 28 commits intomainfrom
4gust/with-attr-token
Apr 30, 2026
Merged

Added support for WithArributeTokens #5888
4gust merged 28 commits intomainfrom
4gust/with-attr-token

Conversation

@4gust
Copy link
Copy Markdown
Contributor

@4gust 4gust commented Mar 26, 2026

Added support for WithAttributeTokens for CCA acquisition methods

This pull request adds support for specifying attribute tokens in token acquisition requests across multiple authentication flows in the Microsoft Identity Client library. It introduces new WithAttributeTokens methods to the parameter builders for authorization code, client credentials, and on-behalf-of flows, allowing developers to include custom attribute tokens in requests via the attribute_tokens parameter.

The most important changes include:

New API Surface:

  • Added WithAttributeTokens(IEnumerable<string> attributeTokens) methods to AcquireTokenByAuthorizationCodeParameterBuilder, AcquireTokenForClientParameterBuilder, and AcquireTokenOnBehalfOfParameterBuilder, enabling the inclusion of attribute tokens in token requests. These methods validate input, join the tokens, and add them to the request body. [1] [2] [3]

  • Updated the public API files for all supported frameworks to register the new WithAttributeTokens methods, ensuring they are part of the public API surface.

OAuth2 Parameter Support:

  • Added a new constant AttributeTokens to the OAuth2Parameter class for use as the key in the request body parameter.

Fixes #

Testing
Unit test added.

@4gust 4gust requested a review from a team as a code owner March 26, 2026 15:18
Copilot AI review requested due to automatic review settings March 26, 2026 15:18
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 support for sending attribute_tokens on confidential-client token requests (auth code, client credentials, and OBO) via new WithAttributeTokens(...) builder APIs, updates the public API baselines, and introduces unit tests validating request-body behavior and (for client credentials) cache partitioning.

Changes:

  • Added WithAttributeTokens(IEnumerable<string>) to auth code, client credentials, and OBO parameter builders.
  • Introduced OAuth2Parameter.AttributeTokens constant ("attribute_tokens").
  • Updated PublicAPI Unshipped baselines across TFMs and added new unit tests.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/Microsoft.Identity.Test.Unit/PublicApiTests/WithAttributeTokensTests.cs Adds unit coverage for WithAttributeTokens formatting, null validation, and client-credentials caching behavior.
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenByAuthorizationCodeParameterBuilder.cs Adds auth-code builder API to attach attribute_tokens to the token request body.
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs Adds client-credentials builder API to attach attribute_tokens (via extra body params).
src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenOnBehalfOfParameterBuilder.cs Adds OBO builder API to attach attribute_tokens to the token request body.
src/client/Microsoft.Identity.Client/OAuth2/OAuthConstants.cs Adds OAuth2Parameter.AttributeTokens constant.
src/client/Microsoft.Identity.Client/PublicApi/*/PublicAPI.Unshipped.txt Registers new public API methods for all supported TFMs.

…ehalfOfParameterBuilder.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 26, 2026 15:38
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 26, 2026 15:46
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

Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.

Comment thread tests/Microsoft.Identity.Test.Unit/PublicApiTests/WithAttributeTokensTests.cs Outdated
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

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Copy link
Copy Markdown
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

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

Too much code duplication. No token caching.

Copilot AI review requested due to automatic review settings April 8, 2026 06:57
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

Copilot reviewed 13 out of 13 changed files in this pull request and generated 10 comments.

Comment thread src/client/Microsoft.Identity.Client/PublicApi/net8.0/PublicAPI.Unshipped.txt Outdated
Comment thread src/client/Microsoft.Identity.Client/PublicApi/net8.0-ios/PublicAPI.Unshipped.txt Outdated
Comment thread src/client/Microsoft.Identity.Client/PublicApi/net472/PublicAPI.Unshipped.txt Outdated
Comment thread src/client/Microsoft.Identity.Client/PublicApi/net462/PublicAPI.Unshipped.txt Outdated
@Robbie-Microsoft
Copy link
Copy Markdown
Contributor

OBO cache-partition limitation is undocumented in the API

The test WithAttributeTokens_OnBehalfOf_SentInRequestBody_Async includes a comment acknowledging that for OBO flows, different attribute-token sets may not coexist side-by-side in the same user token cache partition — meaning a call with tokens {X,Y} can silently evict the cached entry for {A,B}.

This is a significant behavioral footgun that isn't mentioned anywhere in the public XML docs for WithAttributeTokens. Callers expecting per-set cache isolation in OBO flows will be silently broken. The doc should at minimum warn that OBO cache isolation per attribute-token set is not guaranteed and that callers needing strict isolation should use separate ConfidentialClientApplication instances.

@bgavrilMS
Copy link
Copy Markdown
Member

Does this need to be closed @4gust ?

Copilot AI review requested due to automatic review settings April 29, 2026 10:07
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

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings April 29, 2026 16:40
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

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

@4gust
Copy link
Copy Markdown
Contributor Author

4gust commented Apr 29, 2026

@Robbie-Microsoft Good catch, I have updated the method documentation and added a few tests. I skipped one scenario due to a bug.

I’ve opened a tracking issue here: #5963

@4gust
Copy link
Copy Markdown
Contributor Author

4gust commented Apr 30, 2026

@copilot resolve the merge conflicts in this pull request

Copilot AI review requested due to automatic review settings April 30, 2026 08:13
@4gust 4gust review requested due to automatic review settings April 30, 2026 08:13
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 30, 2026

OBO cache-partition limitation is undocumented in the API

The test WithAttributeTokens_OnBehalfOf_SentInRequestBody_Async includes a comment acknowledging that for OBO flows, different attribut...

Added the explicit recommendation to use separate IConfidentialClientApplication instances for strict per-set cache isolation in OBO flows in commit 9e3c714. The <remarks> for OBO now reads: "Callers that require strict per-set cache isolation across different attribute-token sets should use separate IConfidentialClientApplication instances."

@copilot resolve the merge conflicts in this pull request

No merge conflicts exist in the branch — the most recent commit (8aa44f7) is already a merge commit that brought in the latest main. git diff --check and a search for conflict markers both returned clean.

Copilot AI review requested due to automatic review settings April 30, 2026 08:42
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

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

@4gust 4gust merged commit 5052e95 into main Apr 30, 2026
19 checks passed
@4gust 4gust deleted the 4gust/with-attr-token branch April 30, 2026 17:47
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.

7 participants