bitwarden/server · warning · BadRequestException
There already exists a Teams integration for this organizati
Error message
There already exists a Teams integration for this organization
What it means
Thrown during Teams OAuth initiation when a Teams integration already exists for the organization with non-null Configuration (fully completed). The controller blocks overriding a completed integration. BadRequestException returns HTTP 400.
Source
Thrown at src/Api/Dirt/Controllers/TeamsIntegrationController.cs:62
}
var integrations = await integrationRepository.GetManyByOrganizationAsync(organizationId);
var integration = integrations.FirstOrDefault(i => i.Type == IntegrationType.Teams);
if (integration is null)
{
// No teams integration exists, create Initiated version
integration = await integrationRepository.CreateAsync(new OrganizationIntegration
{
OrganizationId = organizationId,
Type = IntegrationType.Teams,
Configuration = null,
});
}
else if (integration.Configuration is not null)
{
// A Completed (fully configured) Teams integration already exists, throw to prevent overriding
throw new BadRequestException("There already exists a Teams integration for this organization");
} // An Initiated teams integration exits, re-use it and kick off a new OAuth flow
var state = IntegrationOAuthState.FromIntegration(integration, timeProvider);
var redirectUrl = teamsService.GetRedirectUrl(
callbackUrl: callbackUrl,
state: state.ToString()
);
if (string.IsNullOrEmpty(redirectUrl))
{
throw new NotFoundException();
}
return Redirect(redirectUrl);
}
[HttpGet("integrations/teams/create", Name = "TeamsIntegration_Create")]View on GitHub (pinned to e93b962371)
Solutions
- Delete the existing completed Teams integration before initiating a new OAuth flow.
- In the UI, detect an existing completed integration and show a 'Reconfigure' flow that deletes-then-recreates.
- Check the integration list endpoint before presenting the connect option.
Example fix
// before
await api.InitiateTeamsOAuthAsync(orgId); // 400 if already configured
// after
var integrations = await api.GetOrganizationIntegrationsAsync(orgId);
var teams = integrations.FirstOrDefault(i => i.Type == "Teams");
if (teams?.Configuration != null)
{
await api.DeleteIntegrationAsync(orgId, teams.Id);
}
await api.InitiateTeamsOAuthAsync(orgId); Defensive patterns
Strategy: validation
Validate before calling
var integrations = await integrationRepository.GetManyByOrganizationAsync(orgId);
var existing = integrations.FirstOrDefault(i => i.Type == IntegrationType.Teams);
if (existing?.Configuration != null)
return Conflict("A completed Teams integration already exists. Delete it first to reconfigure.");
// safe to initiate Type guard
public static bool HasCompletedTeamsIntegration(IEnumerable<OrganizationIntegration> integrations) =>
integrations.Any(i => i.Type == IntegrationType.Teams && i.Configuration != null); Try / catch
try
{
await _teamsService.InitiateOAuthAsync(orgId);
}
catch (BadRequestException ex) when (ex.Message.Contains("already exists"))
{
return Conflict(ex.Message);
} Prevention
- Check for existing completed integrations before presenting the connect option.
- Implement a clean delete-then-recreate workflow for reconfiguration.
- Show a clear UI state when a completed integration is already present.
When it happens
Trigger: Initiating a new Teams OAuth flow for an org that already has a completed Teams integration. An 'Initiated' (Configuration == null) integration can be re-used, but a 'Completed' one triggers this error.
Common situations: Re-running Teams setup for an org that already completed configuration; duplicate setup attempts; admin wants to reconfigure Teams without removing the old integration first.
Related errors
- There already exists a Slack integration for this organizati
- Unable to build callback Url
- Invalid response from Teams.
- Unable to build callback Url
- Invalid response from Slack.
AI-assisted analysis of bitwarden/server@e93b962371 (2026-08-13).
Data as JSON: /api/errors/0d8965e26a05f6d2.
Report an issue: GitHub.