In this end-to-end tutorial, you configure OAuth 2.0 with Microsoft Entra ID, deploy a Teams SDK bot to Azure, and test it in Microsoft Teams. The Bot Auth Quickstart sample uses Teams single sign-on (SSO) to access the signed-in user's Microsoft Graph profile.
Note
This command-based sample provides a delegated user-authentication foundation for Teams SDK conversational agents, not a complete AI agent.
Tip
For OAuth setup in an existing agent or bot without the deployment walkthrough, see Configure OAuth authentication for Teams agents and bots.
In this tutorial, you:
- Create or reuse a resource group and App Service plan for Azure hosting.
- Register an Azure Bot resource and enable the Microsoft Teams channel.
- Configure Microsoft Entra ID, an OAuth connection, and Teams SSO.
- Configure and deploy the sample in your preferred language.
- Install the app in Teams and test
signin,profile, andsignout.
Prerequisites
- Knowledge of bot basics and the Teams SDK.
- Knowledge of Azure and OAuth 2.0 development.
- Git and the language-specific tools listed below. Install Visual Studio Code with Microsoft 365 Agents Toolkit if you use the sample's Toolkit deployment workflow.
- Azure account. If needed, you can create an Azure free account.
- A Teams account with permission to upload custom apps, and permission to configure app registrations and grant consent in your test tenant.
- The Bot Auth Quickstart sample for your selected language.
Select C# for C#/.NET, TypeScript for TypeScript/JavaScript on Node.js, or Python in the language selector. The selection applies throughout this article. The following paths are relative to samples/TeamsSDK/bot-auth-quickstart in the sample repository.
Use the C#/.NET Bot Auth Quickstart sample. Install the .NET 10 SDK and, if using the IDE, a Visual Studio version that supports .NET 10.
- Runtime project:
dotnet/bot-auth-quickstart/BotAuthQuickstart. - App package:
dotnet/bot-auth-quickstart/M365Agent/appPackage.
For .NET, the runtime project and the M365Agent packaging/deployment project are siblings. Don't look for appPackage inside BotAuthQuickstart.
Use the TypeScript/JavaScript Bot Auth Quickstart sample. Install Node.js LTS and npm. The sample's source code is TypeScript and builds to JavaScript.
- Runtime project:
nodejs/bot-auth-quickstart. - App package:
nodejs/bot-auth-quickstart/appPackage.
Use the Python Bot Auth Quickstart sample. Install Python 3.11 or later, below 4.0, with pip and a virtual environment.
- Runtime project:
python/bot-auth-quickstart. - App package:
python/bot-auth-quickstart/appPackage.
Create the resource group
For this tutorial, use a resource group to organize the Azure resources, or you can reuse an existing resource group. The App Service plan is for hosting the bot in Azure App Service, not for enabling OAuth. You use a resource group to create individual resources for the bot. For performance, ensure that these resources are located in the same Azure region:
- In your browser, sign into the Microsoft Azure portal.
- In the left navigation panel, select Resource groups.
- In the upper left of the displayed window, select Add tab to create a new resource group. Provide the following details:
- Subscription. Use your existing subscription.
- Resource group. Enter the name for the resource group. An example could be TeamsResourceGroup. Remember that the name must be unique.
- From the Region dropdown menu, select West US, or a region close to your applications.
- Select the Review and create button. You should see a banner that reads Validation passed.
- Select the Create button. It might take a few minutes to create the resource group.
Tip
As with the resources you'll create later in this tutorial, it's a good idea to pin this resource group to your dashboard for easy access. If you'd like to do so, select the pin icon 📌 in the upper right of the dashboard.
Create the service plan
Skip this section if you already have a suitable App Service plan or plan to host the bot elsewhere. Azure hosting can incur charges; choose a pricing tier appropriate for your test environment.
- In the Azure portal, on the left navigation panel, select Create a resource.
- In the search box, type App Service Plan. Select the App Service Plan card from the search results.
- Select Create.
- Provide the following information:
- Subscription. You can use an existing subscription.
- Resource Group. Select the group you created earlier.
- Name. Enter the name for the service plan. An example could be TeamsServicePlan. Remember that the name must be unique, within the group.
- Operating System. Select Windows or your applicable OS.
- Region. Select West US or a region close to your applications.
- Pricing Tier. Select Standard S1, which is the default value.
- Select the Review and create button. You should see a banner that reads Validation passed.
- Select Create. It might take a few minutes to create the app service plan. The plan is listed in the resource group.
Create Azure Bot resource registration
The Azure Bot resource registers your web service with Azure Bot Service and associates it with a bot identity. This tutorial uses a single-tenant bot with a client secret.
Important
An Azure Bot resource is required for the OAuth connection used here, even when you host your bot outside Azure. If you already have an Azure Bot resource, reuse it. A bot created only through Developer Portal doesn't provide these Azure OAuth connection settings.
Visit Azure portal and search for Azure Bot in Create a resource section.
Open the Azure Bot and select Create.
Enter bot handle name in Bot handle field.
Select your Subscription from the dropdown list.
Select your Resource group from the dropdown list.
Select Single Tenant for Type of App under Microsoft App ID.
Important
- The Multi Tenant bot type in Azure Bot Service is deprecated. Existing Multi Tenant bots continue to work for now.
- All new bot registrations must either use the Single Tenant bot type or the User-Assigned Managed Identity type.
- When registering your Entra app in Azure portal, you can still select the Accounts in any organizational directory (Multi Tenant) option. This enables your bot to work across multiple tenants, even outside the tenant where the app is registered, when using one of the supported bot types.
- Set the bot runtime's TENANT_ID to the tenant containing the bot identity. The identity-provider application's tenant setting is configured separately in the OAuth connection.
Select Review + create.
If the validation passes, select Create.
Azure provisions your bot.
Select Go to resource. The bot and the related resources are listed in the resource group.
Your Azure bot is created.
For a bot that uses a user-assigned managed identity instead, follow the identity-specific configuration in Add authentication to a bot. Don't create a bot client secret for a managed identity.
To create client secret:
In Settings, select Configuration. Save the Microsoft App ID (client ID) for future reference.
Next to Microsoft App ID, select Manage.
In the Client secrets section, select New client secret. Add a client secret window appears.
Enter Description and select Add.
In the Value column, select Copy to clipboard and store the secret value securely. Use the Value, not the secret ID. Also record the bot identity's directory (tenant) ID.
Caution
Don't commit client secrets or access tokens to source control or include them in screenshots, chat messages, or logs.
To add the Microsoft Teams channel:
Go to Home.
Open your bot from the Recent resources section.
Select Channels in the left pane and select Microsoft Teams
.Select the checkbox to accept the terms of service and select Agree.
Select Save.
For more information, see Connect a bot to Microsoft Teams.
Create the identity provider
This tutorial uses Microsoft Entra ID as the identity provider. Keep the bot identity credentials separate from the identity-provider application credentials: the former authenticate the bot to the service, and the latter authorize access on behalf of users.
For OAuth setup without deployment or SSO, see Register the identity-provider application.
In the Azure portal, on the left navigation panel, select Microsoft Entra ID.
Tip
You must create and register this Microsoft Entra resource in a tenant in which you can consent to delegate permissions requested by an application. For instructions on creating a tenant, see Access the portal and create a tenant.
In the left panel, select App registrations.
In the right panel, select the New registration tab, in the upper left.
Provide the following information:
- Name. Enter the name for the application. An example could be BotTeamsIdentity. Remember that the name must be unique.
- Select the Supported account types for your intended users. For a single-tenant test, select Accounts in this organizational directory only.
- For the Redirect URI:
✓Select Web.
✓ Set the URL tohttps://token.botframework.com/.auth/web/redirect. - Select Register.
After Azure creates the app, it displays the Overview page for the app. Copy and save the following information to a file:
- The Application (client) ID value. Use this value later as the Client ID when you register this Azure identity application with your bot.
- The Directory (tenant) ID value. Use this value later as the Tenant ID when you register this Azure identity application with your bot.
In the left panel, select Certificates & secrets to create a client secret for your application.
- Under Client secrets, select ➕ New client secret.
- Add a description to identify this secret from others you might need to create for this app, such as Bot identity app in Teams.
- Set Expires to your selection.
- Select Add.
- Before leaving this page, record the secret. Use this value later as the Client secret when you register your Microsoft Entra application with your bot.
Select API permissions > Add a permission > Microsoft Graph > Delegated permissions. Add
User.Readfor the sample's profile command. Obtain admin consent if required by your tenant.On the identity-provider app you just created, complete the API,
access_as_userscope, Teams client authorization, and access token version steps in Configure SSO with a separate authentication app. Its redirect URI, secret, and Graph permissions are already configured above; configure the Azure Bot OAuth connection in the next section. Don't open the bot identity registration through Azure Bot > Configuration > Manage for the SSO app changes.
Use the following mapping throughout this tutorial. The bot and authentication app IDs are different; don't replace one with the other.
| Value | Source and use |
|---|---|
TEAMS_APP_ID |
Your Teams app's unique ID. Use it for id in the app manifest, independently of the bot and authentication app IDs. |
BOT_ID |
The Microsoft App ID on the Azure Bot resource's Configuration page. Use it for the bot runtime's client ID and bots[].botId in the app manifest. |
SSO_APP_ID |
The Application (client) ID of the separate identity-provider app. Use it for the OAuth connection's Client id and the app manifest's webApplicationInfo.id. Use this app's secret for the OAuth connection's Client secret, not for the bot runtime. |
SSO_APP_ID_URI |
The Application ID URI exposed on the identity-provider app. For this standalone bot, set it to api://botid-{BOT_ID}, replacing {BOT_ID} with the bot's Microsoft App ID, not SSO_APP_ID. |
| Token Exchange URL | Set the Azure Bot OAuth connection field to the exact SSO_APP_ID_URI, without the /access_as_user scope suffix. |
webApplicationInfo.resource |
Set this app manifest field to the exact same SSO_APP_ID_URI. |
validDomains |
Include token.botframework.com for this public-cloud OAuth flow. Preserve other required domains and replace any BOT_DOMAIN placeholder with your bot's hostname. |
Note
This tutorial uses the default public-cloud redirect URI. For other clouds or regional data residency, use Supported OAuth URLs.
Configure the identity provider connection and register it with the bot
Note
Use Azure Active Directory v2 for the SSO sample in this tutorial. The v1 procedure below is retained for existing OAuth integrations, not for this sample's Teams SSO setup. For explicit OAuth sign-in without SSO, see Configure OAuth authentication for Teams agents and bots.
Microsoft Azure Active Directory (Azure AD) v1
In the Azure portal, select your resource group from the dashboard.
Select your bot registration link.
Open the resource page and select Configuration under Settings.
Select Add OAuth Connection Settings.
Complete the form as follows:
Name. Enter a name for the connection, such as BotTeamsAuthADv1. Save this exact name for your bot's runtime configuration; see Prepare the bot sample code for language-specific settings.
Service Provider. Select Azure Active Directory. Once you select this option, the Azure Active Directory-specific fields are displayed.
Client id. Enter the Application (client) ID that you recorded for your Azure identity provider app.
Client secret. Enter the secret that you recorded for your Azure identity provider app.
Grant Type. Enter
authorization_code.Login URL. Enter
https://login.microsoftonline.com.Tenant ID, enter the Directory (tenant) ID that you recorded earlier for your Azure identity app or common depending on the supported account type selected when you created the identity provider app. To decide which value to assign, follow these criteria:
For a single-tenant identity-provider app, enter its directory (tenant) ID.
For a multitenant identity-provider app, enter
commonto support its configured audience.
For Resource URL, enter
https://graph.microsoft.com/.Leave Scopes blank.
Select Save.
Microsoft Azure Active Directory (Azure AD) v2
In the Azure portal, select your Azure Bot from the dashboard.
In the resource page, select Configuration under Settings.
Select Add OAuth Connection Settings.
Complete the form as follows:
Name. Enter a name for the connection, such as BotTeamsAuthADv2. Save this exact name for your bot's runtime configuration; see Prepare the bot sample code for language-specific settings.
Service Provider. Select Azure Active Directory v2. Once you select this option, the Azure AD v2 specific fields are displayed.
Client id. Enter the Application (client) ID that you recorded for your Azure identity provider app.
Client secret. Enter the secret that you recorded for your Azure identity provider app.
Token Exchange URL. For this SSO sample, enter the application ID URI you configured for the identity-provider app. Use the same value for
webApplicationInfo.resourcein the app manifest. Leave this field blank only for explicit OAuth sign-in without SSO.Tenant ID, enter the Directory (tenant) ID that you recorded earlier for your Azure identity app or common depending on the supported account type selected when you created the identity provider app. To decide which value to assign, follow these criteria:
If you selected Accounts in this organizational directory only, enter that application's directory (tenant) ID.
If you selected a multitenant account type, enter
commonto support that application's configured audience. This OAuth connection setting is separate from the bot runtime's tenant ID.
For Scopes, enter
User.Readfor the sample's profile command. Add other delegated permissions only when your bot needs them.
Select Save.
Test the connection
Select the connection entry to open the connection you created.
Select Test Connection at the top of the Service Provider Connection Setting panel.
For the first time, it opens a new browser window asking you to select an account. Select the one you want to use.
Review the permissions requested by the identity-provider application.
Select Accept.
Confirm that Test Connection to <your-connection-name> Succeeded appears. If it fails, use Troubleshoot OAuth setup before trying again.
The bot code uses the connection name to retrieve user authentication tokens. This test verifies the provider connection, not the Teams SSO token exchange.
Prepare the bot sample code
Use one implementation of the Bot Auth Quickstart sample. Keep credentials out of source control and use the sample's local configuration or your hosting platform's secret settings.
For current SDK 2.1 examples, see Teams SDK user authentication. When updating an implementation, migrate its authentication code together with its SDK dependencies. Don't mix legacy default-connection configuration with the current flow-registration APIs.
For agent task continuation after sign-in, see Integrate with Teams SDK 2.1 and its pending-work guidance.
The C#/.NET sample references Microsoft.Teams.Apps 2.1.* and uses current SDK 2.1 OAuth flows, including AddOAuthFlow and SignInAsync.
Clone cs-auth-sample.
Open Visual Studio.
From the toolbar, select File > Open > Project/Solution and open the bot project.
In
BotAuthQuickstart/appsettings.json, configure the following sections:{ "AzureAd": { "TenantId": "<bot-tenant-id>", "ClientId": "<bot-app-id>", "ClientCredentials": [ { "SourceType": "ClientSecret", "ClientSecret": "<bot-client-secret-value>" } ] }, "OAuth": { "ConnectionName": "BotTeamsAuthADv2" } }AzureAd.TenantIdidentifies the tenant containing the bot identity. Set it to the bot's directory (tenant) ID.AzureAd.ClientIdidentifies the bot to Azure Bot Service. Set it to the bot's Microsoft App ID.AzureAd.ClientCredentialssupplies the bot identity's credential. Replace the secret placeholder with the bot's client secret Value through secure configuration.OAuth.ConnectionNameselects the bot's configured OAuth connection. Set it to the exact connection name saved on the Azure Bot resource.
Use
M365Agent/appPackage, alongside theBotAuthQuickstartruntime project, and update the app manifest values before installing the app in Teams.To run locally, use
dotnet run --no-launch-profile --urls http://localhost:3978fromBotAuthQuickstart. This builds the project and sets the HTTP port to3978.
Note
The TypeScript/JavaScript sample references @microsoft/teams.apps ^2.0.0 and uses legacy SDK 2.0-style oauth.defaultConnectionName and context-level sign-in. The dependency range can resolve to later 2.x versions; it isn't a pin to SDK 2.0. These instructions follow the linked legacy implementation, not SDK 2.1 code examples.
Clone node-auth-sample.
In a console, go to the
samples/TeamsSDK/bot-auth-quickstart/nodejs/bot-auth-quickstartproject folder.Install dependencies with
npm install.For manual local setup with the Azure Bot resource you created in this tutorial, create or update
.localConfigsin the project root:TENANT_ID=<bot-tenant-id> CLIENT_ID=<bot-app-id> CLIENT_SECRET=<bot-client-secret-value> CONNECTION_NAME=BotTeamsAuthADv2TENANT_IDidentifies the tenant containing the bot identity. Set it to the bot's directory (tenant) ID.CLIENT_IDidentifies the bot to Azure Bot Service. Set it to the bot's Microsoft App ID.CLIENT_SECRETsupplies the bot identity's client secret value. Use the value, not the secret ID.CONNECTION_NAMEselects the bot's configured OAuth connection. Set it to the exact connection name saved on the Azure Bot resource.
Microsoft 365 Agents Toolkit generates this file during its local deploy lifecycle in
m365agents.local.yml. If you use that workflow instead of manual setup, update the Toolkit environment values that populate.localConfigs; don't rely on manual edits that a later deploy can overwrite. Keep.localConfigsout of source control.Build the TypeScript project, then start it with the sample's installed
env-cmddependency to load.localConfigs. Run each command after the previous one succeeds:npm run build npx --no-install env-cmd -f .localConfigs npm startFor local development with automatic restarts, use
npm run dev:teamsfxinstead. That script also loads.localConfigsbefore starting the development server.npm startalone doesn't load this file, and the sample's launch scripts don't load.env.In the
appPackagefolder, update the app manifest values before installing the app in Teams.
Note
The Python sample pins microsoft-teams-apps==2.0.15 and uses legacy SDK 2.0 default_connection_name and context-level sign-in. These instructions follow the linked legacy implementation, not SDK 2.1 code examples.
Clone py-auth-sample from the GitHub repository.
In the Python runtime project folder, create a virtual environment with
python -m venv .venvand activate it for your operating system. Then install the sample and its dependencies withpython -m pip install -e ..Configure the environment values shown in the sample's
.env.TEMPLATE, using its local configuration instructions:TENANT_ID=<bot-tenant-id> CLIENT_ID=<bot-app-id> CLIENT_SECRET=<bot-client-secret-value> CONNECTION_NAME=BotTeamsAuthADv2TENANT_IDidentifies the tenant containing the bot identity. Set it to the bot's directory (tenant) ID.CLIENT_IDidentifies the bot to Azure Bot Service. Set it to the bot's Microsoft App ID.CLIENT_SECRETsupplies the bot identity's client secret value. Use the value, not the secret ID.CONNECTION_NAMEselects the bot's configured OAuth connection. Set it to the exact connection name saved on the Azure Bot resource.
Save the values in
.envin the Python runtime project folder. SDK 2.0.15 loads this file from the current working directory during import. Alternatively, set the values as environment variables in the terminal.In the
appPackagefolder, update the app manifest values before installing the app in Teams.With the virtual environment active, run
python main.pyfrom the Python runtime project folder. Alternatively, use the supplied Visual Studio Code Start Python debug configuration, which loads.envthrough itsenvFilesetting.
Deploy the bot to Azure
Deploy the Teams SDK web service, not just the Teams app package. You can use the sample's deploy lifecycle in m365agents.yml with Microsoft 365 Agents Toolkit. For the deployment UI and action reference, see Deploy to the cloud.
Create an Azure App Service web app on the plan you prepared earlier, with an operating system and runtime appropriate to your implementation. If the plan's operating system doesn't match the selected language's hosting requirements, create a compatible plan:
Use the Toolkit project folder
dotnet/bot-auth-quickstart/M365Agent, relative to the sample root. The supplied lifecycle publishesBotAuthQuickstart.csprojforwin-x86, self-contained, and uploadsBotAuthQuickstart/bin/Release/net10.0/win-x86/publish. Use a Windows App Service compatible with this target. Alternatively, publish the BotAuthQuickstart web project from Visual Studio to this App Service, not theM365Agentproject.Use the Toolkit project folder
nodejs/bot-auth-quickstart, relative to the sample root. The lifecycle runsnpm installandnpm run build --if-present, then uploads the project. For this walkthrough, use a Linux Node.js App Service and set its startup command tonpm start, which runslib/app.js. Use the same supported Node.js LTS version for the build and host; see Configure a Node.js app in App Service.Use the Toolkit project folder
python/bot-auth-quickstart, relative to the sample root. The lifecycle uploads the project but doesn't install its dependencies. Use a Linux Python App Service with a supported Python version matching the sample. Configure deployment-time dependency installation, set the startup command topython main.py, and set the app environment variablePORT=8000to match the built-in Python container's HTTP port; see Configure a Python app in App Service.Prepare a
requirements.txtfor App Service build automation from the sample'spyproject.tomldependency declarations, including the pinned Teams SDK versions. EnableSCM_DO_BUILD_DURING_DEPLOYMENT=trueso the deployment installs those dependencies. Don't upload your local virtual environment.Open the Toolkit project folder for your implementation in Visual Studio Code. In the selected environment's
env/.env.<environment>file, setBOT_AZURE_APP_SERVICE_RESOURCE_IDto the resource ID of the existing App Service web app.Important
This tutorial already creates a single-tenant bot registration with a client secret. The samples' cloud provisioning templates create managed-identity resources. Don't run their unmodified Provision lifecycle against this setup or replace the bot ID with a newly provisioned identity. Use Deploy to upload code to your existing App Service. Deployment doesn't generate the Teams app package; create it manually in Install and test the bot in Teams.
Configure runtime settings in the App Service environment, using the bot identity and connection name from this tutorial:
Set
AzureAd__TenantId,AzureAd__ClientId,AzureAd__ClientCredentials__0__SourceType=ClientSecret,AzureAd__ClientCredentials__0__ClientSecret, andOAuth__ConnectionName.Set
TENANT_ID,CLIENT_ID,CLIENT_SECRET, andCONNECTION_NAME.Set credentials through secure host configuration, such as Key Vault references. Don't deploy local secrets or rely on
.localConfigsor.envbeing present on the server. Before deployment, review theazureAppService/zipDeployaction'signoreFileand ensure it excludes secret-bearing files, Toolkit environment files, and local virtual environments.In Microsoft 365 Agents Toolkit, select Deploy under LIFECYCLE, then select the environment that targets your existing App Service. Check the deployment output and App Service startup logs for build, dependency, or configuration errors.
Record the App Service HTTPS URL, such as
https://botteamsauth.azurewebsites.net/. In the Azure portal, open your existing Azure Bot resource and set its Messaging endpoint to that URL followed by/api/messages, such ashttps://botteamsauth.azurewebsites.net/api/messages. Select Save.
Only one messaging endpoint is active per bot registration. For local Teams testing instead of Azure deployment, use Testing the bot locally in Teams.
Test locally using Microsoft 365 Agents Playground
Microsoft 365 Agents Playground is optional for checking local message routing, replies, and activity payloads with non-authenticated commands. It doesn't validate user authentication; use Teams testing, including SSO token-exchange verification.
Follow the Teams SDK Playground setup for your installed SDK version. Playground sends requests without a Bot Framework JWT by default. SDK versions that reject unauthenticated requests require explicit local request-authentication configuration.
The current guide documents the AzureAd__DangerouslyAllowUnauthenticatedRequests launch-profile setting for .NET.
The current guide documents dangerouslyAllowUnauthenticatedRequests for TypeScript/JavaScript. Check version compatibility before applying current options to the legacy sample.
The current guide documents dangerously_allow_unauthenticated_requests for Python. Check version compatibility before applying current options to the legacy sample.
Warning
Allow unauthenticated requests only in an isolated local Playground configuration. Never enable this bypass in production, deploy it to App Service, or expose a bypass-enabled local endpoint through a public tunnel. Disable it before testing through the Azure Bot Service and Teams.
Test the deployed bot
Web Chat checks message delivery and explicit sign-in, not Teams SSO. For SSO, use Verify Teams SSO token exchange.
- In your browser, go to the Azure portal.
- Find your resource group.
- Select the resource link. The resource page is displayed.
- In the resource page, select Test in Web Chat. The bot starts and displays the predefined greetings.
- Enter
signinand select Sign in if prompted. - A pop-up dialog appears to Confirm Open URL to authenticate the bot's user (you).
- Select Confirm.
- If asked, select the applicable user's account and grant the requested permissions.
- Enter
profile. Confirm that the bot returns the signed-in user's profile instead of displaying an access token. - Enter
signoutto sign out.
Note
If sign-in fails, test the connection and check the provider error, connection name, and bot credentials. See Troubleshoot OAuth setup.
Install and test the bot in Teams
Locate your selected language's app package folder from Prerequisites. Ensure the package contains
manifest.json,outline.png, andcolor.png.Open the sample's
manifest.jsonand apply the identity value mapping, preserving its other fields. Replace all remaining template placeholders with literal values before packaging. Don't include client secrets in the manifest or package.Manually zip the completed
manifest.json,outline.png, andcolor.pngat the archive root, without an enclosingappPackagefolder. Save the ZIP in a location you can select during upload. This workflow doesn't use a Toolkit-generated package: Deploy uploads bot code but doesn't generate a Teams app package.Open Microsoft Teams.
In the left panel, at the bottom, select the Apps icon.
In the right panel, at the bottom, select Upload a custom app.
Browse to the ZIP you created and upload it.
Select Add to install the app to Teams.
Open a personal chat with the bot for this tutorial's sign-in test.
Note
This tutorial tests personal scope. Teams SSO also supports group chat; see Enable SSO for your app for scope-specific behavior.
Verify user sign-in and OAuth fallback
- Enter
signin. Complete consent or the sign-in prompt if one appears. - Enter
profileand confirm that the bot returns your Microsoft Graph profile. - Enter
signoutand confirm the sign-out response.
These commands verify user access, not the sign-in mechanism. Complete SSO token-exchange verification separately.
Verify Teams SSO token exchange
Run this check after granting the required consent, using the same account in Teams and the authentication flow.
A profile response, sign-in-completion callback, or absence of a pop-up doesn't prove SSO. If the user signs in through an OAuth card and pop-up, record that result as interactive OAuth fallback.
- Enable the installed SDK version's authentication diagnostics, or use a debugger at the SDK's invoke handler. For a deployed bot, inspect its application logs; for a local bot, use its debugger or diagnostic output. Inspect only activity names, correlation identifiers, connection names, and exchange outcomes. Don't log access tokens, authorization headers, secrets, or full invoke payloads.
- Enter
signoutto clear the sample's stored token for the current user and OAuth connection. Entersigninagain while observing diagnostics so a previously cached token doesn't satisfy the test without a new exchange. - Verify that Teams sends a
signin/tokenExchangeinvoke and that the SDK successfully exchanges the token for the configured OAuth connection. Correlate that successful exchange with sign-in completion for the same user and conversation. Receiving the invoke alone isn't sufficient: an exchange can fail and fall back to interactive OAuth. Asignin/verifyStateinvoke indicates completion of the interactive flow, not proof of SSO. - Enter
profileand confirm that the bot returns the expected user's profile following that exchange. Entersignoutwhen finished.
If there is no new token-exchange activity, the outcome is inconclusive; confirm that sign-out cleared the correct user's connection token and repeat. If exchange fails or Teams uses an interactive sign-in card, record OAuth fallback separately and don't mark SSO as verified. Check signin/failure diagnostics, Teams client preauthorization, consent, and the matching Application ID URI, Token Exchange URL, and webApplicationInfo.resource. See SSO troubleshooting.
If you adapt this sample into an agent that resumes pending tasks, also test that behavior in Teams. While signed out, request an operation that needs delegated access, complete sign-in, and confirm the pending operation resumes for the correct user and conversation using the intended OAuth connection. Test cancellation or sign-in failure to verify that the agent provides feedback and expires or clears abandoned work. These are additional checks for your agent adaptation, not behavior demonstrated by the sample's signin, profile, and signout command sequence.
For current app-upload instructions, see Upload your app in Microsoft Teams.
Testing the bot locally in Teams
Teams is an entirely cloud-based product. It requires all services it accesses to be available from the cloud using HTTPS endpoints. Therefore, to enable the bot (our sample) to work in Teams, you need to either publish the code to the cloud of your choice, or make a locally running instance externally accessible via a tunneling tool. We recommend ngrok, which creates an externally addressable URL for a port you open locally on your machine. To set up ngrok in preparation for running your Teams app locally, follow these steps:
Disable any local Playground request-authentication bypass and start the bot using your selected language's sequence in Prepare the bot sample code. Confirm the listening port in the startup output; keep inbound request authentication enabled.
In a terminal window, go the directory where you have
ngrok.exeinstalled. We suggest setting the environment variable path to point to it.Run, for example,
ngrok http 3978 --host-header=localhost:3978. Replace both port values with the bot's actual listening port. It launches ngrok to listen on the port you specify and returns an externally addressable URL, valid for as long as ngrok is running.Copy the forwarding HTTPS address that is similar to:
https://dea822bf.ngrok.io/.Append
/api/messagesto obtainhttps://dea822bf.ngrok.io/api/messages, which is the messages endpoint for the bot running locally on your machine and reachable over the web in a chat in Teams.One final step to perform is to update the messages endpoint of the deployed bot. In the example, we deployed the bot in Azure. So let's perform these steps:
- In your browser, go to the Azure portal.
- Select your Bot Registration.
- In the left panel, select Settings.
- In the right panel, in the Messaging endpoint box, enter the ngrok URL, in our example,
https://dea822bf.ngrok.io/api/messages.
Test the bot while running locally using the Azure portal's Test in Web Chat.
Open the bot's personal chat in Teams and complete user sign-in and OAuth fallback checks and SSO token-exchange verification. Web Chat alone doesn't verify Teams SSO.
Note
If you stop and restart ngrok, the URL changes. To use ngrok in your project, and depending on the capabilities you're using, you must update all URL references.
Additional information
appPackage/manifest.json
Update the existing sample manifest using the identity value mapping, preserving its other fields. Map any differently named sample variables to those values and replace placeholders before packaging the app. For more information, see Update app manifest for SSO.
Code sample
| Sample name | Description | .NET |
|---|---|---|
| Bot Auth Quickstart | The Bot Auth Quickstart sample demonstrates OAuth and Teams SSO with Microsoft Entra ID. Use signin, profile, and signout to test sign-in and Microsoft Graph access. |
View |
| Sample name | Description | TypeScript |
|---|---|---|
| Bot Auth Quickstart | The Bot Auth Quickstart sample demonstrates OAuth and Teams SSO with Microsoft Entra ID. Use signin, profile, and signout to test sign-in and Microsoft Graph access. |
View |
| Sample name | Description | Python |
|---|---|---|
| Bot Auth Quickstart | The Bot Auth Quickstart sample demonstrates OAuth and Teams SSO with Microsoft Entra ID. Use signin, profile, and signout to test sign-in and Microsoft Graph access. |
View |