Class: Cassieq::Authentication
- Inherits:
-
Object
- Object
- Cassieq::Authentication
- Defined in:
- lib/cassieq/authentication.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #auth_headers(method, path, request_time = formated_time_now) ⇒ Object
-
#initialize(key, account) ⇒ Authentication
constructor
A new instance of Authentication.
- #signature_from_key(method, path, request_time = formated_time_now) ⇒ Object
Constructor Details
#initialize(key, account) ⇒ Authentication
13 14 15 16 |
# File 'lib/cassieq/authentication.rb', line 13 def initialize(key, account) @key = key @account = account end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
7 8 9 |
# File 'lib/cassieq/authentication.rb', line 7 def account @account end |
#key ⇒ Object (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, account, method, path) new(key, account).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 = [account, 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 |