Module: Rack::OAuth2::Rails

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

Overview

Rails support.

Adds oauth instance method that returns Rack::OAuth2::Helper, see there for more details.

Adds oauth_required filter method. Use this filter with actions that require authentication, and with actions that require client to have a specific access scope.

Adds oauth setting you can use to configure the module (e.g. setting available scope, see example).

Examples:

config/environment.rb

require "rack/oauth2/rails"

Rails::Initializer.run do |config|
  config.oauth[:scope] = %w{read write}
  config.oauth[:authenticator] = lambda do |username, password|
    User.authenticated username, password
  end
  . . .
end

app/controllers/my_controller.rb

class MyController < ApplicationController

  oauth_required :only=>:show
  oauth_required :only=>:update, :scope=>"write"

  . . .

protected 
  def current_user
    @current_user ||= User.find(oauth.identity) if oauth.authenticated?
  end
end

See Also:

Defined Under Namespace

Modules: Configuration, Filters, Helpers