module Sinch::Request::Authorization
Private Instance Methods
application_key()
click to toggle source
# File lib/sinch/request/concerns/authorization.rb, line 63 def application_key Sinch.config.application_key end
application_secret()
click to toggle source
# File lib/sinch/request/concerns/authorization.rb, line 67 def application_secret Sinch.config.secret_key end
canonical_headers()
click to toggle source
# File lib/sinch/request/concerns/authorization.rb, line 51 def canonical_headers "x-timestamp:#{timestamp}" end
content_md5()
click to toggle source
# File lib/sinch/request/concerns/authorization.rb, line 45 def content_md5 Base64.encode64( Digest::MD5.digest(payload.to_json.encode('UTF-8')) ).strip end
content_type()
click to toggle source
# File lib/sinch/request/concerns/authorization.rb, line 55 def content_type 'application/json' end
protected_resource_auth()
click to toggle source
# File lib/sinch/request/concerns/authorization.rb, line 17 def protected_resource_auth return unless application_secret.present? 'Application ' + [ application_key, signature ].join(':') end
public_resource_auth()
click to toggle source
# File lib/sinch/request/concerns/authorization.rb, line 13 def public_resource_auth "Application #{application_key}" end
signature()
click to toggle source
# File lib/sinch/request/concerns/authorization.rb, line 25 def signature Base64.encode64( OpenSSL::HMAC.digest( OpenSSL::Digest.new('sha256'), Base64.decode64(application_secret), string_to_sign ) ).strip end
string_to_sign()
click to toggle source
# File lib/sinch/request/concerns/authorization.rb, line 35 def string_to_sign [ method.to_s.upcase, content_md5, content_type, canonical_headers, endpoint ].join("\n").encode('UTF-8') end
timestamp()
click to toggle source
# File lib/sinch/request/concerns/authorization.rb, line 59 def timestamp Time.now.utc.iso8601 end