// FIXME: Update this file to be null safe and then delete the line below #nullable disable using System.Security.Claims; using Bit.Core.AdminConsole.Entities; using Bit.Core.Auth.Enums; using Bit.Core.Billing.Models.Business; using Bit.Core.Entities; using Bit.Core.Enums; using Bit.Core.Models.Business; using Fido2NetLib; using Microsoft.AspNetCore.Identity; namespace Bit.Core.Services; public interface IUserService { Guid? GetProperUserId(ClaimsPrincipal principal); Task GetUserByIdAsync(string userId); Task GetUserByIdAsync(Guid userId); Task GetUserByPrincipalAsync(ClaimsPrincipal principal); Task GetAccountRevisionDateByIdAsync(Guid userId); Task SaveUserAsync(User user, bool push = false); Task CreateUserAsync(User user); Task CreateUserAsync(User user, string masterPasswordHash); Task SendMasterPasswordHintAsync(string email); Task StartWebAuthnRegistrationAsync(User user); Task DeleteWebAuthnKeyAsync(User user, int id); Task CompleteWebAuthRegistrationAsync(User user, int value, string name, AuthenticatorAttestationRawResponse attestationResponse); Task SendEmailVerificationAsync(User user); Task ConfirmEmailAsync(User user, string token); Task InitiateEmailChangeAsync(User user, string newEmail); Task ChangeEmailAsync(User user, string masterPassword, string newEmail, string newMasterPassword, string token, string key); Task ChangePasswordAsync(User user, string masterPassword, string newMasterPassword, string passwordHint, string key); Task SetKeyConnectorKeyAsync(User user, string key, string orgIdentifier); Task ConvertToKeyConnectorAsync(User user); Task AdminResetPasswordAsync(OrganizationUserType type, Guid orgId, Guid id, string newMasterPassword, string key); Task UpdateTempPasswordAsync(User user, string newMasterPassword, string key, string hint); Task RefreshSecurityStampAsync(User user, string masterPasswordHash); Task UpdateTwoFactorProviderAsync(User user, TwoFactorProviderType type, bool setEnabled = true, bool logEvent = true); Task DisableTwoFactorProviderAsync(User user, TwoFactorProviderType type); Task DeleteAsync(User user); Task DeleteAsync(User user, string token); Task SendDeleteConfirmationAsync(string email); Task> SignUpPremiumAsync(User user, string paymentToken, PaymentMethodType paymentMethodType, short additionalStorageGb, UserLicense license, TaxInfo taxInfo); Task UpdateLicenseAsync(User user, UserLicense license); Task AdjustStorageAsync(User user, short storageAdjustmentGb); Task ReplacePaymentMethodAsync(User user, string paymentToken, PaymentMethodType paymentMethodType, TaxInfo taxInfo); Task CancelPremiumAsync(User user, bool? endOfPeriod = null); Task ReinstatePremiumAsync(User user); Task EnablePremiumAsync(Guid userId, DateTime? expirationDate); Task DisablePremiumAsync(Guid userId, DateTime? expirationDate); Task UpdatePremiumExpirationAsync(Guid userId, DateTime? expirationDate); Task GenerateLicenseAsync(User user, SubscriptionInfo subscriptionInfo = null, int? version = null); Task CheckPasswordAsync(User user, string password); /// /// Checks if the user has access to premium features, either through a personal subscription or through an organization. /// /// This is the preferred way to definitively know if a user has access to premium features when you already have the User object. /// /// user being acted on /// true if they can access premium; false otherwise. Task CanAccessPremium(User user); /// /// Checks if the user has inherited access to premium features through an organization. /// /// This primarily serves as a means to communicate to the client when a user has inherited their premium status /// through an organization. Feature gating logic probably should not be behind this check. /// /// user being acted on /// true if they can access premium because of organization membership; false otherwise. [Obsolete("Use IHasPremiumAccessQuery.HasPremiumFromOrganizationAsync instead. This method will be removed in a future version.")] Task HasPremiumFromOrganization(User user); Task GenerateSignInTokenAsync(User user, string purpose); Task UpdatePasswordHash(User user, string newPassword, bool validatePassword = true, bool refreshStamp = true); Task RotateApiKeyAsync(User user); string GetUserName(ClaimsPrincipal principal); Task SendOTPAsync(User user); Task VerifyOTPAsync(User user, string token); Task VerifySecretAsync(User user, string secret, bool isSettingMFA = false); /// /// We use this method to check if the user has an active new device verification bypass /// /// self /// returns true if the value is found in the cache Task ActiveNewDeviceVerificationException(Guid userId); /// /// We use this method to toggle the new device verification bypass /// /// Id of user bypassing new device verification Task ToggleNewDeviceVerificationException(Guid userId); void SetTwoFactorProvider(User user, TwoFactorProviderType type, bool setEnabled = true); /// /// This method is used by the TwoFactorAuthenticationValidator to recover two /// factor for a user. This allows users to be logged in after a successful recovery /// attempt. /// /// This method logs the event, sends an email to the user, and removes two factor /// providers on the user account. This means that a user will have to accomplish /// new device verification on their account on new logins, if it is enabled for their user. /// /// recovery code associated with the user logging in /// The user to refresh the 2FA and Recovery Code on. /// true if the recovery code is valid; false otherwise Task RecoverTwoFactorAsync(User user, string recoveryCode); /// /// Returns true if the user is a legacy user. Legacy users use their master key as their /// encryption key. We force these users to the web to migrate their encryption scheme. /// Task IsLegacyUser(string userId); /// /// Indicates if the user is managed by any organization. /// /// /// A user is considered managed by an organization if their email domain matches one of the /// verified domains of that organization, and the user is a member of it. /// The organization must be enabled and able to have verified domains. /// Task IsClaimedByAnyOrganizationAsync(Guid userId); /// /// Verify whether the new email domain meets the requirements for managed users. /// /// /// IdentityResult /// Task ValidateClaimedUserDomainAsync(User user, string newEmail); /// /// Gets the organizations that manage the user. /// /// Task> GetOrganizationsClaimingUserAsync(Guid userId); }