Class: Booth::Requests::Authentication
- Inherits:
-
Object
- Object
- Booth::Requests::Authentication
- 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
- #login(session:) ⇒ Object
- #logout ⇒ Object
- #session_id ⇒ Object
Constructor Details
#initialize(scope:, warden:) ⇒ Authentication
Returns a new instance of Authentication.
9 10 11 12 |
# File 'lib/booth/requests/authentication.rb', line 9 def initialize(scope:, warden:) @scope = scope @warden = warden end |
Instance Method Details
#logged_in? ⇒ Boolean
22 23 24 |
# File 'lib/booth/requests/authentication.rb', line 22 def logged_in? warden.authenticated?(scope) end |
#logged_in_as?(credential:) ⇒ Boolean
26 27 28 |
# File 'lib/booth/requests/authentication.rb', line 26 def logged_in_as?(credential:) logged_in? && credential.id == credential_id end |
#login(session:) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/booth/requests/authentication.rb', line 14 def login(session:) # Whatever instance we pass in to Warden, # it needs to be that, which we also want do get out. # Because serialization only takes place for the *next* request. # In the *same* request, whatever we pass in, is returned back as it is. warden.set_user ::Booth::Sessions::ToPassport.call(session), scope: end |
#logout ⇒ Object
30 31 32 |
# File 'lib/booth/requests/authentication.rb', line 30 def logout warden.logout(scope) end |
#session_id ⇒ Object
34 35 36 |
# File 'lib/booth/requests/authentication.rb', line 34 def session_id passport&.id end |