Skip to content

.NET/Python: Purview: prefer token principal for user identity - #6693

Merged
eoindoherty1 merged 2 commits into
microsoft:mainfrom
taisirhassan:purview-token-identity-fixes
Jun 24, 2026
Merged

.NET/Python: Purview: prefer token principal for user identity#6693
eoindoherty1 merged 2 commits into
microsoft:mainfrom
taisirhassan:purview-token-identity-fixes

Conversation

@taisirhassan

Copy link
Copy Markdown
Contributor

Motivation & Context

Purview middleware needs consistent identity resolution across .NET and Python. User-token credentials should evaluate policy for the authenticated token principal, while app-token flows should continue to support supplied end-user IDs for policy scoping.

This also aligns the content activities route with the other Purview Graph user routes.

Description & Review Guide

  • What are the major changes?

    • Resolve Purview user identity by inspecting token info first in both .NET and Python middleware.
    • Use supplied/message fallback user IDs only when the token has no user principal.
    • Require .NET message userId fallback values to parse as GUIDs, matching Python validation.
    • Fix .NET content activities URL to use /users/{userId}/....
    • Add/update regression tests for token precedence, invalid fallback IDs, scope location matching, and content activity route construction.
  • What is the impact of these changes?

    • User-token flows consistently bind policy evaluation to the authenticated user.
    • App-token flows remain supported through validated supplied/message user IDs.
    • Content activity audit requests use the documented user route.
  • What do you want reviewers to focus on?

    • Identity precedence in ScopedContentProcessor / _processor.py.
    • App-token fallback behavior remains supported.
    • Route assertion in PurviewClientTests.

Related Issue

No public issue. Security hardening and parity fix for Purview middleware.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings June 23, 2026 21:56
@moonbox3 moonbox3 added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python .NET Usage: [Issues, PRs], Target: .Net labels Jun 23, 2026
@github-actions github-actions Bot changed the title Purview: prefer token principal for user identity .NET: Purview: prefer token principal for user identity Jun 23, 2026
@github-actions github-actions Bot changed the title Purview: prefer token principal for user identity Python: Purview: prefer token principal for user identity Jun 23, 2026
@taisirhassan taisirhassan changed the title Python: Purview: prefer token principal for user identity .NET/Python: Purview: prefer token principal for user identity Jun 23, 2026
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/purview/agent_framework_purview
   _processor.py1821293%175, 255–258, 285, 313–314, 325, 327, 333, 335
TOTAL42148498188% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
8302 37 💤 0 ❌ 0 🔥 2m 8s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Purview middleware identity resolution to prefer the authenticated token’s user principal (when present), with validated fallbacks for app-token scenarios, and aligns the .NET content activities route with the documented /users/{userId}/... Graph endpoint.

Changes:

  • Python: always inspect token info up front and use token user_id before considering provided/message fallbacks; update docs and tests accordingly.
  • .NET: validate message-supplied userId fallbacks as GUIDs, prefer token UserId over message metadata, and add regression tests for precedence + scope-location matching.
  • .NET: fix SendContentActivitiesAsync to call /users/{userId}/dataSecurityAndGovernance/activities/contentActivities and update the unit test.

Reviewed changes

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

Show a summary per file
File Description
python/packages/purview/tests/purview/test_processor.py Updates tests to account for unconditional token inspection and token-user precedence.
python/packages/purview/README.md Updates guidance to clarify user-token vs app-token user identity behavior.
python/packages/purview/agent_framework_purview/_processor.py Changes identity resolution order to prefer token principal, then validated fallbacks.
dotnet/tests/Microsoft.Agents.AI.Purview.UnitTests/ScopedContentProcessorTests.cs Adds/updates tests for token precedence, GUID validation, and location matching.
dotnet/tests/Microsoft.Agents.AI.Purview.UnitTests/PurviewClientTests.cs Updates expected content activities URL to the /users/{userId}/... route.
dotnet/src/Microsoft.Agents.AI.Purview/ScopedContentProcessor.cs Implements token-first user identity resolution and GUID validation for message fallbacks.
dotnet/src/Microsoft.Agents.AI.Purview/README.md Updates docs describing token-principal precedence and app-token expectations.
dotnet/src/Microsoft.Agents.AI.Purview/PurviewClient.cs Fixes content activities endpoint construction to use /users/{userId}/....

Comment thread dotnet/src/Microsoft.Agents.AI.Purview/ScopedContentProcessor.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Purview/ScopedContentProcessor.cs Outdated
Align Purview middleware identity resolution so user-token principals are preferred before supplied message identities, while app-token flows continue to use validated fallback user IDs. Also fix the content activities user route and add regression coverage for identity precedence and route construction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread dotnet/src/Microsoft.Agents.AI.Purview/ScopedContentProcessor.cs Outdated
@eoindoherty1
eoindoherty1 added this pull request to the merge queue Jun 24, 2026
Merged via the queue into microsoft:main with commit d5c15f2 Jun 24, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants