I'm using Devise 1.0.7 on rails 2.3.5
Very confused as to how to add new strategy. Here's what I've done
thus far.
Created file in my lib directory with strategy:
require 'devise/strategies/base'
module FbAuthenticatable #:nodoc:
module Strategies #:nodoc:
class FbAuthenticatable < ::Devise::Strategies::Base
def valid?
true
end
def authenticate!
u = User.find_by_fb_uid(params[:fb_uid])
if u
success!(u)
else
fail!('Could not match your Facebook ID with any existing
user.')
end
end
end
end
end
Warden::Strategies.add(:fb_authenticatable,
FbAuthenticatable::Strategies::FbAuthenticatable)
I've loaded that through an initializer.
Now, here is where I'm stuck. For various reasons, I have to use my
own controller for signing in (mainly because I have to talk to grab
info from the cookie and then talk to the FB API to grab additional
information). So I just created a new controller and copy and pasted
the sessions code for the create method in the sessions controller.
class FbController < ApplicationController
before_filter :current_facebook_user
def sign_in
current_facebook_user.fetch
params[:fb_uid] =
current_facebook_user.id
resource = warden.authenticate!(:scope => resource_name, :recall
=> "new")
set_flash_message :notice, :signed_in
sign_in_and_redirect(resource_name, resource)
end
end
So, my questions are:
1. Is this the right tact to take so far?
2. If so, how do I set the resource name (I'm having a hard time
getting my head around scoping and what and why to set things in the
devise config)?
I can't help but think there's a more elegant way of doing this, but I
can't seem to figure out how...