Rails and Facebook Connect with mini_fb

| May 13th, 2010 by agerlic

Facebook connect is an easy way to authenticate users.

API seems really complete, and it’s really easy to ask access to all facebook features via a REST API, OAuth and more recently the Graph API.

But Rails gems are outdated : for example rfacebook is really old, and facebooker will throw some xml exceptions for some basic requests.

Furthermore none of them are compatible with rails3.

I was looking for another facebook connect gem, when I found mini_fb a gem without any dependencies (even rails !) using facebook Graph API and OAuth2 for authentication.

It is really complete, easy to use and you can find a project demo here

Part One : How to enable authentication on a Cassandra node

  1. Edit conf/storage.xml
  2. Change

    <Authenticator>
    org.apache.cassandra.auth.AllowAllAuthenticator
    </Authenticator>

    to

    <Authenticator>
    org.apache.cassandra.auth.SimpleAuthenticator
    </Authenticator>
  3. Edit conf/access.properties
  4. Append

    Keyspace=Username
  5. Edit conf/passwd.properties
  6. Append

    Username=Password

    (Password can be either clear or MD5 encrypted)

  7. Edit bin/cassandra.in.sh
  8. Append :

    -Dpasswd.properties=$cassandra_home/conf/passwd.properties \
    -Daccess.properties=$cassandra_home/conf/access.properties"

    If you previously set Password was MD5 encrypted, append :

    -Dpasswd.mode=MD5

You can now restart your Cassandra node and use the command line tool `cassandra-cli’ to ensure this have been taken into consideration.

Note, in opposition to MySQL :

  1. Connection and keyspaces listing can be done without authentication:
  2. ./bin/cassandra-cli -host=127.0.0.1 -port=9160
     >show keyspaces
    Standard1
    
  3. Getters and Setters cannot be used this way: you have to authenticate using:
  4. ./bin/cassandra-cli -host=127.0.0.1 -port=9160 -username Username -password Password -keyspace KeySpace

Part Two : Ruby Cassandra Gem with authentication

To connect to my cassandra node, I use ruby client gem cassandra

However, even if the Thrift API contains a login method (see below), there is no login in cassandra.rb to Authenticate you.

def login(keyspace, auth_request)
  send_login(keyspace, auth_request)
  recv_login()
end

Authentication can be achieved via several ways. One of them, described here under: extending Cassandra class:

require 'rubygems'
gem 'cassandra'
require 'cassandra'

class Cassandra
  def login(username, pwd)
    auth_info = CassandraThrift::AuthenticationRequest.new()
    auth_info.credentials = {'username' => username, 'password' => pwd}
    client.login(@keyspace, auth_info)
  end
end

cc = Cassandra.new("Standard1", "127.0.0.1:9160")
cc.login("myUsername", "myPassword")