Tutorial: Add OAuth authentication to a Teams bot

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:

  1. Create or reuse a resource group and App Service plan for Azure hosting.
  2. Register an Azure Bot resource and enable the Microsoft Teams channel.
  3. Configure Microsoft Entra ID, an OAuth connection, and Teams SSO.
  4. Configure and deploy the sample in your preferred language.
  5. Install the app in Teams and test signin, profile, and signout.

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:

  1. In your browser, sign into the Microsoft Azure portal.
  2. In the left navigation panel, select Resource groups.
  3. In the upper left of the displayed window, select Add tab to create a new resource group. Provide the following details:
    1. Subscription. Use your existing subscription.
    2. Resource group. Enter the name for the resource group. An example could be TeamsResourceGroup. Remember that the name must be unique.
    3. From the Region dropdown menu, select West US, or a region close to your applications.
    4. Select the Review and create button. You should see a banner that reads Validation passed.
    5. 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.

  1. In the Azure portal, on the left navigation panel, select Create a resource.
  2. In the search box, type App Service Plan. Select the App Service Plan card from the search results.
  3. Select Create.
  4. Provide the following information:
    1. Subscription. You can use an existing subscription.
    2. Resource Group. Select the group you created earlier.
    3. Name. Enter the name for the service plan. An example could be TeamsServicePlan. Remember that the name must be unique, within the group.
    4. Operating System. Select Windows or your applicable OS.
    5. Region. Select West US or a region close to your applications.
    6. Pricing Tier. Select Standard S1, which is the default value.
    7. Select the Review and create button. You should see a banner that reads Validation passed.
    8. 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.

  1. Visit Azure portal and search for Azure Bot in Create a resource section.

  2. Open the Azure Bot and select Create.

  3. Enter bot handle name in Bot handle field.

  4. Select your Subscription from the dropdown list.

  5. Select your Resource group from the dropdown list.

  6. 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.
  7. Select Review + create.

  8. If the validation passes, select Create.

    Azure provisions your bot.

  9. 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:

  1. In Settings, select Configuration. Save the Microsoft App ID (client ID) for future reference.

  2. Next to Microsoft App ID, select Manage.

  3. In the Client secrets section, select New client secret. Add a client secret window appears.

  4. Enter Description and select Add.

  5. 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:

  1. Go to Home.

  2. Open your bot from the Recent resources section.

  3. Select Channels in the left pane and select Microsoft Teams .

  4. Select the checkbox to accept the terms of service and select Agree.

  5. 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.

  1. 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.

  2. In the left panel, select App registrations.

  3. In the right panel, select the New registration tab, in the upper left.

  4. Provide the following information:

    1. Name. Enter the name for the application. An example could be BotTeamsIdentity. Remember that the name must be unique.
    2. Select the Supported account types for your intended users. For a single-tenant test, select Accounts in this organizational directory only.
    3. For the Redirect URI:
      ✓Select Web.
      ✓ Set the URL to https://token.botframework.com/.auth/web/redirect.
    4. Select Register.
  5. After Azure creates the app, it displays the Overview page for the app. Copy and save the following information to a file:

    1. The Application (client) ID value. Use this value later as the Client ID when you register this Azure identity application with your bot.
    2. The Directory (tenant) ID value. Use this value later as the Tenant ID when you register this Azure identity application with your bot.
  6. In the left panel, select Certificates & secrets to create a client secret for your application.

    1. Under Client secrets, select ➕ New client secret.
    2. Add a description to identify this secret from others you might need to create for this app, such as Bot identity app in Teams.
    3. Set Expires to your selection.
    4. Select Add.
    5. 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.
  7. Select API permissions > Add a permission > Microsoft Graph > Delegated permissions. Add User.Read for the sample's profile command. Obtain admin consent if required by your tenant.

  8. On the identity-provider app you just created, complete the API, access_as_user scope, 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

  1. In the Azure portal, select your resource group from the dashboard.

  2. Select your bot registration link.

  3. Open the resource page and select Configuration under Settings.

  4. Select Add OAuth Connection Settings.

  5. Complete the form as follows:

    1. 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.

    2. Service Provider. Select Azure Active Directory. Once you select this option, the Azure Active Directory-specific fields are displayed.

    3. Client id. Enter the Application (client) ID that you recorded for your Azure identity provider app.

    4. Client secret. Enter the secret that you recorded for your Azure identity provider app.

    5. Grant Type. Enter authorization_code.

    6. Login URL. Enter https://login.microsoftonline.com.

    7. 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 common to support its configured audience.

    8. For Resource URL, enter https://graph.microsoft.com/.

    9. Leave Scopes blank.

  6. Select Save.

Microsoft Azure Active Directory (Azure AD) v2

  1. In the Azure portal, select your Azure Bot from the dashboard.

  2. In the resource page, select Configuration under Settings.

  3. Select Add OAuth Connection Settings.

  4. Complete the form as follows:

    1. 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.

    2. Service Provider. Select Azure Active Directory v2. Once you select this option, the Azure AD v2 specific fields are displayed.

    3. Client id. Enter the Application (client) ID that you recorded for your Azure identity provider app.

    4. Client secret. Enter the secret that you recorded for your Azure identity provider app.

    5. 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.resource in the app manifest. Leave this field blank only for explicit OAuth sign-in without SSO.

    6. 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 common to support that application's configured audience. This OAuth connection setting is separate from the bot runtime's tenant ID.

    7. For Scopes, enter User.Read for the sample's profile command. Add other delegated permissions only when your bot needs them.

  5. Select Save.

Test the connection

  1. Select the connection entry to open the connection you created.

  2. Select Test Connection at the top of the Service Provider Connection Setting panel.

  3. For the first time, it opens a new browser window asking you to select an account. Select the one you want to use.

  4. Review the permissions requested by the identity-provider application.

  5. Select Accept.

  6. 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.

  1. Clone cs-auth-sample.

  2. Open Visual Studio.

  3. From the toolbar, select File > Open > Project/Solution and open the bot project.

  4. 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.TenantId identifies the tenant containing the bot identity. Set it to the bot's directory (tenant) ID.
    • AzureAd.ClientId identifies the bot to Azure Bot Service. Set it to the bot's Microsoft App ID.
    • AzureAd.ClientCredentials supplies the bot identity's credential. Replace the secret placeholder with the bot's client secret Value through secure configuration.
    • OAuth.ConnectionName selects the bot's configured OAuth connection. Set it to the exact connection name saved on the Azure Bot resource.
  5. Use M365Agent/appPackage, alongside the BotAuthQuickstart runtime project, and update the app manifest values before installing the app in Teams.

  6. To run locally, use dotnet run --no-launch-profile --urls http://localhost:3978 from BotAuthQuickstart. This builds the project and sets the HTTP port to 3978.

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.

  1. Clone node-auth-sample.

  2. In a console, go to the samples/TeamsSDK/bot-auth-quickstart/nodejs/bot-auth-quickstart project folder.

  3. Install dependencies with npm install.

  4. For manual local setup with the Azure Bot resource you created in this tutorial, create or update .localConfigs in the project root:

    TENANT_ID=<bot-tenant-id>
    CLIENT_ID=<bot-app-id>
    CLIENT_SECRET=<bot-client-secret-value>
    CONNECTION_NAME=BotTeamsAuthADv2
    
    • TENANT_ID identifies the tenant containing the bot identity. Set it to the bot's directory (tenant) ID.
    • CLIENT_ID identifies the bot to Azure Bot Service. Set it to the bot's Microsoft App ID.
    • CLIENT_SECRET supplies the bot identity's client secret value. Use the value, not the secret ID.
    • CONNECTION_NAME selects 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 .localConfigs out of source control.

  5. Build the TypeScript project, then start it with the sample's installed env-cmd dependency to load .localConfigs. Run each command after the previous one succeeds:

    npm run build
    npx --no-install env-cmd -f .localConfigs npm start
    

    For local development with automatic restarts, use npm run dev:teamsfx instead. That script also loads .localConfigs before starting the development server. npm start alone doesn't load this file, and the sample's launch scripts don't load .env.

  6. In the appPackage folder, 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.

  1. Clone py-auth-sample from the GitHub repository.

  2. In the Python runtime project folder, create a virtual environment with python -m venv .venv and activate it for your operating system. Then install the sample and its dependencies with python -m pip install -e ..

  3. 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=BotTeamsAuthADv2
    
    • TENANT_ID identifies the tenant containing the bot identity. Set it to the bot's directory (tenant) ID.
    • CLIENT_ID identifies the bot to Azure Bot Service. Set it to the bot's Microsoft App ID.
    • CLIENT_SECRET supplies the bot identity's client secret value. Use the value, not the secret ID.
    • CONNECTION_NAME selects the bot's configured OAuth connection. Set it to the exact connection name saved on the Azure Bot resource.

    Save the values in .env in 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.

  4. In the appPackage folder, update the app manifest values before installing the app in Teams.

  5. With the virtual environment active, run python main.py from the Python runtime project folder. Alternatively, use the supplied Visual Studio Code Start Python debug configuration, which loads .env through its envFile setting.

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.

  1. 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 publishes BotAuthQuickstart.csproj for win-x86, self-contained, and uploads BotAuthQuickstart/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 the M365Agent project.

    Use the Toolkit project folder nodejs/bot-auth-quickstart, relative to the sample root. The lifecycle runs npm install and npm run build --if-present, then uploads the project. For this walkthrough, use a Linux Node.js App Service and set its startup command to npm start, which runs lib/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 to python main.py, and set the app environment variable PORT=8000 to match the built-in Python container's HTTP port; see Configure a Python app in App Service.

    Prepare a requirements.txt for App Service build automation from the sample's pyproject.toml dependency declarations, including the pinned Teams SDK versions. Enable SCM_DO_BUILD_DURING_DEPLOYMENT=true so the deployment installs those dependencies. Don't upload your local virtual environment.

  2. Open the Toolkit project folder for your implementation in Visual Studio Code. In the selected environment's env/.env.<environment> file, set BOT_AZURE_APP_SERVICE_RESOURCE_ID to 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.

  3. 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, and OAuth__ConnectionName.

    Set TENANT_ID, CLIENT_ID, CLIENT_SECRET, and CONNECTION_NAME.

    Set credentials through secure host configuration, such as Key Vault references. Don't deploy local secrets or rely on .localConfigs or .env being present on the server. Before deployment, review the azureAppService/zipDeploy action's ignoreFile and ensure it excludes secret-bearing files, Toolkit environment files, and local virtual environments.

  4. 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.

  5. 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 as https://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.

  1. In your browser, go to the Azure portal.
  2. Find your resource group.
  3. Select the resource link. The resource page is displayed.
  4. In the resource page, select Test in Web Chat. The bot starts and displays the predefined greetings.
  5. Enter signin and select Sign in if prompted.
  6. A pop-up dialog appears to Confirm Open URL to authenticate the bot's user (you).
  7. Select Confirm.
  8. If asked, select the applicable user's account and grant the requested permissions.
  9. Enter profile. Confirm that the bot returns the signed-in user's profile instead of displaying an access token.
  10. Enter signout to 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

  1. Locate your selected language's app package folder from Prerequisites. Ensure the package contains manifest.json, outline.png, and color.png.

  2. Open the sample's manifest.json and 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.

  3. Manually zip the completed manifest.json, outline.png, and color.png at the archive root, without an enclosing appPackage folder. 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.

  4. Open Microsoft Teams.

  5. In the left panel, at the bottom, select the Apps icon.

  6. In the right panel, at the bottom, select Upload a custom app.

  7. Browse to the ZIP you created and upload it.

  8. Select Add to install the app to Teams.

  9. 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

  1. Enter signin. Complete consent or the sign-in prompt if one appears.
  2. Enter profile and confirm that the bot returns your Microsoft Graph profile.
  3. Enter signout and 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.

  1. 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.
  2. Enter signout to clear the sample's stored token for the current user and OAuth connection. Enter signin again while observing diagnostics so a previously cached token doesn't satisfy the test without a new exchange.
  3. Verify that Teams sends a signin/tokenExchange invoke 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. A signin/verifyState invoke indicates completion of the interactive flow, not proof of SSO.
  4. Enter profile and confirm that the bot returns the expected user's profile following that exchange. Enter signout when 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:

  1. 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.

  2. In a terminal window, go the directory where you have ngrok.exe installed. We suggest setting the environment variable path to point to it.

  3. 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.

  4. Copy the forwarding HTTPS address that is similar to: https://dea822bf.ngrok.io/.

  5. Append /api/messages to obtain https://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.

  6. 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:

    1. In your browser, go to the Azure portal.
    2. Select your Bot Registration.
    3. In the left panel, select Settings.
    4. In the right panel, in the Messaging endpoint box, enter the ngrok URL, in our example, https://dea822bf.ngrok.io/api/messages.
  7. Test the bot while running locally using the Azure portal's Test in Web Chat.

  8. 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

See also