예제 #1
0
        public async Task <PagingModel <ChatUserModel> > GetContactsAsync(string nameFilter, int pageNumber, int pageSize)
        {
            var request = new GetMembersRequest(_chatConfig.ApiUrl, nameFilter, pageNumber, pageSize);

            var result = await _httpClient.TrySendAndDeserializeAsync <QueryResult <MemberSummaryResponse> >(request,
                                                                                                             _logger).ConfigureAwait(false);

            return(result == null
                ? null
                : Mapper.PagedDtoToPagingModel(result, Mapper.DtoToChatUser));
        }
예제 #2
0
        internal Task <LoginResultDto> LogInAsync(string email, string password)
        {
            var dto = new LoginDto
            {
                Email    = email,
                Password = password
            };
            var request = new LoginRequest(dto, _authConfig);

            return(_restHttpClient.TrySendAndDeserializeAsync <LoginResultDto>(request, _logger));
        }
예제 #3
0
        protected override async Task <RefreshTokenStatus> TryRefreshToken(IRestHttpClient restHttpClient)
        {
            var attemptCount = 3;
            var result       = RefreshTokenStatus.Error;
            var loginResult  = default(LoginResultDto);

            while (attemptCount > 0 && result != RefreshTokenStatus.Refreshed)
            {
                try
                {
                    _logger.Info("Try refresh access token...");
                    var request = new RefreshTokenRequest(_accountService.RefreshToken, _authConfig);
                    loginResult = await restHttpClient
                                  .TrySendAndDeserializeAsync <LoginResultDto>(request, _logger)
                                  .ConfigureAwait(false);

                    if (loginResult != null)
                    {
                        result = RefreshTokenStatus.Refreshed;
                    }

                    _logger.Info("Access token refreshed");
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);
                }
                finally
                {
                    attemptCount--;
                }
            }

            if (loginResult != null)
            {
                try
                {
                    _accountService.ResetTokens(loginResult.AccessToken, loginResult.RefreshToken);
                    _logger.Info("Access token saved");
                }
                catch (Exception)
                {
                    _logger.Error("Access token is not saved");
                }
            }

            if (result == RefreshTokenStatus.Error)
            {
                //TODO: logout
            }

            return(result);
        }