Skip to content

Fixing OBO user error - #3712

Merged
Travis Walker (trwalke) merged 1 commit into
masterfrom
trwalke/UpdateOboEvent
Feb 5, 2026
Merged

Travis Walker (trwalke) merged 1 commit into
masterfrom
trwalke/UpdateOboEvent

Conversation

@trwalke

@trwalke Travis Walker (trwalke) commented Feb 5, 2026 •

Copy link
Copy Markdown
Member

This pull request introduces improvements to the handling and testing of the OnBeforeTokenAcquisitionForOnBehalfOf event in token acquisition scenarios, specifically ensuring that the correct ClaimsPrincipal is passed and its context is preserved. The most important changes are grouped below by theme.

Token Acquisition Logic Improvement:

  • Updated the NotifyCertificateSelection method in TokenAcquisition.cs to use userHint instead of user when invoking the OnBeforeTokenAcquisitionForOnBehalfOfAsync event, ensuring the correct principal is used during token acquisition.

Unit Test Enhancements:

  • In AuthorizationHeaderProviderTests.cs, enhanced the LongRunningSessionForDefaultAuthProviderForUserDefaultKeyTest by configuring the TokenAcquisitionExtensionOptions to subscribe to the OnBeforeTokenAcquisitionForOnBehalfOf event. The test now verifies that the ClaimsPrincipal passed to the event matches the one used in the authorization header provider and that the BootstrapContext is preserved.
  • Refactored the test setup by moving the creation of the test ClaimsPrincipal and its identity earlier in the test and removing duplicate code.

Dependency Update:

  • Added NSubstitute.Extensions to the test file imports, likely to support more advanced mocking scenarios in unit tests.Fixing OBO user error

@trwalke
Travis Walker (trwalke) requested a review from a team as a code owner February 5, 2026 22:57
@trwalke
Travis Walker (trwalke) merged commit c24b5ae into master Feb 5, 2026
4 checks passed
@trwalke
Travis Walker (trwalke) deleted the trwalke/UpdateOboEvent branch February 5, 2026 23:17
Ray Luo (rayluo) added a commit that referenced this pull request Feb 9, 2026
…ipal from token

In PR #3712 changed the usage of user to userHint, but based on the logic at the beginning of the changed method, the single source of truth in terms of OBO shall be derived from tokenUsedToCallTheWebApi. This change constructs a ClaimsPrincipal from the token string and preserves the BootstrapContext for use in event handlers.
Travis Walker (trwalke) added a commit that referenced this pull request Feb 11, 2026
…sPricipal from token (#3714)

* Update OnBeforeTokenAcquisitionForOnBehalfOf event to use ClaimsPrincipal from token

In PR #3712 changed the usage of user to userHint, but based on the logic at the beginning of the changed method, the single source of truth in terms of OBO shall be derived from tokenUsedToCallTheWebApi. This change constructs a ClaimsPrincipal from the token string and preserves the BootstrapContext for use in event handlers.

* Adding DTO for OBO event

* Updated comments

* Updating PR

---------

Co-authored-by: trwalke <trwalke@microsoft.com>
Co-authored-by: Travis Walker <travis.walker@microsoft.com>
This was referenced Mar 1, 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.

3 participants