{"record":{"id":"ab7830cf747bfaaf","repo":"bitwarden/server","slug":"cannotfindemailclaim","errorCode":null,"errorMessage":"CannotFindEmailClaim","messagePattern":"CannotFindEmailClaim","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"bitwarden_license/src/Sso/Controllers/AccountController.cs","lineNumber":542,"sourceCode":"    /// <exception cref=\"Exception\">An exception if the user cannot be provisioned as requested.</exception>\n    private async Task<(User resolvedUser, Organization foundOrganization, OrganizationUser foundOrgUser)> CreateUserAndOrgUserConditionallyAsync(\n            string provider,\n            string providerUserId,\n            IEnumerable<Claim> claims,\n            string userIdentifier,\n            SsoConfigurationData ssoConfigData\n        )\n    {\n        // Try to get the email from the claims as we don't know if we have a user record yet.\n        var name = GetName(claims, ssoConfigData.GetAdditionalNameClaimTypes());\n        var email = TryGetEmailAddress(claims, ssoConfigData, providerUserId);\n\n        User? possibleExistingUser;\n        if (string.IsNullOrWhiteSpace(userIdentifier))\n        {\n            if (string.IsNullOrWhiteSpace(email))\n            {\n                throw new Exception(_i18nService.T(\"CannotFindEmailClaim\"));\n            }\n\n            possibleExistingUser = await _userRepository.GetByEmailAsync(email);\n        }\n        else\n        {\n            possibleExistingUser = await GetUserFromManualLinkingDataAsync(userIdentifier);\n        }\n\n        // Find the org (we error if we can't find an org because no org is not valid)\n        var organization = await GetOrganizationByProviderAsync(provider);\n\n        // Try to find an org user (null org user possible and valid here)\n        var possibleOrgUser = await GetOrganizationUserByUserAndOrgIdOrEmailAsync(possibleExistingUser, organization.Id, email);\n\n        //----------------------------------------------------\n        // Scenario 1: We've found the user in the User table\n        //----------------------------------------------------","sourceCodeStart":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/bitwarden_license/src/Sso/Controllers/AccountController.cs#L524-L560","documentation":"Thrown in AccountController.CreateUserAndOrgUserConditionallyAsync (line 542) on the JIT-provisioning path when no manual linking userIdentifier was provided (it is null/whitespace) and TryGetEmailAddress returned no email from the claims or providerUserId. An email is required to look up or create the user.","triggerScenarios":"The user has not authenticated with this SSO provider before (no SsoUser link), no userIdentifier query param is present for manual linking, and the claims contain no email claim nor a providerUserId containing '@'.","commonSituations":"IdP does not emit an email claim and the configuration's additional email claim types don't match; SAML/OIDC attribute mapping for email is incorrect; the providerUserId is a numeric ID without '@' so the fallback email guess fails.","solutions":["Configure the IdP to emit an email claim (email, mail, or a custom attribute mapped in additional email claim types).","If the providerUserId is email-like, ensure it contains '@' so the fallback in TryGetEmailAddress applies.","Add the IdP's email attribute name to the SSO config's additional email claim types list.","For manual SSO linking, ensure the userIdentifier query parameter is passed."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var email = TryGetEmailAddress(claims, ssoConfigData, providerUserId);\nif (string.IsNullOrWhiteSpace(userIdentifier) && string.IsNullOrWhiteSpace(email))\n    return BadRequest(\"An email claim is required for JIT provisioning when no userIdentifier is provided.\");","typeGuard":null,"tryCatchPattern":"try { await CreateUserAndOrgUserConditionallyAsync(provider, providerUserId, claims, userIdentifier, ssoConfigData); }\ncatch (Exception ex) when (ex.Message.Contains(\"CannotFindEmailClaim\"))\n{ /* instruct admin to configure email claim mapping in the IdP */ }","preventionTips":["Ensure the IdP emits an email claim (email, mail, or configured custom type).","Map the IdP's email attribute name in the SSO config's additional email claim types.","For providers where providerUserId is email-like, confirm it contains '@'."],"tags":["sso","authentication","claims","email","provisioning","jit","configuration"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}