ruby on rails - How to add a custom header to doorkeper token response -


the project i'm working on requires me add custom headers based on generated response body responses generated app. works fine after_action in application controller, need add custom header token responses generated doorkeeper. setting base_controller applicationcontroller in doorkeeper configuration, did not cause after_actions called. there possible workarounds?

turns out takes 1 define custom doorkeeper::tokenscontroller class , add filter it.

app/controllers/access_tokens_controller.rb:

class accesstokenscontroller < doorkeeper::tokenscontroller   include abstractcontroller::callbacks   after_action :add_signature_to_response, only: [:create]    def add_signature_to_response     application = strategy.client.application     # ...     # response_based_on_application = ...     # ...      response.headers['custom-header'] = response_based_on_application   end end 

next 1 needs register controller in doorkeeper configuration in config/initializers/doorkeeper.rb

# ... use_doorkeeper scope: 'oauth2'   # ...   controllers tokens: 'access_tokens'   # ... end # ... 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -