Module: Rack::OAuth2::Rails::Filters

Defined in:
lib/rack/oauth2/rails.rb

Overview

Filter methods available in controller.

Instance Method Summary collapse

Instance Method Details

#oauth_required(options = {}) ⇒ Object

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

:except, and the :scope option.

Parameters:

  • options (Hash) (defaults to: {})

    Accepts before_filter options like :only and



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 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