OmniAuth extension for easy Facebook login integration
Ruby
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.document
.gitignore
LICENSE.txt
README.rdoc
Rakefile
VERSION
oa-facebook.gemspec

README.rdoc

oa-facebook

Extension to OmniAuth, that brings cool view helper. All you have to do now is simply add one line to your template and you will see Facebook login button!

Installation

gem install oa-facebook

Add to environment.rb

config.gem 'oa-facebook'

Add to config/initializers/omniauth.rb:

#for rails3 projects
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, <App ID>, <App Secret>
end
#for rails2 projects
ActionController::Dispatcher.middleware.use "OmniAuth::Builder" do
  provider :facebook, <App ID>, <App Secret>
end

If omniauth routes doesn't exist add them to config/routes.rb (e.g.):

#rails3
match '/auth/:provider/callback' => 'authentications#create'
#rails2
map.auth_callback '/auth/:provider/callback', :controller => :authentications :action => :create

Then use special helper method for generate Facebook button:

<%= facebook_login_button %>

Also you can pass a Hash as a parameter. Keys are:

  • native – render button with FBML or render image, true by default;

  • title – text in FBML button, or alt parameter of image tag, default is Login with Facebook;

  • image – address of an image, if native is set to false, default is ;

  • perms - permissions list. default is email,offline_access.

Finally you can right something like this:

<%= facebook_login_button(:native => false, :title => "Login from Facebook", :perms => "email, user_groups, user_events") %>

After click on the button popup window with mail.ru auth-page will be shown and after user was signed in and added permissions for the application then user-data will be transfered with POST-request to /auth/mailru/callback path. In action with this path you can use params from request which body look like:

{
  'uid' => '100000882795341', # user Id from Facebook
  'provider' => 'facebook',
  'user_info' => {
    'nick' => 'igor.alexandrov',
    'email' => 'igor.alexandrov@gmail.com',
    'name' => 'Igor Alexandrov',
    'first_name' => 'Igor',
    'last_name' => 'Alexandrov',
    'image' => 'http://graph.facebook.com/100000882795341/picture?type=square',
    'urls' => {
      'Facebook' => 'http://www.facebook.com/igor.alexandrov'
    },
    'location' => 'Tver'
  }
}

Links

OmniAuth: github.com/intridea/omniauth

Contributing to oa-facebook

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright © 2011 Igor Alexandrov. See LICENSE.txt for further details.