Class: Restfulness::HttpAuthentication::Basic
- Inherits:
-
Object
- Object
- Restfulness::HttpAuthentication::Basic
- Defined in:
- lib/restfulness/http_authentication/basic.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
The Requests::AuthorizationHeader object generated in the request.
Instance Method Summary collapse
-
#credentials ⇒ Object
Attempt to decode the credentials provided in the header.
-
#initialize(header) ⇒ Basic
constructor
A new instance of Basic.
- #password ⇒ Object
- #username ⇒ Object
-
#valid? ⇒ Boolean
Determine if the header we were provided is valid.
Constructor Details
#initialize(header) ⇒ Basic
Returns a new instance of Basic.
9 10 11 |
# File 'lib/restfulness/http_authentication/basic.rb', line 9 def initialize(header) self.header = header end |
Instance Attribute Details
#header ⇒ Object
The Requests::AuthorizationHeader object generated in the request
7 8 9 |
# File 'lib/restfulness/http_authentication/basic.rb', line 7 def header @header end |
Instance Method Details
#credentials ⇒ Object
Attempt to decode the credentials provided in the header.
19 20 21 22 23 24 |
# File 'lib/restfulness/http_authentication/basic.rb', line 19 def credentials @credentials ||= begin txt = ::Base64.decode64(header.params || '') txt.split(/:/, 2) end end |
#password ⇒ Object
30 31 32 |
# File 'lib/restfulness/http_authentication/basic.rb', line 30 def password credentials[1] end |
#username ⇒ Object
26 27 28 |
# File 'lib/restfulness/http_authentication/basic.rb', line 26 def username credentials[0] end |
#valid? ⇒ Boolean
Determine if the header we were provided is valid.
14 15 16 |
# File 'lib/restfulness/http_authentication/basic.rb', line 14 def valid? header.schema == 'Basic' && credentials.length == 2 end |