{"record":{"id":"efd17dc9e794a1ff","repo":"bitwarden/server","slug":"no-teams-were-found","errorCode":null,"errorMessage":"No teams were found.","messagePattern":"No teams were found\\.","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"src/Api/Dirt/Controllers/TeamsIntegrationController.cs","lineNumber":126,"sourceCode":"            protocol: currentContext.HttpContext.Request.Scheme,\n            host: currentContext.HttpContext.Request.Host.ToUriComponent()\n        );\n        if (string.IsNullOrEmpty(callbackUrl))\n        {\n            throw new BadRequestException(\"Unable to build callback Url\");\n        }\n\n        var token = await teamsService.ObtainTokenViaOAuth(code, callbackUrl);\n        if (string.IsNullOrEmpty(token))\n        {\n            throw new BadRequestException(\"Invalid response from Teams.\");\n        }\n\n        var teams = await teamsService.GetJoinedTeamsAsync(token);\n\n        if (!teams.Any())\n        {\n            throw new BadRequestException(\"No teams were found.\");\n        }\n\n        var teamsIntegration = new TeamsIntegration(TenantId: teams[0].TenantId, Teams: teams);\n        integration.Configuration = JsonSerializer.Serialize(teamsIntegration);\n        await integrationRepository.UpsertAsync(integration);\n\n        var location = $\"/organizations/{integration.OrganizationId}/integrations/{integration.Id}\";\n        return Created(location, new OrganizationIntegrationResponseModel(integration));\n    }\n\n    [Route(\"integrations/teams/incoming\")]\n    [AllowAnonymous]\n    [HttpPost]\n    public async Task IncomingPostAsync()\n    {\n        await adapter.ProcessAsync(Request, Response, bot);\n    }\n}","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/src/Api/Dirt/Controllers/TeamsIntegrationController.cs#L108-L144","documentation":"Thrown during the Teams OAuth callback after the token is obtained but teamsService.GetJoinedTeamsAsync returns an empty list. The authenticated Microsoft account has no Teams memberships to integrate with. BadRequestException returns HTTP 400, and the integration is not persisted.","triggerScenarios":"OAuth callback where the Microsoft account that authorized the app belongs to no Microsoft Teams teams. This can happen if the account is a personal Microsoft account, or an organizational account with no team memberships.","commonSituations":"User signs in with a personal Microsoft account instead of a work/school account; the organization has Teams disabled or the user hasn't been added to any team; the Teams service principal lacks permission to read the user's joined teams (Team.ReadBasic.All scope missing).","solutions":["Ensure the user signs in with a work/school Microsoft account that is a member of at least one Team.","Verify the Azure AD app has the Team.ReadBasic.All (or equivalent) permission granted.","Confirm Teams is enabled in the user's Microsoft 365 tenant.","Provide a user-facing message prompting them to join or create a Team first."],"exampleFix":"// before\nvar teams = await teamsService.GetJoinedTeamsAsync(token);\nif (!teams.Any()) throw new BadRequestException(\"No teams were found.\");\n\n// after — actionable user message\nvar teams = await teamsService.GetJoinedTeamsAsync(token);\nif (!teams.Any())\n{\n    throw new BadRequestException(\"Your Microsoft account is not a member of any Teams. Join or create a Team in Microsoft Teams, then retry.\");\n}","handlingStrategy":"validation","validationCode":"// After token acquisition, check team membership before persisting\nvar teams = await _teamsService.GetJoinedTeamsAsync(token);\nif (teams == null || !teams.Any())\n    return BadRequest(\"Your Microsoft account is not a member of any Teams. Join or create a Team, then retry.\");","typeGuard":"public static bool HasTeamMemberships(IReadOnlyList<TeamInfo> teams) =>\n    teams != null && teams.Count > 0;","tryCatchPattern":"try\n{\n    await _teamsService.CompleteOAuthAsync(code, state);\n}\ncatch (BadRequestException ex) when (ex.Message.Contains(\"No teams\"))\n{\n    return BadRequest(\"No Teams found for your account. Ensure you are a member of at least one Microsoft Team.\");\n}","preventionTips":["Ensure users authorize with a work/school account that is a member of at least one Team.","Verify the Azure AD app has Team.ReadBasic.All permission granted and admin-consented.","Show a pre-connect UI message instructing users to join a Team first if they have none."],"tags":["teams","oauth","azure-ad","graph-api","permissions","csharp","aspnet"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}