Add conditions to choose ConnectorClient scope#962
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where TeamsInfo.getMember returns 401 errors when called from incoming webhooks. The issue occurred because the connector client scope was incorrectly derived from the incoming JWT's azp/appid claims instead of using the standard Bot Framework API scope.
Changes:
- Added logic to conditionally select the connector client authentication scope based on the recipient role
- Scope now defaults to
https://api.botframework.comfor non-Skill scenarios - Scope uses
azp/appidonly when communicating back to another agent (Skill role)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/agents-hosting/src/cloudAdapter.ts | Extracted scope resolution logic into a new resolveConnectorScope method that checks recipient role before using azp/appid claims |
| packages/agents-hosting/test/hosting/adapter/cloudAdapter.test.ts | Added three test cases to verify scope resolution for Skill and non-Skill scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // ABS tokens will not have an azp/appid so use the botframework scope. | ||
| // Otherwise use the appId. This will happen when communicating back to another agent. | ||
| if (activity.recipient?.role === RoleTypes.Skill) { |
There was a problem hiding this comment.
Consider using case-insensitive comparison for consistency with other role checks in the same method (lines 143 and 151) which use .toLowerCase() for AgenticIdentity and AgenticUser. Since activity.recipient.role can be a string (as defined in ChannelAccount interface), and the Activity.isAgenticRequest() method uses case-insensitive comparison, using strict equality here could cause the condition to fail if the role string has different casing.
Consider changing to: if (activity.recipient?.role?.toLowerCase() === RoleTypes.Skill.toLowerCase())
| if (activity.recipient?.role === RoleTypes.Skill) { | |
| if (activity.recipient?.role?.toLowerCase() === RoleTypes.Skill.toLowerCase()) { |
Fixes #934
Description
This PR adds a condition to only use the
azpandappidJWT identity values when theActivity.recipient.roleisSkill, otherwise will resolveapi.botframework.comas scope.Testing
The following images show the Agent to Agent operations using MSTeams and WebChat

