module Rack::OAuth2::Rails::Filters

Filter methods available in controller.

Public Instance Methods

oauth_required(options = {}) click to toggle source

Adds before filter to require authentication on all the listed paths. Use the :scope option if client must also have access to that scope.

@param [Hash] options Accepts before_filter options like :only and :except, and the :scope option.

# File lib/rack/oauth2/rails.rb, line 74
def oauth_required(options = {})
  if scope = options.delete(:scope)
    before_filter options do |controller|
      if controller.oauth.authenticated?
        if !controller.oauth.scope.include?(scope)
          controller.send :head, controller.oauth.no_scope!(scope)
        end
      else
        controller.send :head, controller.oauth.no_access!
      end
    end
  else
    before_filter :oauth_required, options
  end
end