- 
                Notifications
    
You must be signed in to change notification settings  - Fork 24
 
Add MS Teams token exchange duplication check #606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 
ifNotExistswrite 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.
        
          
                packages/agents-hosting-storage-cosmos/src/cosmosDbPartitionedStorage.ts
          
            Show resolved
            Hide resolved
        
      | 
           @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?  | 
    
…exchange-duplication
…exchange-duplication
a32acbd    to
    4ec4fd5      
    Compare
  
    | 
           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.  | 
    

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.
