Skip to content

Conversation

@sw-joelmut
Copy link
Collaborator

Fixes #584

Description

This PR adds functionality to detect duplicated MS Teams token exchange activities, allowing one to continue, and the rest to ignore them.
We also applied some useful changes to the storages by returning the ETag after writing the item.

Testing

The following image shows the functionality working and showing the duplicated messages in console.
image

Copilot AI review requested due to automatic review settings September 24, 2025 16:40
Copy link
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

This PR adds functionality to detect duplicated MS Teams token exchange activities, allowing one to continue while the rest are ignored. The implementation uses storage-based deduplication with a new ifNotExists write option and updates all storage implementations to return ETags after write operations.

  • Implements token exchange deduplication using storage-based tracking with ifNotExists write option
  • Updates all storage implementations (Memory, File, CosmosDB, Blob) to return ETags and support conditional writes
  • Removes old token exchange deduplication logic from OAuthFlow and moves it to Authorization class

Reviewed Changes

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

Show a summary per file
File Description
packages/agents-hosting/src/storage/storage.ts Updates Storage interface to add StorageWriteOptions and return StoreItems from write operations
packages/agents-hosting/src/storage/memoryStorage.ts Implements conditional write support and ETag return functionality
packages/agents-hosting/src/storage/fileStorage.ts Adds conditional write support and updates return type
packages/agents-hosting/src/app/authorization.ts Implements token exchange deduplication logic using storage-based tracking
packages/agents-hosting/src/oauth/oAuthFlow.ts Removes old deduplication logic and improves error handling
packages/agents-hosting/src/app/agentApplication.ts Updates flow handling to properly handle undefined token responses from deduplication
packages/agents-hosting-storage-cosmos/src/cosmosDbPartitionedStorage.ts Implements conditional write operations and ETag return for CosmosDB
packages/agents-hosting-storage-blob/src/blobsStorage.ts Adds conditional write support and ETag handling for Blob storage
packages/agents-hosting/test/hosting/app/authorization.test.ts Adds test coverage for duplicate token exchange handling
packages/agents-hosting/test/hosting/oauthflow.test.ts Removes obsolete test for old deduplication logic
packages/agents-hosting/src/app/turnState.ts Updates promise type annotation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

tracyboehrer
tracyboehrer previously approved these changes Oct 3, 2025
@tracyboehrer
Copy link
Member

@sw-joelmut Did you test this with Teams ConsentRequired? i.e., Have to click the "Consent" button on the Teams client side?

@sw-joelmut
Copy link
Collaborator Author

@sw-joelmut Did you test this with Teams ConsentRequired? i.e., Have to click the "Consent" button on the Teams client side?

I think i didnt, how could i test that case?

@sw-joelmut sw-joelmut force-pushed the southworks/add/token-exchange-duplication branch from a32acbd to 4ec4fd5 Compare October 22, 2025 13:19
@sw-joelmut
Copy link
Collaborator Author

Hi @tracyboehrer, I pushed more changes to this PR, this functionality keeps working on Blobs, Cosmos, File, and Memory storages. Also, i took into account the issue we fixed yesterday when MS Teams token exchange fails multiple times and defaults to using the magic code.
image

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.

MS Teams deduplication on multiple clients

3 participants