Closed Piioupiou closed 2 years ago
@taylorbrooks hello, is it possible to merge this PR ?
Is this backwards compatible with the 1.x.x
version of Faraday?
Yes : In : https://lostisland.github.io/faraday/middleware/authentication It is stated that the usage for 1.x is as follow :
# Basic Auth request
# Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Faraday.new(...) do |conn|
conn.request :basic_auth, 'username', 'password'
end
# Token Auth request
# `options` are automatically converted into `key=value` format
# Authorization: Token authentication-token <options>
Faraday.new(...) do |conn|
conn.request :token_auth, 'authentication-token', **options
end
# Generic Auth Request
# Authorization: Bearer authentication-token
Faraday.new(...) do |conn|
conn.request :authorization, 'Bearer', 'authentication-token'
end
We can also see that in V1.0-rc1 (In the commitf 1b26575 : https://github.com/lostisland/faraday/pull/832/files#diff-fbf2a9359f64f8b10713cb330bf684486b648e358381d9f7f9004c6f36721813)
There is a rspec on this, implemented this way :
let(:conn) do
Faraday.new do |b|
b.request auth_type, *auth_config
b.adapter :test do |stub|
stub.get('/auth-echo') do |env|
[200, {}, env[:request_headers]['Authorization']]
end
end
end
end
{...}
describe 'basic_auth' do
let(:auth_type) { :basic_auth }
context 'when passed correct params' do
let(:auth_config) { %w(aladdin opensesame) }
it { expect(response.body).to eq('Basic YWxhZGRpbjpvcGVuc2VzYW1l') }
include_examples 'does not interfere with existing authentication'
end
context 'when passed very long values' do
let(:auth_config) { ['A' * 255, ''] }
it { expect(response.body).to eq("Basic #{'QUFB' * 85}Og==") }
include_examples 'does not interfere with existing authentication'
end
end
NB: In faraday 2.x we should use :
Faraday.new(...) do |conn|
conn.request :authorization, :basic, 'username', 'password'
end
@Piioupiou Pushed 3.8.0 to Rubygems.
Fix Faraday basic auth deprecation