Skip to content

Commit

Permalink
Merge pull request #28 from intercom/faraday
Browse files Browse the repository at this point in the history
Fix compatibility with Faraday 2.0
  • Loading branch information
eugeneius authored Aug 16, 2024
2 parents fa5ca67 + f00f15a commit 9069f47
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 6 additions & 2 deletions lib/omniauth/strategies/intercom.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'omniauth-oauth2'
require 'uri'
require 'base64'

module OmniAuth
module Strategies
Expand Down Expand Up @@ -53,11 +53,15 @@ def request_phase
protected

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

def basic_auth_credentials
Base64.encode64("#{access_token.token}:").delete("\n")
end

def prepopulate_signup_fields_form
options.client_options[:authorize_url] += '/signup'
signup_hash = signup_fields_hash
Expand Down
2 changes: 2 additions & 0 deletions omniauth-intercom.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Gem::Specification.new do |spec|
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_runtime_dependency 'omniauth-oauth2', '>= 1.2'
spec.add_runtime_dependency 'base64'

spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
Expand Down
11 changes: 5 additions & 6 deletions spec/omniauth/strategies/intercom_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'spec_helper'

describe OmniAuth::Strategies::Intercom do
let(:access_token) { double('AccessToken', options: {}) }
let(:access_token) { instance_double(OAuth2::AccessToken) }
let(:token) { 'some-token' }
let(:client) { double('Client') }
let(:connection) { double('Connection') }
let(:client) { instance_double(OAuth2::Client) }
let(:connection) { instance_double(Faraday::Connection) }
let(:headers) { {} }
let(:options) { {} }

Expand All @@ -21,12 +21,11 @@

allow(client).to receive(:connection).and_return connection
allow(connection).to receive(:headers).and_return headers
allow(connection).to receive(:basic_auth).and_return "Bearer #{token}"
end

context 'with verified email' do
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) }
let(:response) { double('Response', :parsed => parsed_response) }
let(:response) { instance_double(OAuth2::Response, :parsed => parsed_response) }

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

context 'with unverified email' do
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) }
let(:response) { double('Response', :parsed => parsed_response) }
let(:response) { instance_double(OAuth2::Response, :parsed => parsed_response) }

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

0 comments on commit 9069f47

Please sign in to comment.