Question

Sorry if this is a noob question on oauth

I've implemented an oauth2 API with devise+doorkeeper based on the examples here: https://doorkeeper-provider.herokuapp.com/ and here: https://github.com/applicake/doorkeeper-devise-client

I want to be able to provide an API endpoint that returns a list of deals that's paginatable, the code is the following:

module Api::V1
  class DealsController < ApiController
    doorkeeper_for :index
    doorkeeper_for :create, :scopes => [:write]

    respond_to :json

    def index
      if params[:page].nil?
        page = 1
      else
        page = params[:page].to_i
      end
      respond_with Deal.page(page).order("published DESC")
    end

    def create
      respond_with 'api_v1', Deal.create!(params[:deal])
    end
  end
end

However, on the client side, I cannot pass a page param with something like this: /explore/deals.json?page=3

The page param is not seen in the provider for some reason. Can someone help me please?

Was it helpful?

Solution

I realized the problem is in the api_controller of doorkeeper-devise-client

The page param isn't passed correctly. Making the following change fixes the problem:

class ApiController < ApplicationController
  respond_to :json

  def explore
    api_call = params[:api]
    if !params[:page].nil?
      api_call << "/?page=#{params[:page]}"  
    end

    @json = doorkeeper_access_token.get("api/v1/#{api_call}").parsed
    respond_with @json
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top