Class: RestEasy::Auth::Basic
- Inherits:
-
Object
- Object
- RestEasy::Auth::Basic
- Defined in:
- lib/rest_easy/auth/basic.rb
Overview
HTTP Basic authentication. Encodes username:password as Base64 and sets the Authorization header.
Instance Method Summary collapse
- #apply(request) ⇒ Object
-
#initialize(username:, password:) ⇒ Basic
constructor
A new instance of Basic.
- #on_rejected(response) ⇒ Object
Constructor Details
#initialize(username:, password:) ⇒ Basic
Returns a new instance of Basic.
10 11 12 |
# File 'lib/rest_easy/auth/basic.rb', line 10 def initialize(username:, password:) @encoded = Base64.strict_encode64("#{username}:#{password}") end |
Instance Method Details
#apply(request) ⇒ Object
14 15 16 |
# File 'lib/rest_easy/auth/basic.rb', line 14 def apply(request) request.headers["Authorization"] = "Basic #{@encoded}" end |
#on_rejected(response) ⇒ Object
18 19 20 |
# File 'lib/rest_easy/auth/basic.rb', line 18 def on_rejected(response) raise RestEasy::AuthenticationError, "Authentication failed: #{response.status}" end |