public async Task AddEnabledTwoStepAuthenticationAsync(int userId, string auth) { using (UserDefinitionDataProvider userDP = new UserDefinitionDataProvider()) { UserDefinition user = await userDP.GetItemByUserIdAsync(userId); if (user == null) { throw new InternalError($"Unexpected error in {nameof(AddEnabledTwoStepAuthenticationAsync)} - no user found"); } TwoStepDefinition authDef = new DataProvider.TwoStepDefinition { Name = auth }; if (!user.EnabledTwoStepAuthentications.Contains(authDef, new TwoStepDefinitionComparer())) { user.EnabledTwoStepAuthentications.Add(authDef); UpdateStatusEnum status = await userDP.UpdateItemAsync(user); if (status != UpdateStatusEnum.OK) { throw new InternalError($"Unexpected status {status} updating user account in {nameof(AddEnabledTwoStepAuthenticationAsync)}"); } Manager.Need2FAState = null;//reevaluate now that user has enabled a two-step authentication } } }
public async Task <bool> HasEnabledTwoStepAuthenticationAsync(int userId, string auth) { using (UserDefinitionDataProvider userDP = new UserDefinitionDataProvider()) { UserDefinition user = await userDP.GetItemByUserIdAsync(userId); if (user == null) { return(false); } TwoStepDefinition authDef = new DataProvider.TwoStepDefinition { Name = auth }; return(user.EnabledTwoStepAuthentications.Contains(authDef, new TwoStepDefinitionComparer())); } }