Sha256: 8c0f9e92c816ba76659f1788f0287fcd7c9b89cb625b012c8f4a937320e3ca93

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'action_controller'

# :nodoc: namespace
module AuthpwnRails

# :nodoc: namespace
module FacebookToken

# Mixed into ActiveController::Base
module ControllerMixin
  def self.included(base)
    base.send :extend, ControllerClassMethods
  end
end

# Methods here become ActiveController::Base class methods.
module ControllerClassMethods  
  # Authenticates users via Facebook OAuth2, using fbgraph_rails.
  #
  # The User model class must implement for_facebook_token. The controller
  # should obtain the Facebook token, using probes_facebook_access_token or
  # requires_facebook_access_token.
  def authenticates_using_facebook(options = {})
    include ControllerInstanceMethods
    before_filter :authenticate_using_facebook_access_token, options
  end
end

# Included in controllers that call authenticates_using_facebook.
module ControllerInstanceMethods
  def authenticate_using_facebook_access_token
    return true if current_user
    if access_token = current_facebook_access_token
      self.current_user = User.for_facebook_token access_token
    end
  end
  private :authenticate_using_facebook_access_token
end

ActionController::Base.send :include, ControllerMixin

end  # namespace AuthpwnRails::FacebookToken

end  # namespace AuthpwnRails

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authpwn_rails-0.3.0 lib/authpwn_rails/facebook_token.rb