Module: Clarity::BasicAuth

Included in:
Server
Defined in:
lib/clarity/server/basic_auth.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!(http_header) ⇒ Object



19
20
21
# File 'lib/clarity/server/basic_auth.rb', line 19

def authenticate!(http_header)
  raise NotAuthenticatedError unless authenticate(http_header)
end

#authentication_dataObject



12
13
14
15
16
17
# File 'lib/clarity/server/basic_auth.rb', line 12

def authentication_data
  headers = @http_headers.split("\000")
  auth_header = headers.detect {|head| head =~ /Authorization: / }
  header = auth_header.nil? ? "" : auth_header.split("Authorization: Basic ").last    
  return (user_name_and_password(header) rescue ['', ''])
end

#decode_credentials(request) ⇒ Object



4
5
6
# File 'lib/clarity/server/basic_auth.rb', line 4

def decode_credentials(request)
  Base64.decode64(request).split.last
end

#user_name_and_password(request) ⇒ Object



8
9
10
# File 'lib/clarity/server/basic_auth.rb', line 8

def user_name_and_password(request)
  decode_credentials(request).split(/:/, 2)
end