bitwarden/server · error · BadRequestException

User invalid.

Error message

User invalid.

What it means

Thrown inside AcceptUserAsync when _providerUserRepository.GetByIdAsync(providerUserId) returns null — no ProviderUser exists for that Id. The invite acceptance requires a valid ProviderUser record. BadRequestException (HTTP 400).

Source

Thrown at bitwarden_license/src/Commercial.Core/AdminConsole/Services/ProviderService.cs:250

            if (providerUser.Status != ProviderUserStatusType.Invited || providerUser.ProviderId != invite.ProviderId)
            {
                result.Add(Tuple.Create(providerUser, "User invalid."));
                continue;
            }

            await SendInviteAsync(providerUser, provider);
            result.Add(Tuple.Create(providerUser, ""));
        }

        return result;
    }

    public async Task<ProviderUser> AcceptUserAsync(Guid providerUserId, User user, string token)
    {
        var providerUser = await _providerUserRepository.GetByIdAsync(providerUserId);
        if (providerUser == null)
        {
            throw new BadRequestException("User invalid.");
        }

        if (providerUser.Status != ProviderUserStatusType.Invited)
        {
            throw new BadRequestException("Already accepted.");
        }

        if (!CoreHelpers.TokenIsValid("ProviderUserInvite", _dataProtector, token, user.Email, providerUser.Id,
            _globalSettings.OrganizationInviteExpirationHours))
        {
            throw new BadRequestException("Invalid token.");
        }

        if (string.IsNullOrWhiteSpace(providerUser.Email) ||
            !providerUser.Email.Equals(user.Email, StringComparison.InvariantCultureIgnoreCase))
        {
            throw new BadRequestException("User email does not match invite.");
        }

View on GitHub (pinned to e93b962371)

Solutions

  1. Verify the ProviderUser exists (GetByIdAsync) before accepting.
  2. Re-issue the invite if it was revoked.
  3. Ensure the providerUserId comes from a current invite link, not a stale one.
Defensive patterns

Strategy: validation

Validate before calling

var providerUser = await _providerUserRepository.GetByIdAsync(providerUserId);
if (providerUser == null)
    throw new InvalidOperationException("ProviderUser invite not found or was revoked.");

Try / catch

try { await _providerService.AcceptUserAsync(providerUserId, user, token); }
catch (BadRequestException ex) when (ex.Message == "User invalid.")
{ /* invite missing — request a new one */ }

Prevention

When it happens

Trigger: Accepting an invite with a providerUserId that was deleted, already consumed, or fabricated.

Common situations: Invite revoked before acceptance; expired/old invite link; Id mismatch in test data; concurrent revocation.

Related errors


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