I am wondering how to implement a custom authentication strategy with devise using devise :token_authenticable
.
I already found instructions on how to do it with a model using devise :database_authenticatable
which is covered here.
The model im trying to authenticate is named Pupil
.
So here is my current strategy (located in config/initializers/custom_auth.rb
):
Warden::Strategies.add(:auth_pupil_strategy) do
# missing valid? method indicates this strategy is always applied
def authenticate!
fail!("YOU SHALL NOT PASS!")
end
end
And in my config/initializers/devise.rb
(also tried it without the :scope => :pupil
):
config.warden do |manager|
manager.default_strategies(:scope => :pupil).unshift :auth_pupil_strategy
end
So this should lead to the user not beeing able to login, but somehow this strategy is not applied when switching from devise :database_authenticatable
to devise :token_authenticable
.
Maybe I'm just missing the right :scope
here.
Now, here's the strange thing: Whenever a user enters an invalid token my strategy is invoked and "YOU SHALL NOT PASS!" is returned. However when the correct token is supplied, the user can log in just fine.