Class: Cassieq::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/cassieq/authentication.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, account) ⇒ Authentication

Returns a new instance of Authentication.



13
14
15
16
# File 'lib/cassieq/authentication.rb', line 13

def initialize(key, )
  @key = key
  @account = 
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



7
8
9
# File 'lib/cassieq/authentication.rb', line 7

def 
  @account
end

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/cassieq/authentication.rb', line 7

def key
  @key
end

Class Method Details

.generate_auth_headers(key, account, method, path) ⇒ Object



9
10
11
# File 'lib/cassieq/authentication.rb', line 9

def self.generate_auth_headers(key, , method, path)
  new(key, ).auth_headers(method, path)
end

Instance Method Details

#auth_headers(method, path, request_time = formated_time_now) ⇒ Object



18
19
20
21
22
# File 'lib/cassieq/authentication.rb', line 18

def auth_headers(method, path, request_time = formated_time_now)
  auth_signature = signature_from_key(method, path, request_time)

  { "X-Cassieq-Request-Time" => request_time, "Authorization" => "Signed #{auth_signature}" }
end

#signature_from_key(method, path, request_time = formated_time_now) ⇒ Object



24
25
26
27
28
29
# File 'lib/cassieq/authentication.rb', line 24

def signature_from_key(method, path, request_time = formated_time_now)
  key_bytes = Base64.urlsafe_decode64("#{key}==")
  string_to_sign = [, method.to_s.upcase, path, request_time].join("\n")
  hmac = OpenSSL::HMAC.digest("sha256", key_bytes, string_to_sign)
  Base64.urlsafe_encode64(hmac).gsub(/=+$/, "")
end