Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
- Removed ruby-hmac dependency. Using OpenSSL::HMAC instead
Browse files Browse the repository at this point in the history
- Updated the Request class and tests
- Added .bundle to the ignore list
  • Loading branch information
DBA committed Jul 1, 2010
1 parent 84c6ca2 commit 0ee8f97
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.bundle
**/.DS_Store
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ source :gemcutter

gem 'rspec', '>= 2.0.0.beta'
gem 'activesupport', '>= 3.0.0.beta'
gem 'ruby-hmac'
6 changes: 2 additions & 4 deletions oauth2-server/lib/oauth2/server/request.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'openssl'
require 'oauth2/attributes'
require 'hmac-sha2'
require 'active_support/base64'

module OAuth2
Expand Down Expand Up @@ -84,9 +84,7 @@ def calculate_signature
request_uri
].join(',')

digest = HMAC::SHA256.digest(secret, normalized_string)

ActiveSupport::Base64.encode64s(digest)
ActiveSupport::Base64.encode64s(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), secret, normalized_string))
end

def validate_signature
Expand Down
4 changes: 2 additions & 2 deletions oauth2-server/spec/server/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
subject.should_receive(:request_header).exactly(3).times.with(no_args).and_return(header)
subject.should_receive(:secret).once.and_return("secret")

HMAC::SHA256.should_receive(:digest).once.
with("secret", normalized_string).
OpenSSL::HMAC.should_receive(:digest).once.
with(OpenSSL::Digest::Digest.new('sha256'), "secret", normalized_string).
and_return("digest")

ActiveSupport::Base64.should_receive(:encode64s).
Expand Down
6 changes: 6 additions & 0 deletions oauth2-server/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
puts 'RSpec not found. Please install rspec with command bundle install'
end

begin
require 'openssl'
rescue LoadError => e
puts 'OpenSSL not present. Please check your Ruby installation and make sure it includes the OpenSSL libraries'
end

require 'oauth2/server'

Dir.glob(File.dirname(__FILE__) + "/support/**/*.rb").each do |file|
Expand Down

0 comments on commit 0ee8f97

Please sign in to comment.