private IPrincipal ValidateSessionApiKey(string authToken, Customer customer) { if (string.IsNullOrEmpty(authToken)) { return(null); } var apiToken = _apiSessionTokenService.Details(authToken, customer.Id); if (apiToken != null) { return(new GenericPrincipal(new GenericIdentity(apiToken.Id.ToString(), Constants.ApiSessionKeySchemeName), null)); } return(null); }
public void ValidateSecurityAnswer(ValidateSecurityAnswerModel model) { if (!ModelState.IsValid) { throw new ModelException(ModelState); } var apiToken = _apiSessionTokenService.Details(Guid.Parse(User.Identity.Name)); var user = apiToken.User; var question = user.GetSecurityQuestion(apiToken.SecurityQuestionId); if (!question.ValidateAnswer(model.Answer)) { throw new ApiException(ApiException.Errors.Auth.IncorrectSecurityAnswer); } _apiSessionTokenService.UpdateQuestionAnswered(apiToken.Id); }