omniauth-basecrm 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a8ae49f8aaf9d0d64d79e795987f453c6f4d26ab
4
+ data.tar.gz: 6c500a8753393af89b275c77c154aa5531d9d2ed
5
+ SHA512:
6
+ metadata.gz: 2fdd6da3561563ebe34141fa5c7900a115c5da28c4ecf9ee504924255bbd74cea96e1662d556483f0196700097d07d4fdfa1c9e9281b64f1072bc8a68122fc15
7
+ data.tar.gz: fab389cae77d05d531523086824441545a560410636ca5a9852122f61c924a72979c3929a829e5e7c92743ac3379dd110c991734a3bc20f71ef5a785c0093648
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,2 @@
1
+ .idea
2
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --fail-fast
3
+ --order random
@@ -0,0 +1 @@
1
+ 2.2.2
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem 'rake', '~> 10.4'
6
+ gem 'rdoc', '~> 4.2'
7
+ gem 'coveralls', '~> 0.8.10', require: false
8
+
9
+ group :test do
10
+ gem 'memcache_mock'
11
+ gem 'mock_redis'
12
+ gem 'rspec', '~> 3.1'
13
+ gem 'rspec-core', '~> 3.1'
14
+ gem 'rspec-mocks', '~> 3.1'
15
+ gem 'simplecov', '~> 0.9', :require => false
16
+ gem 'simplecov-html', '~> 0.8', :require => false
17
+ end
18
+
19
+ gem 'jruby-openssl', :platform => :jruby
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-basecrm (1.0.0)
5
+ omniauth-oauth2 (~> 1.1)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ coveralls (0.8.19)
11
+ json (>= 1.8, < 3)
12
+ simplecov (~> 0.12.0)
13
+ term-ansicolor (~> 1.3)
14
+ thor (~> 0.19.1)
15
+ tins (~> 1.6)
16
+ diff-lcs (1.3)
17
+ docile (1.1.5)
18
+ faraday (0.11.0)
19
+ multipart-post (>= 1.2, < 3)
20
+ hashie (3.5.5)
21
+ json (2.0.3)
22
+ jwt (1.5.6)
23
+ memcache_mock (0.0.14)
24
+ mock_redis (0.16.0)
25
+ multi_json (1.12.1)
26
+ multi_xml (0.6.0)
27
+ multipart-post (2.0.0)
28
+ oauth2 (1.3.1)
29
+ faraday (>= 0.8, < 0.12)
30
+ jwt (~> 1.0)
31
+ multi_json (~> 1.3)
32
+ multi_xml (~> 0.5)
33
+ rack (>= 1.2, < 3)
34
+ omniauth (1.6.1)
35
+ hashie (>= 3.4.6, < 3.6.0)
36
+ rack (>= 1.6.2, < 3)
37
+ omniauth-oauth2 (1.4.0)
38
+ oauth2 (~> 1.0)
39
+ omniauth (~> 1.2)
40
+ rack (2.0.1)
41
+ rake (10.5.0)
42
+ rdoc (4.3.0)
43
+ rspec (3.5.0)
44
+ rspec-core (~> 3.5.0)
45
+ rspec-expectations (~> 3.5.0)
46
+ rspec-mocks (~> 3.5.0)
47
+ rspec-core (3.5.4)
48
+ rspec-support (~> 3.5.0)
49
+ rspec-expectations (3.5.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.5.0)
52
+ rspec-mocks (3.5.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.5.0)
55
+ rspec-support (3.5.0)
56
+ simplecov (0.12.0)
57
+ docile (~> 1.1.0)
58
+ json (>= 1.8, < 3)
59
+ simplecov-html (~> 0.10.0)
60
+ simplecov-html (0.10.0)
61
+ term-ansicolor (1.4.0)
62
+ tins (~> 1.0)
63
+ thor (0.19.4)
64
+ tins (1.13.2)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ coveralls (~> 0.8.10)
71
+ jruby-openssl
72
+ memcache_mock
73
+ mock_redis
74
+ omniauth-basecrm!
75
+ rake (~> 10.4)
76
+ rdoc (~> 4.2)
77
+ rspec (~> 3.1)
78
+ rspec-core (~> 3.1)
79
+ rspec-mocks (~> 3.1)
80
+ simplecov (~> 0.9)
81
+ simplecov-html (~> 0.8)
82
+
83
+ BUNDLED WITH
84
+ 1.14.6
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ # OmniAuth for BaseCrm
2
+ [![Build Status](https://travis-ci.org/berk/omniauth-basecrm.png?branch=master)](https://travis-ci.org/berk/omniauth-basecrm)
3
+ [![Coverage Status](https://coveralls.io/repos/berk/omniauth-basecrm/badge.png?branch=master)](https://coveralls.io/r/berk/omniauth-basecrm?branch=master)
4
+ [![Gem Version](https://badge.fury.io/rb/omniauth-basecrm.svg)](http://badge.fury.io/rb/omniauth-basecrm)
5
+
6
+ BaseCrm OAuth2 Strategy for OmniAuth 1.0.
7
+
8
+ Supports the OAuth 2.0 server-side. Read the BaseCrm docs for more details:
9
+
10
+ https://developers.getbase.com/docs/rest/articles/oauth2/introduction
11
+
12
+ ## Installing
13
+
14
+ Add to your `Gemfile`:
15
+
16
+ ```ruby
17
+ gem 'omniauth-basecrm'
18
+ ```
19
+
20
+ Then `bundle install`.
21
+
22
+ ## Usage
23
+
24
+ `OmniAuth::Strategies::BaseCrm` is simply a Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
25
+
26
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
27
+
28
+ ```ruby
29
+ Rails.application.config.middleware.use OmniAuth::Builder do
30
+ provider :basecrm, ENV['BASECRM_CLIENT_ID'], ENV['BASECRM_SECRET']
31
+ end
32
+ ```
33
+
34
+ ## Configuring
35
+
36
+ You can configure several options, which you pass in to the `provider` method via a `Hash`:
37
+
38
+ * `scope`: A space-separated list of scopes you want to request from the user. See the BaseCrm docs for a full list of available permissions.
39
+
40
+ For example, to request `profile` permission:
41
+
42
+ ```ruby
43
+ Rails.application.config.middleware.use OmniAuth::Builder do
44
+ provider :basecrm, ENV['BASECRM_CLIENT_ID'], ENV['BASECRM_SECRET'], :scope => 'profile'
45
+ end
46
+ ```
47
+
48
+ ## Authentication Hash
49
+
50
+ Here's an example *Authentication Hash* available in `request.env['omniauth.auth']`:
51
+
52
+ ```ruby
53
+ {"provider"=>"basecrm",
54
+ "uid"=>33333,
55
+ "info"=>
56
+ {
57
+ "name"=>"Name"},
58
+ "credentials"=>
59
+ {"token"=>
60
+ "dfkjadlfkjasdkjflaskdjfjsldflasjdflkasdjflaskdjf",
61
+ "refresh_token"=>"lkfkjasldjkflaskjdflkasjdlfjkasdljfk",
62
+ "expires_at"=>1489053154,
63
+ "expires"=>true},
64
+ "extra"=>
65
+ {"user"=>
66
+ {
67
+ "id"=>33333,
68
+ "name"=>"name",
69
+ "time_format"=>"12H",
70
+ "timezone"=>"UTC-08:00",
71
+ "created_at"=>"2015-05-12T01:01:15Z",
72
+ "updated_at"=>"2017-03-13T17:31:22Z",
73
+ "currency"=>"USD",
74
+ "phone"=>"+1 111-111-1111"}}}
75
+ ```
76
+
77
+ The precise information available may depend on the permissions which you request.
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/deploy ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ gem_name = 'omniauth-basecrm'
4
+
5
+ def execute(cmd)
6
+ puts "\n***************************************************************************\n"
7
+ puts "$ #{cmd}"
8
+ system(cmd)
9
+ end
10
+
11
+ def version_file_path
12
+ './lib/omniauth/base_crm/version.rb'
13
+ end
14
+
15
+ def version_file
16
+ @version_file ||= File.read(version_file_path)
17
+ end
18
+
19
+ def version
20
+ @version ||= version_file.match(/VERSION\s*=\s*'([^']*)'/)[1]
21
+ end
22
+
23
+ def increment_version
24
+ parts = version.split('.')
25
+ parts[2] = (parts[2].to_i + 1).to_s
26
+ new_version = parts.join('.')
27
+
28
+ version_file.gsub!(version, new_version)
29
+
30
+ File.open(version_file_path, 'w') do |file|
31
+ file.write(version_file)
32
+ end
33
+
34
+ @version_file = nil
35
+ @version = nil
36
+ end
37
+
38
+ puts "\nBuilding omniauth-basecrm-#{version}.gem..."
39
+
40
+ if ARGV.include?('release')
41
+ execute('git checkout master')
42
+ execute('git merge develop')
43
+ execute('git push')
44
+ end
45
+
46
+ execute('bundle exec rspec')
47
+ execute("gem build #{gem_name}.gemspec")
48
+ execute("gem install #{gem_name}-#{version}.gem --no-ri --no-rdoc")
49
+
50
+ if ARGV.include?('release')
51
+ execute("git tag #{version}")
52
+ execute('git push --tags')
53
+
54
+ execute("gem push #{gem_name}-#{version}.gem")
55
+
56
+ execute('git checkout develop')
57
+
58
+ increment_version
59
+
60
+ execute("git add #{version_file_path}")
61
+ execute("git commit -m 'Updated version to #{version}'")
62
+ execute('git push')
63
+ end
64
+
65
+
66
+
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+
3
+ gem 'rack', '~> 1.3.6'
4
+
5
+ gem 'sinatra'
6
+ gem 'omniauth-basecrm', :path => '../'
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ omniauth-basecrm (1.0.0)
5
+ omniauth-oauth2 (~> 1.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ addressable (2.2.6)
11
+ faraday (0.7.6)
12
+ addressable (~> 2.2)
13
+ multipart-post (~> 1.1)
14
+ rack (~> 1.1)
15
+ hashie (1.2.0)
16
+ multi_json (1.0.4)
17
+ multipart-post (1.1.4)
18
+ oauth2 (0.5.2)
19
+ faraday (~> 0.7)
20
+ multi_json (~> 1.0)
21
+ omniauth (1.0.2)
22
+ hashie (~> 1.2)
23
+ rack
24
+ omniauth-oauth2 (1.0.0)
25
+ oauth2 (~> 0.5.0)
26
+ omniauth (~> 1.0)
27
+ rack (1.3.6)
28
+ rack-protection (1.2.0)
29
+ rack
30
+ sinatra (1.3.2)
31
+ rack (~> 1.3, >= 1.3.6)
32
+ rack-protection (~> 1.2)
33
+ tilt (~> 1.3, >= 1.3.3)
34
+ tilt (1.3.3)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ omniauth-basecrm!
41
+ rack (~> 1.3.6)
42
+ sinatra
@@ -0,0 +1,31 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'omniauth-basecrm'
4
+
5
+ SCOPE = 'email'
6
+
7
+ class App < Sinatra::Base
8
+
9
+ get '/' do
10
+ redirect '/auth/basecrm'
11
+ end
12
+
13
+ get '/auth/:provider/callback' do
14
+ content_type 'application/json'
15
+ MultiJson.encode(request.env)
16
+ end
17
+
18
+ get '/auth/failure' do
19
+ content_type 'application/json'
20
+ MultiJson.encode(request.env)
21
+ end
22
+
23
+ end
24
+
25
+ use Rack::Session::Cookie
26
+
27
+ use OmniAuth::Builder do
28
+ provider :basecrm, ENV['APP_ID'], ENV['APP_SECRET'], :scope => SCOPE
29
+ end
30
+
31
+ run App.new
@@ -0,0 +1,22 @@
1
+ #--
2
+ # Permission is hereby granted, free of charge, to any person obtaining
3
+ # a copy of this software and associated documentation files (the
4
+ # "Software"), to deal in the Software without restriction, including
5
+ # without limitation the rights to use, copy, modify, merge, publish,
6
+ # distribute, sublicense, and/or sell copies of the Software, and to
7
+ # permit persons to whom the Software is furnished to do so, subject to
8
+ # the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be
11
+ # included in all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #++
21
+
22
+ require 'omniauth/base_crm'
@@ -0,0 +1,23 @@
1
+ #--
2
+ # Permission is hereby granted, free of charge, to any person obtaining
3
+ # a copy of this software and associated documentation files (the
4
+ # "Software"), to deal in the Software without restriction, including
5
+ # without limitation the rights to use, copy, modify, merge, publish,
6
+ # distribute, sublicense, and/or sell copies of the Software, and to
7
+ # permit persons to whom the Software is furnished to do so, subject to
8
+ # the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be
11
+ # included in all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #++
21
+
22
+ require 'omniauth/base_crm/version'
23
+ require 'omniauth/strategies/base_crm'
@@ -0,0 +1,26 @@
1
+ #--
2
+ # Permission is hereby granted, free of charge, to any person obtaining
3
+ # a copy of this software and associated documentation files (the
4
+ # "Software"), to deal in the Software without restriction, including
5
+ # without limitation the rights to use, copy, modify, merge, publish,
6
+ # distribute, sublicense, and/or sell copies of the Software, and to
7
+ # permit persons to whom the Software is furnished to do so, subject to
8
+ # the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be
11
+ # included in all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #++
21
+
22
+ module OmniAuth
23
+ module BaseCrm
24
+ VERSION = '1.0.0'
25
+ end
26
+ end
@@ -0,0 +1,67 @@
1
+ #--
2
+ # Permission is hereby granted, free of charge, to any person obtaining
3
+ # a copy of this software and associated documentation files (the
4
+ # "Software"), to deal in the Software without restriction, including
5
+ # without limitation the rights to use, copy, modify, merge, publish,
6
+ # distribute, sublicense, and/or sell copies of the Software, and to
7
+ # permit persons to whom the Software is furnished to do so, subject to
8
+ # the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be
11
+ # included in all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #++
21
+
22
+ require 'omniauth-oauth2'
23
+
24
+ module OmniAuth
25
+ module Strategies
26
+ class BaseCrm < OmniAuth::Strategies::OAuth2
27
+
28
+ option :client_options, {
29
+ :site => 'https://api.getbase.com',
30
+ :authorize_url => '/oauth2/authorize',
31
+ :token_url => '/oauth2/token'
32
+ }
33
+
34
+ option :name, 'basecrm'
35
+
36
+ option :authorize_options, [:scope]
37
+
38
+ uid { raw_info['id'] }
39
+
40
+ info do
41
+ prune!({
42
+ 'name' => raw_info['name']
43
+ })
44
+ end
45
+
46
+ extra do
47
+ { 'user' => prune!(raw_info) }
48
+ end
49
+
50
+ def raw_info
51
+ @raw_info ||= access_token.get('/v2/accounts/self').parsed['data']
52
+ end
53
+
54
+ private
55
+
56
+ def prune!(hash)
57
+ hash.delete_if do |_, value|
58
+ prune!(value) if value.is_a?(Hash)
59
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
60
+ end
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+
67
+ OmniAuth.config.add_camelization 'basecrm', 'BaseCrm'
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/base_crm/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-basecrm'
7
+ s.version = OmniAuth::BaseCrm::VERSION
8
+ s.authors = ['Michael Berkovich']
9
+ s.email = ['theiceberk@gmail.com']
10
+ s.summary = 'BaseCrm strategy for OmniAuth'
11
+ s.homepage = 'https://github.com/berk/omniauth-basecrm'
12
+ s.description = 'BaseCrm strategy for SSO using OmniAuth framework'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
+ s.require_paths = ['lib']
18
+ s.licenses = 'MIT-LICENSE'
19
+
20
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
21
+ end
@@ -0,0 +1,157 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-basecrm'
3
+
4
+ describe OmniAuth::Strategies::BaseCrm do
5
+ before :each do
6
+ @request = double('Request')
7
+ @request.stub(:params) { {} }
8
+ @request.stub(:cookies) { {} }
9
+
10
+ @client_id = 'abc'
11
+ @client_secret = 'def'
12
+ end
13
+
14
+ subject do
15
+ args = [@client_id, @client_secret, @options].compact
16
+ OmniAuth::Strategies::BaseCrm.new(nil, *args).tap do |strategy|
17
+ strategy.stub(:request) { @request }
18
+ end
19
+ end
20
+
21
+ it_should_behave_like 'an oauth2 strategy'
22
+
23
+ describe '#client' do
24
+ it 'has correct site' do
25
+ subject.client.site.should eq('https://api.getbase.com')
26
+ end
27
+
28
+ it 'has correct authorize url' do
29
+ subject.client.options[:authorize_url].should eq('/oauth2/authorize')
30
+ end
31
+
32
+ it 'has correct token url' do
33
+ subject.client.options[:token_url].should eq('/oauth2/token')
34
+ end
35
+ end
36
+
37
+ describe '#uid' do
38
+ before :each do
39
+ subject.stub(:raw_info) { { 'id' => '123' } }
40
+ end
41
+
42
+ it 'returns the id from raw_info' do
43
+ subject.uid.should eq('123')
44
+ end
45
+ end
46
+
47
+ describe '#info' do
48
+ before :each do
49
+ @raw_info ||= { 'name' => 'Alex' }
50
+ subject.stub(:raw_info) { @raw_info }
51
+ end
52
+
53
+ context 'when optional data is not present in raw info' do
54
+ it 'has no email key' do
55
+ subject.info.should_not have_key('email')
56
+ end
57
+ end
58
+
59
+ context 'when data is present in raw info' do
60
+ it 'returns first name' do
61
+ subject.info['name'].should eq('Alex')
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#raw_info' do
67
+ before :each do
68
+ @access_token = double('OAuth2::AccessToken')
69
+ subject.stub(:access_token) { @access_token }
70
+ end
71
+
72
+ it 'performs a GET to /v2/accounts/self' do
73
+ @access_token.stub(:get) { double('OAuth2::Response').as_null_object }
74
+ @access_token.should_receive(:get).with('/v2/accounts/self')
75
+ subject.raw_info
76
+ end
77
+
78
+ it 'returns a Hash' do
79
+ @access_token.stub(:get).with('/v2/accounts/self') do
80
+ raw_response = double('Faraday::Response')
81
+ raw_response.stub(:body) { '{"data": { "ohai": "thar" }}' }
82
+ raw_response.stub(:status) { 200 }
83
+ raw_response.stub(:headers) { { 'Content-Type' => 'application/json' } }
84
+ OAuth2::Response.new(raw_response)
85
+ end
86
+ subject.raw_info.should be_a(Hash)
87
+ subject.raw_info['ohai'].should eq('thar')
88
+ end
89
+ end
90
+
91
+ describe '#credentials' do
92
+ before :each do
93
+ @access_token = double('OAuth2::AccessToken')
94
+ @access_token.stub(:token)
95
+ @access_token.stub(:expires?)
96
+ @access_token.stub(:expires_at)
97
+ @access_token.stub(:refresh_token)
98
+ subject.stub(:access_token) { @access_token }
99
+ end
100
+
101
+ it 'returns a Hash' do
102
+ subject.credentials.should be_a(Hash)
103
+ end
104
+
105
+ it 'returns the token' do
106
+ @access_token.stub(:token) { '123' }
107
+ subject.credentials['token'].should eq('123')
108
+ end
109
+
110
+ it 'returns the expiry status' do
111
+ @access_token.stub(:expires?) { true }
112
+ subject.credentials['expires'].should eq(true)
113
+
114
+ @access_token.stub(:expires?) { false }
115
+ subject.credentials['expires'].should eq(false)
116
+ end
117
+
118
+ it 'returns the refresh token and expiry time when expiring' do
119
+ ten_mins_from_now = (Time.now + 600).to_i
120
+ @access_token.stub(:expires?) { true }
121
+ @access_token.stub(:refresh_token) { '321' }
122
+ @access_token.stub(:expires_at) { ten_mins_from_now }
123
+ subject.credentials['refresh_token'].should eq('321')
124
+ subject.credentials['expires_at'].should eq(ten_mins_from_now)
125
+ end
126
+
127
+ it 'does not return the refresh token when it is nil and expiring' do
128
+ @access_token.stub(:expires?) { true }
129
+ @access_token.stub(:refresh_token) { nil }
130
+ subject.credentials['refresh_token'].should be_nil
131
+ subject.credentials.should_not have_key('refresh_token')
132
+ end
133
+
134
+ it 'does not return the refresh token when not expiring' do
135
+ @access_token.stub(:expires?) { false }
136
+ @access_token.stub(:refresh_token) { 'XXX' }
137
+ subject.credentials['refresh_token'].should be_nil
138
+ subject.credentials.should_not have_key('refresh_token')
139
+ end
140
+ end
141
+
142
+ describe '#extra' do
143
+ before :each do
144
+ @raw_info = { 'name' => 'Fred Smith' }
145
+ subject.stub(:raw_info) { @raw_info }
146
+ end
147
+
148
+ it 'returns a Hash' do
149
+ subject.extra.should be_a(Hash)
150
+ end
151
+
152
+ it 'contains raw info' do
153
+ subject.extra.should eq({ 'user' => @raw_info })
154
+ end
155
+ end
156
+
157
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -0,0 +1,23 @@
1
+ # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
+ shared_examples 'an oauth2 strategy' do
3
+ describe '#client' do
4
+ it 'should be initialized with symbolized client_options' do
5
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
6
+ subject.client.options[:authorize_url].should == 'https://example.com'
7
+ end
8
+ end
9
+
10
+ describe '#token_params' do
11
+ it 'should include any authorize params passed in the :authorize_params option' do
12
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
13
+ subject.token_params['foo'].should eq('bar')
14
+ subject.token_params['baz'].should eq('zip')
15
+ end
16
+
17
+ it 'should include top-level options that are marked as :authorize_options' do
18
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
19
+ subject.token_params['scope'].should eq('bar')
20
+ subject.token_params['foo'].should eq('baz')
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-basecrm
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Berkovich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ description: BaseCrm strategy for SSO using OmniAuth framework
28
+ email:
29
+ - theiceberk@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".coveralls.yml"
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".ruby-version"
38
+ - ".travis.yml"
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE
42
+ - README.md
43
+ - Rakefile
44
+ - deploy
45
+ - example/Gemfile
46
+ - example/Gemfile.lock
47
+ - example/config.ru
48
+ - lib/omniauth-basecrm.rb
49
+ - lib/omniauth/base_crm.rb
50
+ - lib/omniauth/base_crm/version.rb
51
+ - lib/omniauth/strategies/base_crm.rb
52
+ - omniauth-basecrm.gemspec
53
+ - spec/omniauth/strategies/base_crm_spec.rb
54
+ - spec/spec_helper.rb
55
+ - spec/support/shared_examples.rb
56
+ homepage: https://github.com/berk/omniauth-basecrm
57
+ licenses:
58
+ - MIT-LICENSE
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.5
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: BaseCrm strategy for OmniAuth
80
+ test_files:
81
+ - spec/omniauth/strategies/base_crm_spec.rb
82
+ - spec/spec_helper.rb
83
+ - spec/support/shared_examples.rb