using System.Security.Claims; using Bit.Core.AdminConsole.Entities; using Bit.Core.Auth.Enums; using Bit.Core.Auth.Models; 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); /// /// Used for both email two factor and email two factor setup. /// /// user requesting the action /// this controls if what verbiage is shown in the email /// void Task SendTwoFactorEmailAsync(User user, bool authentication = true); /// /// Calls the same email implementation but instead it sends the token to the account email not the /// email set up for two-factor, since in practice they can be different. /// /// user attepting to login with a new device /// void Task SendNewDeviceVerificationEmailAsync(User user); Task VerifyTwoFactorEmailAsync(User user, string token); 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 ChangeKdfAsync(User user, string masterPassword, string newMasterPassword, string key, KdfType kdf, int kdfIterations, int? kdfMemory, int? kdfParallelism); 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. /// /// user being acted on /// true if they can access premium; false otherwise. Task CanAccessPremium(ITwoFactorProvidersUser user); Task HasPremiumFromOrganization(ITwoFactorProvidersUser 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); Task ResendNewDeviceVerificationEmail(string email, string secret); /// /// 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); [Obsolete("To be removed when the feature flag pm-17128-recovery-code-login is removed PM-18175.")] Task RecoverTwoFactorAsync(string email, string masterPassword, string recoveryCode); /// /// 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); }