Sha256: 9e0f2949fa9830c92a4730cc7482b176d99de42bce6b9b51c4f0a07c9315f14a

Contents?: true

Size: 1.69 KB

Versions: 12

Compression:

Stored size: 1.69 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 store?
        super && !mapping.to.skip_session_storage.include?(:token_auth)
      end

      def authenticate!
        resource = mapping.to.find_for_token_authentication(authentication_hash)
        return fail(:invalid_token) unless resource

        if validate(resource)
          resource.after_token_authentication
          success!(resource)
        end
      end

    private

      # Token Authenticatable can be authenticated with params in any controller and any verb.
      def valid_params_request?
        true
      end

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

      # Try both scoped and non scoped keys.
      def params_auth_hash
        if params[scope].kind_of?(Hash) && params[scope].has_key?(authentication_keys.first)
          params[scope]
        else
          params
        end
      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

12 entries across 12 versions & 5 rubygems

Version Path
devise-2.1.4 lib/devise/strategies/token_authenticatable.rb
devise-warbler-2.2.3 lib/devise/strategies/token_authenticatable.rb
devise-2.2.3 lib/devise/strategies/token_authenticatable.rb
devise-2.1.3 lib/devise/strategies/token_authenticatable.rb
devise-2.2.2 lib/devise/strategies/token_authenticatable.rb
devise-2.2.1 lib/devise/strategies/token_authenticatable.rb
devise-2.2.0 lib/devise/strategies/token_authenticatable.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/devise-2.2.0.rc/lib/devise/strategies/token_authenticatable.rb
devise-2.2.0.rc lib/devise/strategies/token_authenticatable.rb
af-devise-2.1.2 lib/devise/strategies/token_authenticatable.rb
devise-2.1.2 lib/devise/strategies/token_authenticatable.rb
rmello-devise-2.1.0.2 lib/devise/strategies/token_authenticatable.rb