Devise/Warden custom single-sign-on strategy

1.3k views Asked by At

I want my SSO custom strategy to be the only strategy that devise uses. I'm doing this by:

config.warden do |manager|
  manager.default_strategies :my_sso_strategy
end

This is where I get stuck. I want to invoke the strategy, and I thought this would be done for me by:

app/controllers/devise/sessions_controller.rb

But, it doesn't look like my strategy gets invoked.

I took away the :authenticatable / :database_authenticatable from the devise declaration in my User model thinking that may be causing the problem.
After making the sign-in/out routes manually (because :authenticatable makes them), I get an AbstractController::ActionNotFound error.

At this point I'm at a loss how to continue.

My views should be setup correctly to auto-submit my credentials I get from the SSO application (it worked in authlogic)

Has anyone done something similar to this?

2

There are 2 answers

0
Daniel Huang On

I have seen others use the ":user" scope and noticed you did not have it in your excerpt. Perhaps that is causing the original error.

config.warden do |manager|
  manager.default_strategies(:scope => :user).unshift :fb_database_authenticatable
end
1
radixhound On

I can't say for sure unless you share how you coded the strategy. The simple answer is that you need a valid? method defined to specify when to use the strategy. Since you only want to use one strategy then I would expect your valid method to be like this..

Warden::Strategies.add(:my_sso_strategy) do 
  def valid?
    true
  end 

  def authenticate!
   #do authentication
  end
end