ruby on rails 4 - How to configure doorkeeper without oauth -
i learning how develop api rails app. trying develop use mobile app. far developed small api of controller. having problem login. using devise user management , rails 4.1.
i watched railscast video doorkeeper implementation . in video used doorkeeper oauth gem. want implement without oauth. how can that?
so far added doorkeeper gem
, in initialize
folder added doorkeeper.rb
following code
doorkeeper.configure resource_owner_authenticator user.find_by_id(session[:current_user_id]) || redirect_to(login_url) end end
and added before_action :doorkeeper_authorize!
in controller
module api module v1 class coursescontroller < applicationcontroller #before_action :doorkeeper_authorize! before_action :set_course, only: [:show, :edit, :update, :destroy] respond_to :json # /courses/1 # /courses/1.json def show @course = course.find(params[:id]) @assignment = @course.assignments respond_with @assignment end end end end
now when hit link on browser
http://localhost:3000/api/v1/courses/5
i no output in console this
filter chain halted :doorkeeper_authorize! rendered or redirected completed 401 unauthorized
and if comment out before_action :doorkeeper_authorize!
in controller json output expected data. how can configure doorkeeper , make work?
first things first: need authenticate user api first, after receive oauth access token. there's multiple flows (= ways of getting access token) listed in rfc 6749. use said access token in subsequent requests request resource. put token in authorization header of request.
right you're counting on session variable session[:user_id], doesn't exist, leads :doorkeeper_authorize!
redirecting, ending chain, resulting in 401 unauthorized response doorkeeper.
if, in case, wish authenticate user's credentials, per section 1.3.4, need configure doorkeeper that. see wiki.
i hope gets going.
Comments
Post a Comment