Module: Authentication
- Defined in:
- lib/authentication.rb,
lib/authentication/version.rb,
lib/authentication/authenticator.rb
Overview
Top-level namespace of this library, also works as a convenient module to supply authentication-related methods for Rails controller etc.
By including this, the class will have methods like “login!” or “current_user!”. See method list for the documentation of Authenticator.
To find current_user, this module uses “find_current_user” method defined in included module to find current user, and “current_user_id” as the session key.
Defined Under Namespace
Classes: Authenticator, Unauthenticated
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
Instance Method Summary collapse
-
#current_user_authenticator ⇒ Authentication::Authenticator
Return authenticator for current_user.
Class Method Details
.included(base) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/authentication.rb', line 13 def self.included(base) base.class_eval do extend Forwardable def_delegators :current_user_authenticator, :login!, :current_user, :current_user_id, :logged_in?, :logout! end end |
Instance Method Details
#current_user_authenticator ⇒ Authentication::Authenticator
Return authenticator for current_user.
23 24 25 26 27 28 29 30 31 |
# File 'lib/authentication.rb', line 23 def current_user_authenticator @__authenticator ||= Authentication::Authenticator.new( session: session, session_key: :current_user_id, finder: -> { find_current_user }, after_login_callback: -> { self.respond_to?(:after_login, true) && after_login }, after_logout_callback: -> { self.respond_to?(:after_logout, true) && after_logout } ) end |