Building, integrating, or customizing apps and workflows within Microsoft Teams using developer tools and APIs
The 401 in a single-tenant setup is caused by how the bot’s identity and tenant configuration are wired, not by a general Teams or Direct Line issue. In a single-tenant bot, the app registration, bot resource, and the tenant where the bot runs must be aligned, and the adapter must be initialized correctly for that single-tenant identity.
From the provided context, there are two directly relevant patterns:
- Single-tenant bot identity must be configured correctly in the bot code
For a single-tenant bot, the configuration must explicitly use:-
MicrosoftAppType = SingleTenant -
MicrosoftAppId =the bot’s app (client) ID -
MicrosoftAppPassword =the bot’s app secret -
MicrosoftAppTenantId =the tenant ID where the app is registered
appsettings.jsonfor C#,.envfor JavaScript,config.pyfor Python). If any of these values are missing or mismatched (for example, wrong tenant ID or app type), token acquisition will fail and outbound calls (such as Send Message) will return 401. -
- Service principal must exist for single-tenant bots
For a single-tenant Azure Bot Service (msaAppType: 'SingleTenant'), the app registration must be linked to a service principal in the tenant. If the service principal is missing, token requests tologin.microsoftonline.com/{tenantId}fail with 401. The fix is:- In Azure portal, go to App registrations.
- Open the bot’s app registration using the bot’s
Client ID. - Check the Managed application in local directory field:
- If a value is present, the service principal exists.
- If it shows Create Service Principal, select that to create it.
- After creation, restart the bot so it can acquire tokens using the new principal.
- Adapter initialization for single-tenant / cross-tenant scenarios
A similar 401 issue in Teams was resolved when the bot’s adapter (CloudAdapter) was initialized correctly for cross-tenant communication. If the adapter is still configured as if the app were multi-tenant, or if it does not use the correctMicrosoftAppTypeand tenant ID, the bot will receive 401 when sending messages even though it can receive them. The working pattern is:- Ensure the adapter uses the same identity configuration as above (
SingleTenant, correctAppId,TenantId, and secret). - For cross-tenant Teams usage with a single-tenant bot, the bot still authenticates only against its home tenant; the adapter must not be configured as multi-tenant just to reach other tenants.
- Ensure the adapter uses the same identity configuration as above (
- Why multi-tenant appears to “fix” it
When the app registration is changed to “Multiple Entra ID tenants”, the platform can fall back to multi-tenant token validation, which can mask a missing or misconfigured single-tenant identity (service principal orMicrosoftAppType/tenant ID mismatch). This is why it works in multi-tenant mode but fails in single-tenant mode. However, the Bot Framework and Teams support secure single-tenant bots. The correct fix is to:- Keep the app registration as single tenant.
- Ensure the service principal exists.
- Ensure the bot’s configuration and adapter use
SingleTenantwith the correct tenant ID and secret.
- Checklist to resolve the 401 in single-tenant mode
- In Azure portal → App registrations:
- Confirm the bot app is single tenant.
- Confirm a Managed application in local directory exists; if not, select Create Service Principal.
- In the bot’s configuration file:
- Set
MicrosoftAppType = SingleTenant. - Set
MicrosoftAppIdtod957be44-985d-4286-a773-f34cbae2e7a4. - Set
MicrosoftAppTenantIdto1134ea03-328d-4b26-9caf-505e7392d4aa. - Set
MicrosoftAppPasswordto the current client secret for that app.
- Set
- Ensure the adapter (CloudAdapter or equivalent) is initialized using those values.
- Restart the bot and retry the Send Message call.
- In Azure portal → App registrations:
Once the service principal and identity configuration are correct, the bot can remain single-tenant and still send messages via the Send Message API without 401 errors, including in cross-tenant Teams scenarios.
References: