public async Task <IActionResult> ActiveTokensData(Guid id, int skip, int take)
        {
            var integrationUid = id;

            if (integrationUid.IsEmptyGuid())
            {
                return(Forbid());
            }

            var request = new IntegrationActiveTokenReadListRequest(CurrentUser.Id, integrationUid);

            SetPaging(skip, take, request);

            var response = await _integrationService.GetActiveTokensOfIntegration(request);

            if (response.Status.IsNotSuccess)
            {
                return(NotFound());
            }

            var result = new DataResult();

            result.AddHeaders("integration_client_uid", "access_token", "ip", "created_at", "expires_at", "");

            for (var i = 0; i < response.Items.Count; i++)
            {
                var item          = response.Items[i];
                var stringBuilder = new StringBuilder();
                stringBuilder.Append($"{item.Uid}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{item.IntegrationClientUid}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{item.AccessToken}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{item.IP}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{GetDateTimeAsString(item.ExpiresAt)}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{GetDateTimeAsString(item.CreatedAt)}{DataResult.SEPARATOR}");

                result.Data.Add(stringBuilder.ToString());
            }

            result.PagingInfo      = response.PagingInfo;
            result.PagingInfo.Type = PagingInfo.PAGE_NUMBERS;

            return(Json(result));
        }
Exemple #2
0
        public async Task <IntegrationActiveTokenReadListResponse> GetActiveTokensOfIntegration(IntegrationActiveTokenReadListRequest request)
        {
            var response = new IntegrationActiveTokenReadListResponse();

            var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId);

            var now      = DateTime.UtcNow;
            var entities = await _tokenRepository.SelectMany(x => x.IntegrationUid == request.IntegrationUid &&
                                                             x.OrganizationId == currentUser.OrganizationId &&
                                                             x.ExpiresAt > now, request.PagingInfo.Skip, request.PagingInfo.Take, x => x.Id, request.PagingInfo.IsAscending);

            if (entities != null)
            {
                for (var i = 0; i < entities.Count; i++)
                {
                    var entity = entities[i];
                    var dto    = _tokenFactory.CreateDtoFromEntity(entity);
                    response.Items.Add(dto);
                }
            }

            response.Status = ResponseStatus.Success;
            return(response);
        }