Class: Rack::Bacoo::Authenticator
- Inherits:
-
Object
- Object
- Rack::Bacoo::Authenticator
- Defined in:
- lib/rack/bacoo/authenticator.rb
Instance Method Summary collapse
- #basic_auth_provided? ⇒ Boolean
- #basic_authenticated {|@credentials| ... } ⇒ Object
- #cookie_authenticated {|@credentials| ... } ⇒ Object
-
#initialize(cookie_attributes:, cookie_encryptor:, password_cost:, users:) ⇒ Authenticator
constructor
A new instance of Authenticator.
- #persist_session!(credentials, headers) ⇒ Object
- #valid_basic_auth? ⇒ Boolean
- #with_env(env) ⇒ Object
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_encryptor = @password_cost = password_cost @users = users end |
Instance Method Details
#basic_auth_provided? ⇒ 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
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 |
#cookie_authenticated {|@credentials| ... } ⇒ Object
38 39 40 41 42 |
# File 'lib/rack/bacoo/authenticator.rb', line 38 def return unless @credentials.(@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
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 |