Ask A Question

Notifications

You’re not receiving notifications from this thread.

Doorkeeper and Authorization Code Flow

brbernardo90 asked in Gems / Libraries

Hi! I'm learning rails building an CRUD app with authorization. I want to autorizate http requests.

I can't generate the authoriation code, when send the url with client_id and callback url, the page is redirect to the root of my application. The same behavior happens when I click in the button "authorizate" in the application painel (see the image).

Codes:

doorkeeper.rb

Doorkeeper.configure do
  orm :active_record

  resource_owner_authenticator do
      User.find_by_id(session[:user_id]) || redirect_to(new_user_session_url)
  end

  admin_authenticator do
     if current_user
       current_user
     else
       session[:user_return_to] = request.fullpath
       redirect_to(new_user_session_url)
     end
  end

  native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
  grant_flows %w[authorization_code client_credentials]
end

routes.rb

Rails.application.routes.draw do
  use_doorkeeper
  devise_for :users
  resources :eventos
  get 'admin/index'
  root 'eventos#index'
  mount API::Base, at: "/"
end

application painel

Reply
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 74,071+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.