Class: Booth::Requests::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/booth/requests/authentication.rb

Overview

Convenience wrapper for ‘Warden::Manager`.

Instance Method Summary collapse

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

Returns:

  • (Boolean)


22
23
24
# File 'lib/booth/requests/authentication.rb', line 22

def logged_in?
  warden.authenticated?(scope)
end

#logged_in_as?(credential:) ⇒ Boolean

Returns:

  • (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 (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

#logoutObject



30
31
32
# File 'lib/booth/requests/authentication.rb', line 30

def logout
  warden.logout(scope)
end

#session_idObject



34
35
36
# File 'lib/booth/requests/authentication.rb', line 34

def session_id
  passport&.id
end