Skip to content

Add OAuthFlow with back compat to context.SignIn flows#437

Open
rido-min wants to merge 23 commits intonext/corefrom
next/core-apiclients-sso
Open

Add OAuthFlow with back compat to context.SignIn flows#437
rido-min wants to merge 23 commits intonext/corefrom
next/core-apiclients-sso

Conversation

@rido-min
Copy link
Copy Markdown
Member

@rido-min rido-min commented Apr 21, 2026

This pull request adds two new sample bots demonstrating OAuth authentication flows (multi-connection OAuth and Teams SSO) and makes minor improvements to the API client code for clarity and type-safety. The new samples provide practical guidance for implementing authentication scenarios with Microsoft Teams bots.

New OAuth sample bots:

  • Added OAuthFlowBot sample, which demonstrates handling multiple OAuth connections (Microsoft Graph and GitHub), including sign-in, sign-out, and status commands. Includes new files: OAuthFlowBot.csproj, Program.cs, and appsettings.json. [1] [2] [3]
  • Added SsoBot sample, which demonstrates Teams SSO using a single OAuth connection with simplified context-based authentication. Includes new files: SsoBot.csproj, Program.cs, and appsettings.json. [1] [2] [3]
  • Registered both new samples in the solution file (core.slnx).

API client improvements:

  • Updated BotSignInClient.GetResourceAsync to return a non-nullable result, aligning with the underlying core client and improving type-safety.
  • Added remarks and clarified async/await usage in UserTokenApiClient methods to document bridging of type and nullability differences between the API surface and the core client. [1] [2] [3]

rido-min added 12 commits April 16, 2026 16:47
- Register signin/failure route and handler in OAuthFlow
- Add SignInFailureValue for structured failure details
- Update SignInFailureHandler to accept failure info
- Log detailed warnings for client-side SSO failures
- Fire OnSignInFailure on all flows for signin/failure invokes
- Return HTTP 200 for signin/failure, 412 for expected token errors
- Add TokenExchangeInvokeResponse for diagnostics on 412
- Remove automatic user/bot token fetch; now explicit
- Clarify and implement token exchange deduplication
- Update docs, edge cases, and summary tables accordingly
@rido-min rido-min added the CORE label Apr 21, 2026
Refactored OAuth and token client classes for better thread safety and nullability.
- BotSignInClient: GetResourceAsync now returns a non-nullable result.
- UserTokenApiClient: Added async/await wrappers to align nullability and types, with explanatory remarks.
- OAuthFlow: Added SemaphoreSlim for serialized connection name discovery, suppressed disposal warning, and improved thread safety with volatile flag and double-checked locking.
- Context<TActivity>: Marked IsSignedIn as obsolete and documented thread-pool starvation risk, recommending async usage.
@rido-min rido-min marked this pull request as ready for review April 22, 2026 00:08
rido-min and others added 5 commits April 21, 2026 20:39
- Created `sso-trace-2026-04-22-sequence-diagrams.md` to document the login, profile, and logout flows using sequence diagrams.
- Added `sso-trace-2026-04-22-summary.md` to provide a detailed trace summary of the SsoBot interactions, including identity references, request summaries, and MSAL token acquisitions.
Resolves conflicts by keeping Compat decoupled from TeamsBotApplication/Apps
(per PR #391). Removes duplicate CompatChannelAccount.cs (methods now in
CompatActivity.cs). Updates CompatAdapterTests to use BotApplication.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Base automatically changed from next/core-restartApiClients to next/core April 22, 2026 21:10
Resolved conflicts in 5 files:
- BotSignInClient.cs: accept nullable return type from next/core
- UserTokenApiClient.cs: remove extra remarks docs removed in next/core
- Context.cs: keep both Auth and Api.Clients usings needed by PR
- TeamsBotApplication.cs: keep Auth using needed by OAuthFlowRegistry
- CompatTeamsInfoTests.cs: accept ConversationList return type from next/core

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
{
Name = string.Join("/", [TeamsActivityType.Message, regex.ToString()]),
Selector = msg => regex.IsMatch(msg.Text ?? ""),
Selector = msg => regex.IsMatch(msg.TextWithoutMentions ?? ""),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MehakBindra I added this TestWithoutMentions to remove the mention when testing SSO in channels/groups

We could also do it in a middleware... thoughts?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think it is a useful property that could be required elsewhere too , I say we keep it

- Include user's name in status message response.
- Fix recipient type in OAuthFlow and clarify foreach typing.
- Remove unused using directives in several files.
- Delete CompatTeamsSSOTokenExchangeMiddleware and related logic.
Introduce TeamsBotApplicationOptions for DI configuration of OAuth flows, enabling registration of connection name, card text, and button text at startup. Overload AddTeamsBotApplication to accept configuration delegates. Update TeamsBotApplication to auto-register flows from DI options and provide GetOAuthFlow for callback attachment. Enhance OAuthFlow to support default OAuthOptions per flow. Update docs and samples to demonstrate the new pattern. Improve status messages, JSON formatting, and add validation.
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.

2 participants