Skip to content

Add backward compatibility for legacy Teams auth config - #628

Merged
MehakBindra merged 5 commits into
mainfrom
feature/backward-compat-auth-config
Jul 30, 2026
Merged

Add backward compatibility for legacy Teams auth config#628
MehakBindra merged 5 commits into
mainfrom
feature/backward-compat-auth-config

Conversation

@singhk97

@singhk97 singhk97 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

In 2.0, apps commonly configured bot auth with a Teams section (TenantId, ClientId, ClientSecret). In 2.1, the supported model is Microsoft.Identity.Web under AzureAd with ClientCredentials.

This change preserves backward compatibility for the legacy Teams shape while keeping the 2.1 AzureAd path as the canonical runtime model.

What changed

  • Added fallback in BotConfig.Resolve(...) to use legacy Teams only when the primary section has no ClientId.
  • Mapped legacy values into an in-memory AzureAd-shaped configuration section:
    • TenantId
    • ClientId
    • Instance (defaulted to https://login.microsoftonline.com/)
    • ClientCredentials:0:SourceType = ClientSecret
    • ClientCredentials:0:ClientSecret
  • Kept SectionName as the requested section name (default AzureAd) so JWT scheme naming and MSAL named options stay consistent for downstream consumers.
  • Added a warning log when legacy Teams is used, including the target Microsoft.Identity.Web JSON structure for migration.
image

Behavior and compatibility

  • Teams only config works.
  • AzureAd only config works.
  • If both exist, AzureAd takes precedence.
  • Legacy path defaults Instance to the public cloud endpoint, matching prior behavior where Teams had no instance key.

Testing

Unit tests

Added coverage in BotConfigTests for:

  • Resolving client and tenant from legacy Teams
  • Defaulting Instance for legacy config
  • Keeping SectionName as AzureAd
  • Producing MSAL ClientCredentials shape from legacy config
  • Ensuring legacy mapping is not treated as UMI
  • Preferring AzureAd when both sections are present
  • Verifying mapped TenantId/ClientId/Instance in MsalConfigurationSection

End-to-end validation

Validated these scenarios in both appsettings.json and launchSettings.json:

  • Teams
  • AzureAd
  • Teams + AzureAd (with AzureAd precedence)

singhk97 and others added 3 commits July 29, 2026 07:25
When AzureAd:ClientId is absent but Teams:ClientId is present,
BotConfig.Resolve() now maps the legacy shape to the canonical
AzureAd shape via an in-memory IConfiguration. This ensures all
downstream code (MSAL binding, JWT validation, UMI detection) sees
a consistent AzureAd-shaped section regardless of which config
format the user has set.

Mapping applied:
  Teams:TenantId    -> AzureAd:TenantId
  Teams:ClientId    -> AzureAd:ClientId
  Teams:ClientSecret -> AzureAd:ClientCredentials:0:ClientSecret
                        (SourceType = ClientSecret)
  Instance          -> fixed to https://login.microsoftonline.com/

When both sections are present, AzureAd takes precedence.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Fall back to the legacy 'Teams' config section (TenantId, ClientId,
  ClientSecret) when the primary 'AzureAd' section has no ClientId
- Remap the legacy shape to the Microsoft.Identity.Web ClientCredentials
  array structure so all downstream code sees a consistent AzureAd-shaped
  section without any changes
- Default Instance to https://login.microsoftonline.com/ for legacy config
- SectionName, JWT scheme, and MSAL named-options key all remain 'AzureAd'
- Emit a Warning log with the full migration JSON example when the legacy
  section is used
- Add 7 unit tests covering all backward-compat scenarios

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 29, 2026 20:08
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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 adds backward compatibility in Microsoft.Teams.Core so apps still using the legacy Teams auth configuration shape (TenantId/ClientId/ClientSecret) can run on the 2.1+ Microsoft.Identity.Web (AzureAd) model by mapping legacy values into an AzureAd-shaped configuration section at runtime.

Changes:

  • Added fallback logic in BotConfig.Resolve(...) to map legacy Teams configuration into an AzureAd-shaped in-memory configuration section when the primary section lacks ClientId.
  • Added unit tests covering legacy resolution behavior and AzureAd precedence when both sections are present.
  • Updated Microsoft.Teams.Apps.csproj to suppress additional warnings (including a NuGet vulnerability warning).

Reviewed changes

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

File Description
core/src/Microsoft.Teams.Core/Hosting/BotConfig.cs Adds legacy Teams fallback and logging to keep runtime config shape consistent for downstream Microsoft.Identity.Web/MSAL binding.
core/test/Microsoft.Teams.Core.UnitTests/Hosting/BotConfigTests.cs Adds unit coverage for legacy Teams fallback behavior and precedence rules.
core/src/Microsoft.Teams.Apps/Microsoft.Teams.Apps.csproj Updates project warning suppressions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/src/Microsoft.Teams.Core/Hosting/BotConfig.cs
Comment thread core/src/Microsoft.Teams.Apps/Microsoft.Teams.Apps.csproj Outdated
Comment thread core/test/Microsoft.Teams.Core.UnitTests/Hosting/BotConfigTests.cs
Comment thread core/src/Microsoft.Teams.Core/Hosting/BotConfig.cs
- Map Teams:DangerouslyAllowUnauthenticatedRequests during legacy Teams->AzureAd fallback
- Add unit coverage for legacy auth bypass behavior
- Remove NU1903 from Microsoft.Teams.Apps NoWarn

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- remove ExperimentalTeamsQuotedReplies
- keep only ExperimentalTeamsTargeted in NoWarn

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@MehakBindra
MehakBindra added this pull request to the merge queue Jul 30, 2026
Merged via the queue into main with commit 2d5fff3 Jul 30, 2026
8 checks passed
@MehakBindra
MehakBindra deleted the feature/backward-compat-auth-config branch July 30, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants