bitwarden/server · critical · Exception

UserShouldBeFound

Error message

UserShouldBeFound

What it means

Thrown in AccountController.ExternalCallback (line 347) as a null-coalescing throw: possibleSsoLinkedUser is null after both FindUserFromExternalProviderAsync and CreateUserAndOrgUserConditionallyAsync have run. This is an internal invariant violation — the provisioning path is expected to always produce a non-null user.

Source

Thrown at bitwarden_license/src/Sso/Controllers/AccountController.cs:347

                // its own match/no-match split (see SsoAuthnRequiresOrgMembershipException
                // for the two scenarios that converge here).
                await HttpContext.SignOutAsync(
                    AuthenticationSchemes.BitwardenExternalCookieAuthenticationScheme);

                var redirectUrl = SsoRedirectUrlBuilder.BuildLoginRedirectUrl(
                    _globalSettings.BaseServiceUri.VaultWithHash,
                    ex.UserEmail,
                    ex.OrganizationId,
                    ex.OrganizationDisplayName,
                    SsoRedirectUrlBuilder.ErrorCodes.OrgMembershipRequired);

                return Redirect(redirectUrl);
            }
#nullable restore
        }

        User resolvedSsoLinkedUser = possibleSsoLinkedUser
                                              ?? throw new Exception(_i18nService.T("UserShouldBeFound"));

        await PreventOrgUserLoginIfStatusInvalidAsync(organization, provider, orgUser, resolvedSsoLinkedUser);

        // This allows us to collect any additional claims or properties
        // for the specific protocols used and store them in the local auth cookie.
        // this is typically used to store data needed for signout from those protocols.
        var additionalLocalClaims = new List<Claim>();
        var localSignInProps = new AuthenticationProperties
        {
            IsPersistent = true,
            ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(1)
        };
        ProcessLoginCallback(result, additionalLocalClaims, localSignInProps);

        // Issue authentication cookie for user
        await HttpContext.SignInAsync(
            new IdentityServerUser(resolvedSsoLinkedUser.Id.ToString())
            {

View on GitHub (pinned to e93b962371)

Solutions

  1. This is an internal server error — investigate server logs around the SSO callback to find the upstream provisioning failure.
  2. Check CreateUserAndOrgUserConditionallyAsync for any code path that could return without a non-null user.
  3. Verify the user provisioning dependencies (user repository, register command) are healthy.
Defensive patterns

Strategy: try-catch

Try / catch

try { await ExternalCallback(); }
catch (Exception ex) when (ex.Message.Contains("UserShouldBeFound"))
{
    _logger.LogCritical(ex, "SSO provisioning invariant violated — no user resolved");
    return StatusCode(500, "An internal error occurred during SSO login.");
}

Prevention

When it happens

Trigger: After the full provisioning flow, the resolved user reference is still null. This should not happen under normal operation; it indicates a logic gap where neither the existing-user path nor the new-user creation path returned a user.

Common situations: A code change in CreateUserAndOrgUserConditionallyAsync introduced a path that returns without setting resolvedUser; an exception in the provisioning path was swallowed; a race condition deleted the user between provisioning and assignment.

Related errors


AI-assisted analysis of bitwarden/server@e93b962371 (2026-08-13). Data as JSON: /api/errors/4961e9a012324dce. Report an issue: GitHub.