Skip to content

Commit 37b16e2

Browse files
authored
Add docs for signin/failure handling (#2719)
Add documentation for new feature adding handling for `'signin/failure'` invoke activities, which previously would fail silently. **Note**: I have included a special note for Python that points out the difference between middleware chain behavior & TS/CS: creating the custom handler does NOT replace the default handler. This means both handlers will run, and is a quirk of teams.py. --------- Co-authored-by: Corina Gum <>
1 parent 62ff2b0 commit 37b16e2

File tree

7 files changed

+99
-1
lines changed

7 files changed

+99
-1
lines changed

teams.md/docs/main/teams/user-authentication/sso-setup.md renamed to teams.md/docs/main/teams/user-authentication/sso-setup.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,7 @@ The Teams application manifest needs to be updated to reflect the settings confi
8080
}
8181
```
8282

83+
## Troubleshooting
84+
85+
If you encounter SSO errors, see the [Troubleshooting](troubleshooting-sso) guide for common issues and solutions.
86+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
sidebar_position: 2
3+
title: Troubleshooting
4+
summary: Common SSO errors and how to resolve them
5+
---
6+
7+
import LangLink from '@site/src/components/LangLink';
8+
9+
# SSO Troubleshooting
10+
11+
When SSO fails, Teams sends a `signin/failure` invoke activity to your bot with a `code` and `message` describing the error. The SDK's default handler logs a warning with these details.
12+
13+
## Failure codes
14+
15+
| Code | Silent | Description |
16+
|------|--------|-------------|
17+
| `installappfailed` | No | Failed to install the app in the user's personal scope (group chat SSO flow). |
18+
| `authrequestfailed` | No | The SSO auth request failed after app installation. |
19+
| `installedappnotfound` | Yes | The bot app is not installed for the user or group chat. *(most common)* |
20+
| `invokeerror` | Yes | A generic error occurred during the SSO invoke flow. |
21+
| `resourcematchfailed` | Yes | The token exchange resource URI on the OAuthCard does not match the Application ID URI in the Entra app registration's "Expose an API" section. *(common)* |
22+
| `oauthcardnotvalid` | Yes | The bot's OAuthCard could not be parsed. |
23+
| `tokenmissing` | Yes | AAD token acquisition failed. |
24+
25+
"Silent" failures produce no user-facing feedback in the Teams client — the user sees nothing and sign-in simply doesn't complete. "Non-silent" failures occur during the group chat SSO flow where the user is shown an install/auth card.
26+
27+
:::note
28+
The `userconsentrequired` and `interactionrequired` codes are handled by the Teams client via the OAuth card fallback flow and do not typically reach the bot.
29+
:::
30+
31+
## `resourcematchfailed`
32+
33+
If you see a warning in your app logs like:
34+
35+
> Sign-in failed for user "..." in conversation "...": resourcematchfailed -- Resource match failed
36+
37+
This means Teams attempted the SSO token exchange but failed because the token exchange resource URI does not match your Entra app registration. To fix this:
38+
39+
1. **Verify "Expose an API"** in your Entra app registration: the Application ID URI must be set (typically `api://<Your-Application-Id>`)
40+
2. **Verify the `access_as_user` scope** is defined under "Expose an API"
41+
3. **Verify pre-authorized client applications** include the Teams Desktop (`1fec8e78-bce4-4aaf-ab1b-5451cc387264`) and Teams Web (`5e3ce6c0-2b1f-4285-8d4b-75ee78787346`) client IDs
42+
4. **Verify the Token Exchange URL** in your Azure Bot OAuth connection matches the Application ID URI exactly
43+
5. **Verify the `webApplicationInfo.resource`** in your Teams app manifest matches the Application ID URI
44+
45+
:::tip
46+
If you don't need SSO and only want standard OAuth (sign-in button), leave the **Token Exchange URL** blank in your OAuth connection settings.
47+
:::
48+
49+
To handle `signin/failure` programmatically in your app, see <LangLink to="in-depth-guides/user-authentication#handling-sign-in-failures">Handling Sign-In Failures</LangLink> in the User Authentication guide.

teams.md/src/components/include/in-depth-guides/user-authentication/csharp.incl.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ teams.OnMessage("/signout", async context =>
8888
await context.Send("you have been signed out!");
8989
});
9090
```
91+
<!-- signin-failure -->
92+
93+
```cs
94+
teams.OnSignInFailure(async (context, cancellationToken) =>
95+
{
96+
var failure = context.Activity.Value;
97+
Console.WriteLine($"Sign-in failed: {failure?.Code} - {failure?.Message}");
98+
await context.Send("Sign-in failed.", cancellationToken);
99+
});
100+
```
101+
91102
<!-- regional-bot -->
92103

93104
N/A

teams.md/src/components/include/in-depth-guides/user-authentication/python.incl.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ async def handle_signout_message(ctx: ActivityContext[MessageActivity]):
8686
await ctx.send("You have been signed out!")
8787
```
8888

89+
<!-- signin-failure -->
90+
91+
```python
92+
@app.on_signin_failure()
93+
async def handle_signin_failure(ctx):
94+
failure = ctx.activity.value
95+
print(f"Sign-in failed: {failure.code} - {failure.message}")
96+
await ctx.send("Sign-in failed.")
97+
```
98+
99+
:::note
100+
In Python, registering a custom handler does **not** replace the built-in default handler. Both will run as part of the middleware chain.
101+
:::
102+
89103
<!-- regional-bot -->
90104
import Tabs from '@theme/Tabs';
91105
import TabItem from '@theme/TabItem';

teams.md/src/components/include/in-depth-guides/user-authentication/typescript.incl.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ app.message('/signout', async ({ send, signout, isSignedIn }) => {
8181
});
8282
```
8383

84+
<!-- signin-failure -->
85+
86+
```ts
87+
app.on('signin.failure', async ({ activity, send }) => {
88+
const { code, message } = activity.value;
89+
console.log(`Sign-in failed: ${code} - ${message}`);
90+
await send('Sign-in failed.');
91+
});
92+
```
93+
8494
<!-- regional-bot -->
8595
import Tabs from '@theme/Tabs';
8696
import TabItem from '@theme/TabItem';

teams.md/src/pages/templates/in-depth-guides/user-authentication.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ You can signout by calling the `signout` method, this will remove the token from
9696

9797
<LanguageInclude section="signing-out" />
9898

99+
## Handling Sign-In Failures
100+
101+
When using SSO, if the token exchange fails Teams sends a `signin/failure` invoke activity to your app. The SDK includes a built-in default handler that logs a warning with actionable troubleshooting guidance. You can optionally register your own handler to customize the behavior:
102+
103+
<LanguageInclude section="signin-failure" />
104+
105+
:::tip
106+
The most common failure codes are `installedappnotfound` (bot app not installed for the user) and `resourcematchfailed` (Token Exchange URL doesn't match the Application ID URI). See [SSO Setup - Troubleshooting](/teams/user-authentication/sso-setup#troubleshooting-sso) for a full list of failure codes and troubleshooting steps.
107+
:::
108+
99109
<LanguageInclude section="regional-bot" />
100110

101111
## Resources

teams.md/src/pages/templates/migrations/slack-bolt.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ There are two primary types of user authentication for Teams and Slack: authenti
7575

7676
In Slack, if you want to use Slack REST APIs that require user-delegated scopes, you need to implement an OAuth 2.0 installation flow in your application to obtain and store Slack user tokens, even if the app was already installed by another user. In Teams, you can leverage Teams SSO to obtain user Entra tokens for calling Graph REST APIs. The Teams SDK integrates with Teams SSO and Azure Bot Token Service to handle token acquisition, storage, and refresh automatically for you.
7777

78-
First, follow the instructions in the [Teams SSO guide](../../../../docs/main/teams/user-authentication/sso-setup.md).
78+
First, follow the instructions in the [Teams SSO guide](../../../../docs/main/teams/user-authentication/sso-setup.mdx).
7979

8080
Then, configure the authentication in your code.
8181

0 commit comments

Comments
 (0)