title: Custom Authentication Strategy for Devise Using :token_authenticable
body: <p>I am wondering how to implement a custom authentication strategy with devise using <code>devise :token_authenticable</code>.</p>
  
  <p>I already found instructions on how to do it with a model using <code>devise :database_authenticatable</code> which is covered <a href="https://stackoverflow.com/questions/4223083/custom-authentication-strategy-for-devise">here</a>.</p>
  
  <p>The model im trying to authenticate is named <code>Pupil</code>.
  So here is my current strategy (located in <code>config/initializers/custom_auth.rb</code>):    </p>
  
  <pre><code>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
  </code></pre>
  
  <p>And in my <code>config/initializers/devise.rb</code> (also tried it without the <code>:scope =&gt; :pupil</code>):</p>
  
  <pre><code>config.warden do |manager|
    manager.default_strategies(:scope =&gt; :pupil).unshift :auth_pupil_strategy
  end
  </code></pre>
  
  <p>So this should lead to the user not beeing able to login, but somehow this strategy is not applied when switching from <code>devise :database_authenticatable</code> to <code>devise :token_authenticable</code>.</p>
  
  <p>Maybe I'm just missing the right <code>:scope</code> here.</p>
  
  <p>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.</p>