From 15164012778a2899dd18cade294281406312f8e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rik=20Escobedo?= Date: Mon, 23 Oct 2017 12:01:13 -0500 Subject: [PATCH 1/2] Use `strict_encode64` for basic authentication --- lib/oauth2/authenticator.rb | 2 +- spec/oauth2/authenticator_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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({}) From 83e121c30b4ad7dfbaf19d674b7f3fd9301080c5 Mon Sep 17 00:00:00 2001 From: meganemura Date: Fri, 5 Oct 2018 02:54:38 +0900 Subject: [PATCH 2/2] Replace strict_encode64 with Base64 built-in's --- lib/oauth2/mac_token.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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