Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_sha256 #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/oauth1/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Helper
def initialize(method, url, params, options)
options.reverse_update({
version: "1.0",
signature_method: 'HMAC-SHA1',
signature_method: options.delete(:sign_method),
timestamp: Time.now.to_i.to_s,
nonce: SecureRandom.uuid
})
Expand All @@ -30,8 +30,8 @@ def signature_base
end


def full_url
append_signature_to_params
def full_url(sign_method)
append_signature_to_params(sign_method)
url_with_params.to_s
end

Expand All @@ -44,16 +44,16 @@ def url_with_params
@url.dup.tap{|url| url.query_values = url_params}
end

def append_signature_to_params
@url_params[:oauth_signature] = hmac_sha1_signature(key, signature_base)
def append_signature_to_params(sign_method)
@url_params[:oauth_signature] = hmac_signature(key, signature_base, sign_method)
end

def prepend_oauth_to_key(options)
Hash[options.map{|key, value| ["oauth_#{key}".to_sym, value]}]
end

def hmac_sha1_signature(key, signature_string)
digest = OpenSSL::Digest.new('sha1')
def hmac_signature(key, signature_string, sign_method)
digest = OpenSSL::Digest.new(sign_method)
hmac = OpenSSL::HMAC.digest(digest, key, signature_string)
Base64.encode64(hmac).chomp.gsub(/\n/, '')
end
Expand Down