Sha256: 0b53c1dc285f2f7b42304d256f6275405f3eaa7d4070b9df4344838c7939ccb9

Contents?: true

Size: 1.43 KB

Versions: 11

Compression:

Stored size: 1.43 KB

Contents

require 'devise/strategies/base'

module Devise
  module Strategies
    # Strategy for signing in a user, based on a authenticatable token. This works for both params
    # and http. For the former, all you need to do is to pass the params in the URL:
    #
    #   http://myapp.example.com/?user_token=SECRET
    #
    # For HTTP, you can pass the token as username and blank password. Since some clients may require
    # a password, you can pass "X" as password and it will simply be ignored.
    class TokenAuthenticatable < Authenticatable
      def authenticate!
        resource = mapping.to.find_for_token_authentication(authentication_hash)

        if validate(resource)
          resource.after_token_authentication
          success!(resource)
        else
          fail(:invalid_token)
        end
      end

    private

      # TokenAuthenticatable request is valid for any controller and any verb.
      def valid_request?
        true
      end

      # Do not use remember_me behavir with token.
      def remember_me?
        false
      end

      # Try both scoped and non scoped keys.
      def params_auth_hash
        params[scope] || params
      end

      # Overwrite authentication keys to use token_authentication_key.
      def authentication_keys
        @authentication_keys ||= [mapping.to.token_authentication_key]
      end
    end
  end
end

Warden::Strategies.add(:token_authenticatable, Devise::Strategies::TokenAuthenticatable)

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
devise-1.1.8 lib/devise/strategies/token_authenticatable.rb
devise-1.1.7 lib/devise/strategies/token_authenticatable.rb
devise-1.1.6 lib/devise/strategies/token_authenticatable.rb
devise-1.1.5 lib/devise/strategies/token_authenticatable.rb
devise-1.1.4 lib/devise/strategies/token_authenticatable.rb
devise-1.1.3 lib/devise/strategies/token_authenticatable.rb
devise-1.1.2 lib/devise/strategies/token_authenticatable.rb
devise-1.1.1 lib/devise/strategies/token_authenticatable.rb
devise-1.1.0 lib/devise/strategies/token_authenticatable.rb
namxam-devise-1.1.0.win lib/devise/strategies/token_authenticatable.rb
devise-1.1.rc2 lib/devise/strategies/token_authenticatable.rb