Class: Rack::Bacoo::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bacoo/authenticator.rb

Instance Method Summary collapse

Constructor Details

#initialize(cookie_attributes:, cookie_encryptor:, password_cost:, users:) ⇒ Authenticator

Returns a new instance of Authenticator.



9
10
11
12
13
14
# File 'lib/rack/bacoo/authenticator.rb', line 9

def initialize(cookie_attributes:, cookie_encryptor:, password_cost:, users:)
  @cookie_attributes = cookie_attributes
  @cookie_encryptor = cookie_encryptor
  @password_cost = password_cost
  @users = users
end

Instance Method Details

#basic_auth_provided?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rack/bacoo/authenticator.rb', line 24

def basic_auth_provided?
  @basic_auth_request.provided?
end

#basic_authenticated {|@credentials| ... } ⇒ Object

Yields:

  • (@credentials)


32
33
34
35
36
# File 'lib/rack/bacoo/authenticator.rb', line 32

def basic_authenticated
  return unless @credentials.basic_authenticated?(@basic_auth_request)

  yield @credentials
end

Yields:

  • (@credentials)


38
39
40
41
42
# File 'lib/rack/bacoo/authenticator.rb', line 38

def cookie_authenticated
  return unless @credentials.cookie_authenticated?(@session_cookie)

  yield @credentials
end

#persist_session!(credentials, headers) ⇒ Object



44
45
46
# File 'lib/rack/bacoo/authenticator.rb', line 44

def persist_session!(credentials, headers)
  @session_cookie.set(headers, credentials.username, credentials.password)
end

#valid_basic_auth?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rack/bacoo/authenticator.rb', line 28

def valid_basic_auth?
  @basic_auth_request.valid_basic_auth?
end

#with_env(env) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rack/bacoo/authenticator.rb', line 16

def with_env(env)
  @env = env
  @basic_auth_request = BasicAuthRequest.new(env)
  @session_cookie = SessionCookie.new(@cookie_attributes, @cookie_encryptor, env)
  @credentials = Credentials.new(@password_cost, @users)
  yield
end