diff --git a/lib/oauth2/authenticator.rb b/lib/oauth2/authenticator.rb index ce627920..71d98bd3 100644 --- a/lib/oauth2/authenticator.rb +++ b/lib/oauth2/authenticator.rb @@ -31,7 +31,7 @@ def apply(params) end def self.encode_basic_auth(user, password) - 'Basic ' + Base64.encode64(user + ':' + password).delete("\n") + 'Basic ' + Base64.strict_encode64(user + ':' + password) end private diff --git a/lib/oauth2/mac_token.rb b/lib/oauth2/mac_token.rb index db7d4d77..0d9e16ff 100644 --- a/lib/oauth2/mac_token.rb +++ b/lib/oauth2/mac_token.rb @@ -88,7 +88,7 @@ def signature(timestamp, nonce, verb, uri) '', nil ].join("\n") - strict_encode64(OpenSSL::HMAC.digest(@algorithm, secret, signature)) + Base64.strict_encode64(OpenSSL::HMAC.digest(@algorithm, secret, signature)) end # Set the HMAC algorithm @@ -113,10 +113,5 @@ def algorithm=(alg) # and the MAC always goes in a header def token=(_noop) end - - # Base64.strict_encode64 is not available on Ruby 1.8.7 - def strict_encode64(str) - Base64.encode64(str).delete("\n") - end end end diff --git a/spec/oauth2/authenticator_spec.rb b/spec/oauth2/authenticator_spec.rb index 15980fa6..8a7c371f 100644 --- a/spec/oauth2/authenticator_spec.rb +++ b/spec/oauth2/authenticator_spec.rb @@ -40,7 +40,7 @@ context 'with Basic authentication' do let(:mode) { :basic_auth } - let(:header) { 'Basic ' + Base64.encode64("#{client_id}:#{client_secret}").delete("\n") } + let(:header) { 'Basic ' + Base64.strict_encode64("#{client_id}:#{client_secret}") } it 'encodes credentials in headers' do output = subject.apply({})