Class: Booth::Requests::Authentication
- Inherits:
-
Object
- Object
- Booth::Requests::Authentication
- Includes:
- Logging
- Defined in:
- lib/booth/requests/authentication.rb
Overview
Convenience wrapper for Warden::Manager.
Instance Method Summary collapse
-
#initialize(scope:, warden:) ⇒ Authentication
constructor
A new instance of Authentication.
- #logged_in? ⇒ Boolean
- #logged_in_as?(credential:) ⇒ Boolean
- #logged_out? ⇒ Boolean
- #login(session:) ⇒ Object
- #logout ⇒ Object
- #session_id ⇒ Object
Constructor Details
#initialize(scope:, warden:) ⇒ Authentication
Returns a new instance of Authentication.
13 14 15 16 |
# File 'lib/booth/requests/authentication.rb', line 13 def initialize(scope:, warden:) @scope = scope @warden = warden end |
Instance Method Details
#logged_in? ⇒ Boolean
27 28 29 30 |
# File 'lib/booth/requests/authentication.rb', line 27 def logged_in? log { "Checking whether logged in in scope #{scope}" } warden.authenticated?(scope) end |
#logged_in_as?(credential:) ⇒ Boolean
36 37 38 |
# File 'lib/booth/requests/authentication.rb', line 36 def logged_in_as?(credential:) logged_in? && credential.id == credential_id end |
#logged_out? ⇒ Boolean
32 33 34 |
# File 'lib/booth/requests/authentication.rb', line 32 def logged_out? !logged_in? end |
#login(session:) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/booth/requests/authentication.rb', line 18 def login(session:) log { "Persisting Session in Cookie for scope #{scope}" } # Warden's serialization mechanism only takes place for the *next* request. # In the *same* request, whatever we pass in, is returned back as it is. # That's why we don't pass in some ID here, but the entire Passport object # (which is that what we normally would receive by Warden's deserialization). warden.set_user ::Booth::Core::Sessions::ToPassport.call(session), scope: end |
#logout ⇒ Object
40 41 42 |
# File 'lib/booth/requests/authentication.rb', line 40 def logout warden.logout(scope) end |
#session_id ⇒ Object
44 45 46 |
# File 'lib/booth/requests/authentication.rb', line 44 def session_id passport&.session_id end |