Skip to content

eliotsykes/authlogic_facebook_connect

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 

Repository files navigation

Help make these instructions better, submit your improvements via github.

Install and use

1. Install facebooker as gem or plugin

You can install facebooker as a gem or as a plugin.

If you want to install facebooker as a gem

$ sudo gem install facebooker

Make your application dependent on the facebooker gem

config.gem "facebooker"

If you want to install facebooker as a plugin

$ script/plugin install git://github.com/mmangino/facebooker.git

Once you’ve installed facebooker gem or plugin====

Run the xd_receiver generator to create the cross domain scripting bridge to make it possible for your application to communicate with facebook

$ script/generate xd_receiver

Copy the template facebooker.yml from the facebooker gem source to your rails app at config/facebooker.yml.

Next create a facebook application for your development environment at www.facebook.com/developers/createapp.php

Once you’ve created your Facebook app, you will be shown an api_key and a secret_key. These should be copied into the development section of config/facebooker.yml. In facebooker.yml also set the callback_url to the home page of your development app, e.g. localhost:3000.

Add the following 2 lines to your application(_controller).rb (ApplicationController):

# Facebooker docs recommend this to prevent Facebook TOS violation.
filter_parameter_logging :fb_sig_friends

For more information on the facebooker gem checkout it’s readme github.com/mmangino/facebooker/tree/master

2. Install the Authlogic Facebook Connect plugin

$ script/plugin install git://github.com/kalasjocke/authlogic_facebook_connect.git

This plugin should soon be packed inside a gem.

3. Make some changes to your database

class AddFacebookConnectFieldsToUser < ActiveRecord::Migration
  def self.up
    add_column :users, :name, :string
    add_column :users, :facebook_uid, :integer, :limit => 8
    add_column :users, :facebook_session_key, :string
  end

  def self.down
    remove_column :users, :facebook_session_key
    remove_column :users, :facebook_uid
    remove_column :users, :name
  end
end

4. Make your layout look something like this

The important parts are:

  • The facebook html namespace in the opening html tag

  • The javascript include call, fb_connect_javascript_tag

  • The init_fb_connect call.

    <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns=“www.w3.org/1999/xhtml” xmlns:fb=“www.facebook.com/2008/fbml”> <head>

    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <title>Your awesome facebook connected app</title>
    
    <%= stylesheet_link_tag 'application' %>
    <%= javascript_include_tag :defaults %>

    </head> <body>

    <p style=“color: green”><%= flash %></p>

    <%= fb_connect_javascript_tag %> <%= init_fb_connect “XFBML” %>

    <%= yield %>

    </body> </html>

5. Add the Facebook Connect button to your login form

<%= authlogic_facebook_login_button %>

If the path to create an authlogic session is not mapped to 
the /user_session route then you will need to pass in a :controller option,
e.g.

<%= authlogic_facebook_login_button :controller => 'path_to_create_session' %>

If you are using jquery instead of the default prototype library, then:

<%= authlogic_facebook_login_button :js => :jquery %>

You can also pass in additional options to authlogic_facebook_login_button that
will be passed on to facebooker's fb_login_button method to alter behaviour
and formatting of the button, e.g.:

<%= authlogic_facebook_login_button :size => 'large',
  :length => 'long', :autologoutlink => true, :v => 2 %>

Notes

before_connect hook

If you want to save some user data when connecting to facebook you can define the before_connect hook in your user model. before_connect is called the first time a facebook user authenticates with your application.

This hook is a good place to set values for authlogic required credentials or you can make credentials optional by allowing nulls in the database. See the authlogic example app migration for more on optional credential columns.

The only credential column that is not optional is persistence token. You can ensure this is set in before_connect with reset_persistence_token.

Here is an example implementation of the before_connect hook:

def before_connect(facebook_session)
  self.name = facebook_session.user.name
  # Set required credentials
  reset_persistence_token
end

For more information about what you can get form the facebook_session checkout the Facebooker gem rdoc.

Help make these instructions better, submit your improvements via github.

About

Extension of the Authlogic library to add Facebook Connect support built upon the excellent facebooker gem

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%