module Emailage::Signature

Public Class Methods

concatenate_request_elements(method, url, query) click to toggle source

9.1.3. Concatenate Request Elements

# File lib/emailage/signature.rb, line 16
def concatenate_request_elements(method, url, query)
  [method.to_s.upcase, url, query].map {|e| CGI.escape(e)}.join '&'
end
create(method, url, params, hmac_key) click to toggle source

oauth.net/core/1.0/#signing_process Using HTTP GET parameters option.

@param method [String] HTTP 1.1 Method @param url [String] Normalized URL to be requested until ? sign. @param params [Hash] GET or www-urlencoded POST request params. @param hmac_key [String] Key generated out of Consumer secret and token.

@return [String] Value of the oauth_signature query parameter.

# File lib/emailage/signature.rb, line 35
def create(method, url, params, hmac_key)
  query = normalize_query_parameters(params)
  base_string = concatenate_request_elements(method, url, query)
  digest = hmac_sha1(base_string, hmac_key)
  # 9.2.1.  Generating Signature
  Base64.strict_encode64 digest
end
hmac_sha1(base_string, hmac_key) click to toggle source

9.2. HMAC-SHA1

# File lib/emailage/signature.rb, line 21
def hmac_sha1(base_string, hmac_key)
  OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), hmac_key, base_string)
end
normalize_query_parameters(params) click to toggle source

9.1.1. Normalize Request Parameters

# File lib/emailage/signature.rb, line 11
def normalize_query_parameters(params)
  params.sort.map {|k,v| [CGI.escape(k.to_s), ERB::Util.url_encode(v.to_s)].join '='}.join '&'
end