public async Task <ResultFlow <string> > GetJwtToken(string email, string password, string audience) { try { var encryptedPassword = _sha256Utility.Encrypt(password); email = email.ToLower(); var authenticateResultFlow = await _apiUserRepository.Authenticate(email, encryptedPassword); if (authenticateResultFlow.IsSuccess() && authenticateResultFlow.Result == null) { return(ResultFlowFactory.Exception <string>("Invalid credentials")); } var apiUser = authenticateResultFlow.Result; var token = _jwtUtility.EncodeJwt( Configuration.GetSection("Server:Jwt:SecretKey").Value, audience, apiUser.Id.ToString(), apiUser.ApiRole.Id.ToString(), apiUser.Email, Convert.ToInt32(Configuration.GetSection("Server:Jwt:DaysToExpire").Value) ); return(ResultFlowFactory.Success <string>(token.RawData)); } catch { throw; } }
public async Task <ResultFlow <ApiUserEntity> > Read(ApiUserEntity model) { try { var readResultFlow = await _apiUserLogic.Read(model); if (readResultFlow.IsException()) { return(ResultFlowFactory.Exception <ApiUserEntity>(readResultFlow.Message)); } return(ResultFlowFactory.Success <ApiUserEntity>(readResultFlow.Result)); } catch { throw; } }
public async Task <ResultFlow <string> > Authenticate(string email, string password, string audience) { try { var getJwtTokenResultFlow = await _apiUserLogic.GetJwtToken(email, password, audience); if (getJwtTokenResultFlow.IsException()) { return(ResultFlowFactory.Exception <string>(getJwtTokenResultFlow.Message)); } return(ResultFlowFactory.Success <string>(getJwtTokenResultFlow.Result)); } catch { throw; } }
public async Task <ResultFlow <ApiUserEntity> > Read(ApiUserEntity model) { try { var readResultFlow = await _apiUserRepository.Read(model); if (readResultFlow.IsSuccess() && readResultFlow.Result == null) { return(ResultFlowFactory.Exception <ApiUserEntity>("Api user not found")); } return(ResultFlowFactory.Success <ApiUserEntity>(readResultFlow.Result)); } catch { throw; } }
public async Task <ResultFlow <IEnumerable <ApiResourceRouteEntity> > > List(QueryParamValueObject <ApiResourceRouteEntity> model) { try { var listResultFlow = await _apiResourceRouteRepository.List(model); if (listResultFlow.IsException()) { return(ResultFlowFactory.Exception <IEnumerable <ApiResourceRouteEntity> >(listResultFlow.Message)); } return(ResultFlowFactory.Success <IEnumerable <ApiResourceRouteEntity> >(listResultFlow.Result)); } catch { throw; } }