Add Graph client factory helpers to Teams turn context and app-only overloads - #928
Merged
tracyboehrer merged 3 commits intoJul 16, 2026
Merged
Conversation
…verloads Introduce a shared GraphClientFactory used by both TeamsAgentExtension and TeamsTurnContext to build GraphServiceClient instances, eliminating duplicated token-provider and scope-derivation logic. - Add app-only (application token) GraphServiceClient overloads: - GetAppGraphClient (connection resolved from the current turn) - GetAppGraphClientForConnection (named token connection) - Expose GetGraphClient / GetAppGraphClient / GetAppGraphClientForConnection on ITeamsTurnContext / TeamsTurnContext, resolving UserAuthorization and IConnections from ITurnContext.Services. - Register IConnections in turn services (AgentApplication.SetTurnContextServices) so the turn-context helpers can resolve it. - Name the named-connection variant GetAppGraphClientForConnection to avoid a single-string overload collision with GetAppGraphClient(graphBaseUrl). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b49f943e-28fb-4905-b258-0b51ef3aa557
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Microsoft Graph GraphServiceClient factory helpers to the MSTeams extension so agents can easily obtain delegated (user) and app-only Graph clients from either TeamsAgentExtension or ITeamsTurnContext, with shared scope/resource derivation via a central factory.
Changes:
- Introduces
GraphClientFactoryto centralize Graph client creation for delegated and app-only authentication. - Exposes Graph client helpers on
TeamsTurnContext/ITeamsTurnContextand adds app-only overloads (including named-connection). - Registers
IConnectionsinto per-turn services inAgentApplication.SetTurnContextServicesso turn-context helpers can resolve it.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/Extensions/Microsoft.Agents.Extensions.MSTeams/TeamsTurnContext.cs | Adds Graph client helper methods that resolve UserAuthorization / IConnections from turn services. |
| src/libraries/Extensions/Microsoft.Agents.Extensions.MSTeams/TeamsAgentExtension.cs | Refactors delegated Graph client creation to factory; adds app-only Graph client helpers (turn-resolved + named-connection). |
| src/libraries/Extensions/Microsoft.Agents.Extensions.MSTeams/ITeamsTurnContext.cs | Adds Graph client helper methods to the public Teams turn-context interface. |
| src/libraries/Extensions/Microsoft.Agents.Extensions.MSTeams/GraphClientFactory.cs | New shared factory for delegated + app-only Graph client construction and scope derivation. |
| src/libraries/Builder/Microsoft.Agents.Builder/App/AgentApplication.cs | Registers IConnections into turnContext.Services when configured, enabling turn-context resolution. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
tracyboehrer
enabled auto-merge
July 16, 2026 20:52
rodrigobr-msft
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Microsoft Graph client factory helpers so agents can obtain a
GraphServiceClientfor both delegated (user) and app-only (application) tokens without manually wiring up token providers or scopes.Changes
GraphClientFactory— shared byTeamsAgentExtensionandTeamsTurnContext, centralizing the token-provider and.defaultscope-derivation logic (no duplication). Scope/resource is derived from the Graph base URL so national clouds (e.g.graph.microsoft.us) are honored.GetAppGraphClient(...)— connection resolved from the current turn (ITurnContext.Identity+Activity) viaIConnections.GetTokenProvider.GetAppGraphClientForConnection(connectionName, ...)— named token connection. No extraappsettingsrequired beyond the existing token connection.GetGraphClient/GetAppGraphClient/GetAppGraphClientForConnectionare now exposed onITeamsTurnContext/TeamsTurnContext, resolvingUserAuthorizationandIConnectionsfromITurnContext.Services(clearInvalidOperationExceptionif unconfigured).AgentApplication.SetTurnContextServicesnow registersIConnectionsin turn services so the turn-context helpers can resolve it.Notes
GetAppGraphClientForConnection(not an overload ofGetAppGraphClient) to avoid a silent single-stringoverload collision withGetAppGraphClient(graphBaseUrl).client.Users["{userId}"]...).Testing
dotnet build src\libraries\Extensions\Microsoft.Agents.Extensions.MSTeams\Microsoft.Agents.Extensions.MSTeams.csproj→ 0 warnings / 0 errors.