Class: Restfulness::HttpAuthentication::Basic

Inherits:
Object
  • Object
show all
Defined in:
lib/restfulness/http_authentication/basic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#headerObject

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

#credentialsObject

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

#passwordObject



30
31
32
# File 'lib/restfulness/http_authentication/basic.rb', line 30

def password
  credentials[1]
end

#usernameObject



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.

Returns:

  • (Boolean)


14
15
16
# File 'lib/restfulness/http_authentication/basic.rb', line 14

def valid?
  header.schema == 'Basic' && credentials.length == 2
end