devise_facebook_open_graph
The goal of this gem is to give Devise the ability to authorize users based if they are connected to Facebook or not. It relays on connection to Facebook set up via the Facebook JavaScript SDK. Maybe devise facebook js sdk connectable should be a better name for this gem ;-)
Warning
I guess I should start with a small warning: Right now, this gem is kinda a fast-written prototype for me. Don't expect anything to work ;-) ..Even though committed code do work for me in my Rails 3 beta 3 application :-) I have managed to authenticate users which sign in via Facebook's JavaScript SDK and I guess this code might be useful to others too. Sadly, I haven't written any specs while writing this code. This is not 100% complete code either. For instance, creating users based on facebook connection is not finished, although I guess it will be soon.
How to get started
Set up gem dependency in your Gemfile
gem 'devise_facebook_open_graph'
Get facebook credentials, add ids and keys to a configuration file
If you haven't done so already, create a facebook application so you'll acquire an application id, secret and an API key. You can register applications here: http://www.facebook.com/developers/.
DeviseFacebookOpenGraph provides a class for easy access to configuration values. These are by default read from Rails.root/config/facebook.yml which should look something like this:
production: &production
application_id: ""
api_key: ""
application_secret: ""
development:
<<: *production
Configure your model to use facebook_open_graph_authenticatable
class User < ActiveRecord::Base devise :database_authenticatable, :facebook_open_graph_authenticatable # etc..
Add facebook user id column to your users table
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
# ...other definitions here..
t.facebook_open_graph_authenticatable
end
add_index :users, User.facebook_uid_field, :unique => true
end
def self.down
drop_table :users
end
end
Add Facebook SDK initializer HTML and JavaScript
The next thing we'll be doing are adding Facebook's JavaScript SDK and initialize it. This should be added at the bottom of the page, before