{"record":{"id":"32ec235daad8af90","repo":"bitwarden/server","slug":"provider-admin-not-found","errorCode":null,"errorMessage":"Provider admin not found.","messagePattern":"Provider admin not found\\.","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"bitwarden_license/src/Commercial.Core/AdminConsole/Services/ProviderService.cs","lineNumber":689,"sourceCode":"        {\n            await _eventService.LogProviderOrganizationEventAsync(providerOrganization, EventType.ProviderOrganization_VaultAccessed);\n        }\n        if (organization != null)\n        {\n            await _eventService.LogOrganizationEventAsync(organization, EventType.Organization_VaultAccessed);\n        }\n    }\n\n    public async Task InitiateDeleteAsync(Provider provider, string providerAdminEmail)\n    {\n        if (string.IsNullOrWhiteSpace(provider.Name))\n        {\n            throw new BadRequestException(\"Provider name not found.\");\n        }\n        var providerAdmin = await _userRepository.GetByEmailAsync(providerAdminEmail);\n        if (providerAdmin == null)\n        {\n            throw new BadRequestException(\"Provider admin not found.\");\n        }\n\n        var providerAdminOrgUser = await _providerUserRepository.GetByProviderUserAsync(provider.Id, providerAdmin.Id);\n        if (providerAdminOrgUser == null || providerAdminOrgUser.Status != ProviderUserStatusType.Confirmed ||\n            providerAdminOrgUser.Type != ProviderUserType.ProviderAdmin)\n        {\n            throw new BadRequestException(\"Org admin not found.\");\n        }\n\n        var token = _providerDeleteTokenDataFactory.Protect(new ProviderDeleteTokenable(provider, 1));\n        await _mailService.SendInitiateDeletProviderEmailAsync(providerAdminEmail, provider, token);\n    }\n\n    public async Task DeleteAsync(Provider provider, string token)\n    {\n        if (!_providerDeleteTokenDataFactory.TryUnprotect(token, out var data) || !data.Valid || !data.IsValid(provider))\n        {\n            throw new BadRequestException(\"Invalid token.\");","sourceCodeStart":671,"sourceCodeEnd":707,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/bitwarden_license/src/Commercial.Core/AdminConsole/Services/ProviderService.cs#L671-L707","documentation":"Thrown by ProviderService.InitiateDeleteAsync when no user account exists for providerAdminEmail (userRepository.GetByEmailAsync returns null). The admin who authorizes provider deletion must be a real account. BadRequestException (HTTP 400).","triggerScenarios":"Calling InitiateDeleteAsync with an email that does not match any User (wrong address, unregistered admin, wrong-case lookup if the store is case-sensitive).","commonSituations":"Typo in the admin email; admin account not yet created; using a personal alias that differs from the registered email; case mismatch in the stored email.","solutions":["Confirm the admin email matches an existing User account (GetByEmailAsync) before initiating deletion.","Use the exact email casing stored on the user record.","If the admin lacks an account, create/invite them first."],"exampleFix":"// before\nawait providerService.InitiateDeleteAsync(provider, adminEmail);\n\n// after\nvar admin = await _userRepository.GetByEmailAsync(adminEmail);\nif (admin == null)\n{\n    return BadRequest(\"No account found for the given admin email.\");\n}\nawait providerService.InitiateDeleteAsync(provider, adminEmail);","handlingStrategy":"validation","validationCode":"var admin = await userRepository.GetByEmailAsync(adminEmail);\nif (admin == null) return BadRequest(\"Admin account not found.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the exact registered admin email.","Confirm the admin account exists before deletion."],"tags":["provider","user-lookup","deletion","bad-request"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}