Skip to content

Commit f00f15a

Browse files
committed
Fix compatibility with Faraday 2.0
Faraday::Connection#basic_auth was deprecated in Faraday 1.10 and removed in Faraday 2.0. Building an Authorization header is not that involved, we can do it ourselves.
1 parent fa5ca67 commit f00f15a

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

lib/omniauth/strategies/intercom.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'omniauth-oauth2'
2-
require 'uri'
2+
require 'base64'
33

44
module OmniAuth
55
module Strategies
@@ -53,11 +53,15 @@ def request_phase
5353
protected
5454

5555
def accept_headers
56-
access_token.client.connection.headers['Authorization'] = access_token.client.connection.basic_auth(access_token.token, '')
56+
access_token.client.connection.headers['Authorization'] = "Basic #{basic_auth_credentials}"
5757
access_token.client.connection.headers['Accept'] = "application/vnd.intercom.3+json"
5858
access_token.client.connection.headers['User-Agent'] = "omniauth-intercom/#{::OmniAuth::Intercom::VERSION}"
5959
end
6060

61+
def basic_auth_credentials
62+
Base64.encode64("#{access_token.token}:").delete("\n")
63+
end
64+
6165
def prepopulate_signup_fields_form
6266
options.client_options[:authorize_url] += '/signup'
6367
signup_hash = signup_fields_hash

omniauth-intercom.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Gem::Specification.new do |spec|
1717
spec.bindir = "exe"
1818
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
1919
spec.require_paths = ["lib"]
20+
2021
spec.add_runtime_dependency 'omniauth-oauth2', '>= 1.2'
22+
spec.add_runtime_dependency 'base64'
2123

2224
spec.add_development_dependency "rake", "~> 10.0"
2325
spec.add_development_dependency "rspec", "~> 3.0"

spec/omniauth/strategies/intercom_spec.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require 'spec_helper'
22

33
describe OmniAuth::Strategies::Intercom do
4-
let(:access_token) { double('AccessToken', options: {}) }
4+
let(:access_token) { instance_double(OAuth2::AccessToken) }
55
let(:token) { 'some-token' }
6-
let(:client) { double('Client') }
7-
let(:connection) { double('Connection') }
6+
let(:client) { instance_double(OAuth2::Client) }
7+
let(:connection) { instance_double(Faraday::Connection) }
88
let(:headers) { {} }
99
let(:options) { {} }
1010

@@ -21,12 +21,11 @@
2121

2222
allow(client).to receive(:connection).and_return connection
2323
allow(connection).to receive(:headers).and_return headers
24-
allow(connection).to receive(:basic_auth).and_return "Bearer #{token}"
2524
end
2625

2726
context 'with verified email' do
2827
let(:parsed_response) { JSON.parse({email: '[email protected]', name: 'Kevin Antoine', avatar: {image_url: 'https://static.intercomassets.com/avatars/343616/square_128/me.jpg?1454165491'}, email_verified: true}.to_json) }
29-
let(:response) { double('Response', :parsed => parsed_response) }
28+
let(:response) { instance_double(OAuth2::Response, :parsed => parsed_response) }
3029

3130
before do
3231
allow(access_token).to receive(:get).with('/me').and_return response
@@ -103,7 +102,7 @@
103102

104103
context 'with unverified email' do
105104
let(:parsed_response) { JSON.parse({email: '[email protected]', name: 'Kevin Antoine', avatar: {image_url: 'https://static.intercomassets.com/avatars/343616/square_128/me.jpg?1454165491'}, email_verified: false}.to_json) }
106-
let(:response) { double('Response', :parsed => parsed_response) }
105+
let(:response) { instance_double(OAuth2::Response, :parsed => parsed_response) }
107106

108107
before do
109108
allow(access_token).to receive(:get).with('/me').and_return response

0 commit comments

Comments
 (0)