├── .gitignore ├── .rspec ├── .travis.yml ├── lib ├── omniauth-infusionsoft.rb └── omniauth │ ├── infusionsoft │ └── version.rb │ └── strategies │ └── infusionsoft.rb ├── Gemfile ├── Rakefile ├── spec ├── spec_helper.rb └── omniauth │ └── strategies │ └── infusionsoft_spec.rb ├── LICENSE.txt ├── omniauth-infusionsoft.gemspec ├── Readme.md └── Gemfile.lock /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | coverage/ 3 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color spec 2 | --format documentation 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.0.0 4 | -------------------------------------------------------------------------------- /lib/omniauth-infusionsoft.rb: -------------------------------------------------------------------------------- 1 | require 'omniauth/infusionsoft/version' 2 | require 'omniauth/strategies/infusionsoft' 3 | -------------------------------------------------------------------------------- /lib/omniauth/infusionsoft/version.rb: -------------------------------------------------------------------------------- 1 | module OmniAuth 2 | module Infusionsoft 3 | VERSION = '1.0.6' 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in omniauth-infusionsoft.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | require 'rspec/core/rake_task' 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task :default => :spec 7 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rspec' 2 | require 'omniauth' 3 | require 'omniauth-infusionsoft' 4 | 5 | RSpec.configure do |config| 6 | 7 | config.expect_with :rspec do |c| 8 | c.syntax = :expect 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /spec/omniauth/strategies/infusionsoft_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe OmniAuth::Strategies::Infusionsoft do 4 | 5 | subject do 6 | OmniAuth::Strategies::Infusionsoft.new({}) 7 | end 8 | 9 | before do 10 | OmniAuth.config.test_mode = true 11 | end 12 | 13 | after do 14 | OmniAuth.config.test_mode = false 15 | end 16 | 17 | context 'default options' do 18 | it 'has the correct name' do 19 | expect(subject.options.name).to eq('infusionsoft') 20 | end 21 | end 22 | 23 | context 'client options' do 24 | it 'has the correct site' do 25 | expect(subject.options.client_options.site).to eq('https://signin.infusionsoft.com') 26 | end 27 | 28 | it 'has the correct authorize url' do 29 | expect(subject.options.client_options.authorize_url).to eq('https://signin.infusionsoft.com/app/oauth/authorize') 30 | end 31 | 32 | it 'has the correct token url' do 33 | expect(subject.options.client_options.token_url).to eq('https://api.infusionsoft.com/token') 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 l1h3r 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /omniauth-infusionsoft.gemspec: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require File.expand_path('../lib/omniauth/infusionsoft/version', __FILE__) 3 | 4 | Gem::Specification.new do |gem| 5 | gem.name = 'omniauth-infusionsoft' 6 | gem.version = OmniAuth::Infusionsoft::VERSION 7 | gem.authors = ['Devin Turner'] 8 | gem.email = ['devin.turner09@gmail.com'] 9 | gem.summary = 'An Infusionsoft OAuth2 strategy for OmniAuth' 10 | gem.homepage = 'https://github.com/l1h3r/omniauth-infusionsoft' 11 | gem.license = 'MIT' 12 | 13 | gem.files = `git ls-files`.split($/) 14 | gem.executables = gem.files.grep(%r( ^bin/ )).map { |f| File.basename(f) } 15 | gem.test_files = gem.files.grep(%r( ^(test|spec|features)/ )) 16 | gem.require_paths = ['lib'] 17 | 18 | gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') 19 | 20 | gem.add_runtime_dependency 'nokogiri', '>= 1.6.5' 21 | gem.add_runtime_dependency 'omniauth', '~> 2.0' 22 | gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.1' 23 | 24 | gem.add_development_dependency 'bundler', '~> 1.5' 25 | gem.add_development_dependency 'rake', '~> 10.3' 26 | gem.add_development_dependency 'rspec', '~> 3.0' 27 | end 28 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | [](http://badge.fury.io/rb/omniauth-infusionsoft) 2 | [](https://travis-ci.org/L1h3r/omniauth-infusionsoft) 3 | [](https://codeclimate.com/github/L1h3r/omniauth-infusionsoft) 4 | 5 | OmniAuth::Infusionsoft 6 | --- 7 | 8 | An Infusionsoft OAuth2 strategy for OmniAuth. 9 | 10 | For more details, read the Infusionsoft documentation: https://developer.infusionsoft.com/docs 11 | 12 | Installation 13 | --- 14 | 15 | Add this line to your application's Gemfile: 16 | 17 |
gem 'omniauth-infusionsoft'18 | 19 | And then execute: 20 | 21 |
$ bundle install22 | 23 | Or install it yourself as: 24 | 25 |
$ gem install omniauth-infusionsoft26 | 27 | Usage 28 | --- 29 | 30 | Sign up for an Infusionsoft developer account: https://developer.infusionsoft.com 31 | 32 | An example that you might put into a Rails initializer at
config/initializers/omniauth.rb
33 |
34 | ```ruby
35 | Rails.application.config.middleware.use OmniAuth::Builder do
36 | provider :infusionsoft, ENV['INFUSIONSOFT_KEY'], ENV['INFUSIONSOFT_SECRET']
37 | end
38 | ```
39 |
40 | Contributing
41 | ---
42 |
43 | 1. Fork it
44 | 2. Create your feature branch (`git checkout -b my-new-feature`)
45 | 3. Commit your changes (`git commit -am 'Add some feature'`)
46 | 4. Push to the branch (`git push origin my-new-feature`)
47 | 5. Create new Pull Request
48 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: .
3 | specs:
4 | omniauth-infusionsoft (1.0.6)
5 | nokogiri (>= 1.6.5)
6 | omniauth (~> 2.0)
7 | omniauth-oauth2 (~> 1.1)
8 |
9 | GEM
10 | remote: https://rubygems.org/
11 | specs:
12 | diff-lcs (1.2.5)
13 | faraday (2.6.0)
14 | faraday-net_http (>= 2.0, < 3.1)
15 | ruby2_keywords (>= 0.0.4)
16 | faraday-net_http (3.0.1)
17 | hashie (5.0.0)
18 | jwt (2.5.0)
19 | mini_portile2 (2.8.0)
20 | multi_xml (0.6.0)
21 | nokogiri (1.13.9)
22 | mini_portile2 (~> 2.8.0)
23 | racc (~> 1.4)
24 | oauth2 (2.0.9)
25 | faraday (>= 0.17.3, < 3.0)
26 | jwt (>= 1.0, < 3.0)
27 | multi_xml (~> 0.5)
28 | rack (>= 1.2, < 4)
29 | snaky_hash (~> 2.0)
30 | version_gem (~> 1.1)
31 | omniauth (2.1.0)
32 | hashie (>= 3.4.6)
33 | rack (>= 2.2.3)
34 | rack-protection
35 | omniauth-oauth2 (1.8.0)
36 | oauth2 (>= 1.4, < 3)
37 | omniauth (~> 2.0)
38 | racc (1.6.0)
39 | rack (3.0.0)
40 | rack-protection (3.0.2)
41 | rack
42 | rake (10.3.2)
43 | rspec (3.1.0)
44 | rspec-core (~> 3.1.0)
45 | rspec-expectations (~> 3.1.0)
46 | rspec-mocks (~> 3.1.0)
47 | rspec-core (3.1.5)
48 | rspec-support (~> 3.1.0)
49 | rspec-expectations (3.1.2)
50 | diff-lcs (>= 1.2.0, < 2.0)
51 | rspec-support (~> 3.1.0)
52 | rspec-mocks (3.1.2)
53 | rspec-support (~> 3.1.0)
54 | rspec-support (3.1.1)
55 | ruby2_keywords (0.0.5)
56 | snaky_hash (2.0.1)
57 | hashie
58 | version_gem (~> 1.1, >= 1.1.1)
59 | version_gem (1.1.1)
60 |
61 | PLATFORMS
62 | ruby
63 |
64 | DEPENDENCIES
65 | bundler (~> 1.5)
66 | omniauth-infusionsoft!
67 | rake (~> 10.3)
68 | rspec (~> 3.0)
69 |
70 | BUNDLED WITH
71 | 1.17.2
72 |
--------------------------------------------------------------------------------
/lib/omniauth/strategies/infusionsoft.rb:
--------------------------------------------------------------------------------
1 | require 'omniauth-oauth2'
2 | require 'resolv'
3 | require 'net/http'
4 | require 'net/https'
5 | require 'nokogiri'
6 |
7 | module OmniAuth
8 | module Strategies
9 | class Infusionsoft < OmniAuth::Strategies::OAuth2
10 | option :name, 'infusionsoft'
11 |
12 | option :client_options, {
13 | authorize_url: 'https://signin.infusionsoft.com/app/oauth/authorize',
14 | token_url: 'https://api.infusionsoft.com/token',
15 | site: 'https://signin.infusionsoft.com'
16 | }
17 |
18 | def full_host
19 | case OmniAuth.config.full_host
20 | when String
21 | OmniAuth.config.full_host
22 | when Proc
23 | OmniAuth.config.full_host.call(env)
24 | else
25 | uri = URI.parse(request.url.gsub(/\?.*$/,''))
26 | uri.path = ''
27 | uri.query = nil
28 | #infusionsoft requires https for callback urls
29 | #force ssl for all hosts except: 127.x.x.x, fe80:: and ::1
30 | uri.scheme = 'https' unless Resolv.getaddress(uri.host) =~ /^(fe80::|127|::1)/
31 | uri.to_s
32 | end
33 | end
34 |
35 | uid { "#{user_info['globalUserId']}-#{user_info['appAlias']}" }
36 |
37 | info do
38 | {
39 | name: user_info['displayName'],
40 | email: user_info['casUsername']
41 | }
42 | end
43 |
44 | def user_info
45 | @user_info ||= get_user_info(access_token.token)
46 | end
47 |
48 | def get_user_info(token)
49 | uri = URI.parse("https://api.infusionsoft.com/crm/xmlrpc/v1?access_token=#{token}")
50 | https = Net::HTTP.new(uri.host, uri.port)
51 | https.use_ssl = true
52 | req = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'application/xml'})
53 | req.body = %q{
54 |