Skip to content

Commit

Permalink
Add option fallback_to_devise
Browse files Browse the repository at this point in the history
Fixes #49
Closes #59
  • Loading branch information
Vladimir Lyzo authored and gonzalo-bulnes committed May 17, 2014
1 parent 94f9edd commit 399a0b7
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ module ActsAsTokenAuthenticationHandlerMethods
private :header_email_name
# This is our new function that comes before Devise's one
before_filter :authenticate_entity_from_token!
# This is Devise's authentication
before_filter :authenticate_entity!

# This is necessary to test which arguments were passed to sign_in
# from authenticate_entity_from_token!
Expand Down Expand Up @@ -89,6 +87,15 @@ 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 @@ -102,8 +109,11 @@ module ActsAsTokenAuthenticationHandler

module ClassMethods
def acts_as_token_authentication_handler_for(entity, options = {})
options = { fallback_to_devise: true }.merge(options)

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

def acts_as_token_authentication_handler
Expand Down

0 comments on commit 399a0b7

Please sign in to comment.