private ConsentDto CreateConsentViewModel(
            ConsentInputDto model,
            string returnUrl,
            AuthorizationRequest request,
            Client client,
            Resources resources)
        {
            var vm = new ConsentDto
            {
                RememberConsent = model?.RememberConsent ?? true,
                ScopesConsented = model?.ScopesConsented ?? Enumerable.Empty <string>(),

                ReturnUrl = returnUrl,

                ClientName           = client.ClientName ?? client.ClientId,
                ClientUrl            = client.ClientUri,
                ClientLogoUrl        = client.LogoUri,
                AllowRememberConsent = client.AllowRememberConsent
            };

            vm.IdentityScopes = resources.IdentityResources.Select(x => CreateScopeViewModel(x, vm.ScopesConsented.Contains(x.Name) || model == null)).ToArray();
            vm.ResourceScopes = resources.ApiResources.SelectMany(x => x.Scopes).Select(x => CreateScopeViewModel(x, vm.ScopesConsented.Contains(x.Name) || model == null)).ToArray();
            if (ConsentOptions.EnableOfflineAccess && resources.OfflineAccess)
            {
                vm.ResourceScopes = vm.ResourceScopes.Union(new ScopeDto[] {
                    GetOfflineAccessScope(vm.ScopesConsented.Contains(IdentityServer4.IdentityServerConstants.StandardScopes.OfflineAccess) || model == null)
                });
            }

            return(vm);
        }
        public async Task <IdentityRightWayResponseBase <ConsentDto> > Handle(GetConsentQuery requestModel, CancellationToken cancellationToken)
        {
            ConsentInputDto model   = null;
            var             request = await _interaction.GetAuthorizationContextAsync(requestModel.ReturnUrl);

            if (request != null)
            {
                var client = await _clientStore.FindEnabledClientByIdAsync(request.ClientId);

                if (client != null)
                {
                    var resources = await _resourceStore.FindEnabledResourcesByScopeAsync(request.ScopesRequested);

                    if (resources != null && (resources.IdentityResources.Any() || resources.ApiResources.Any()))
                    {
                        return(new IdentityRightWayResponseBase <ConsentDto> {
                            IsValid = true, Payload = CreateConsentViewModel(model, requestModel.ReturnUrl, request, client, resources)
                        });
                    }
                    else
                    {
                        _logger.LogError("No scopes matching: {0}", request.ScopesRequested.Aggregate((x, y) => x + ", " + y));
                    }
                }
                else
                {
                    _logger.LogError("Invalid client id: {0}", request.ClientId);
                }
            }
            else
            {
                _logger.LogError("No consent request matching request: {0}", requestModel.ReturnUrl);
            }

            return(null);
        }