Skip to content

Commit

Permalink
Add :only and :except filter options
Browse files Browse the repository at this point in the history
Allows the `acts_as_token_authentication_handler_for` to be
applied to a specific set of controller actions, as would a filter.

Fixes #53
Closes #62
  • Loading branch information
Vladimir Lyzo authored and gonzalo-bulnes committed May 24, 2014
1 parent 2cf026e commit e2dc225
Showing 1 changed file with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module ActsAsTokenAuthenticationHandlerMethods
private :authenticate_entity_from_token!
private :header_token_name
private :header_email_name
# This is our new function that comes before Devise's one
before_filter :authenticate_entity_from_token!

# This is necessary to test which arguments were passed to sign_in
# from authenticate_entity_from_token!
Expand Down Expand Up @@ -87,15 +85,6 @@ def self.set_entity entity
end
end

module ActsAsTokenAuthenticationHandlerDeviseFallback
extend ActiveSupport::Concern

included do
# This is Devise's authentication
before_filter :authenticate_entity!
end
end

module ActsAsTokenAuthenticationHandler
extend ActiveSupport::Concern

Expand All @@ -113,7 +102,11 @@ def acts_as_token_authentication_handler_for(entity, options = {})

SimpleTokenAuthentication::ActsAsTokenAuthenticationHandlerMethods.set_entity entity
include SimpleTokenAuthentication::ActsAsTokenAuthenticationHandlerMethods
include SimpleTokenAuthentication::ActsAsTokenAuthenticationHandlerDeviseFallback if options[:fallback_to_devise]

# This is our new function that comes before Devise's one
before_filter :authenticate_entity_from_token!, options.slice(:only, :except)
# This is Devise's authentication
options[:fallback_to_devise] && before_filter(:authenticate_entity!, options.slice(:only, :except))
end

def acts_as_token_authentication_handler
Expand Down

0 comments on commit e2dc225

Please sign in to comment.