adding a warden custom strategy to Devise

1,160 views
Skip to first unread message

Erwin

unread,
Aug 20, 2013, 5:30:51 AM8/20/13
to plataforma...@googlegroups.com
I defined a warden custom strategy in an initializer  vertex.rb

  config.warden do |manager|
     manager.intercept_401 = false
     manager.default_strategies(:scope => :user).unshift :vertex
 end

and it's running fine but I would like to run it after standard Devise authentication and only if this one fails...
is there any way  to define that in my devise initializer ?

thanks

Erwin

unread,
Aug 20, 2013, 5:59:27 AM8/20/13
to plataforma...@googlegroups.com
should I add a

env['warden'].authenticate(:database_authenticable, :rememberable, :token_authenticable, :vertex)
to have a cascading process ?

Erwin

unread,
Aug 20, 2013, 10:30:20 AM8/20/13
to plataforma...@googlegroups.com
I found a solution for the remote_authentification as per post at http://4trabes.com/2012/10/31/remote-authentication-with-devise/
and adding :

  require "devise/strategies/remote_authenticable.rb"
 
  config.warden do |manager|
    manager.strategies.add(:remote, Devise::Strategies::RemoteAuthenticatable)
    manager.default_strategies(:scope => :user).unshift :remote
  end

into my devise initializer, I can perform the remote authentication... but as warden accepts cascading strategies ( https://github.com/hassox/warden/wiki/Strategies - using strategies )
how can I stipulate that I want  first :database_authentication and only if it fails the :remote stategy  ??
like  
env['warden'].authenticate(:database_authentificable, :remote)




Le mardi 20 août 2013 11:30:51 UTC+2, Erwin a écrit :

Erwin

unread,
Aug 23, 2013, 2:26:51 AM8/23/13
to plataforma...@googlegroups.com
[SOLVED]
the warden block in devise initializer defines an array of strategies in warden config, however the :remote strategy is listed as first...
        # warden.config[:default_strategies][:user] =>  [:remote, :rememberable, :database_authenticatable]

so  I modified the #createaction  in my users/sessions_controller, to move :remote to the end of the list

    # POST /resource/sign_in
    def create
        warden.config[:default_strategies][:user].push(warden.config[:default_strategies][:user].shift)
        self.resource = warden.authenticate!(auth_options)

now, user authentication starts wit Devise ( :rememberable, :database_authenticable) and if it fails , then a try a given to :remote_authenticable
Reply all
Reply to author
Forward
0 new messages