omniauth-surveymonkey-oauth2 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca9675395baa77435377604b8a6545d318070734
4
+ data.tar.gz: 8607cf1b0fd53ff5f6ad2e379f2793f88703b6bd
5
+ SHA512:
6
+ metadata.gz: 58874d7ba3eb487382aeb8e10b65bde2295fe229ec411d3bf2672e57d39d2d8dfc3e578df80a6e813ef2602b148109868e82ec22d9a337626d7b60eacf97226d
7
+ data.tar.gz: b7b0c3b23f9857d177d87b95c37fdcdf16eabd5c000efa794d82fd5ae5ba89c15e1f588baa141c2aab3108cf08f08b06474dd98a9f4da214e112e4d5b2b8bc27
@@ -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-surveymonkey-oauth2 (1.0.1)
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-surveymonkey-oauth2!
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,80 @@
1
+ # OmniAuth for SurveyMonkey
2
+ [![Build Status](https://travis-ci.org/berk/omniauth-surveymonkey-oauth2.png?branch=master)](https://travis-ci.org/berk/omniauth-surveymonkey-oauth2)
3
+ [![Coverage Status](https://coveralls.io/repos/berk/omniauth-surveymonkey-oauth2/badge.png?branch=master)](https://coveralls.io/r/berk/omniauth-surveymonkey-oauth2?branch=master)
4
+ [![Gem Version](https://badge.fury.io/rb/omniauth-surveymonkey-oauth2.svg)](http://badge.fury.io/rb/omniauth-surveymonkey-oauth2)
5
+
6
+ SurveyMonkey OAuth2 Strategy for OmniAuth 1.0.
7
+
8
+ Supports the OAuth 2.0 server-side. Read the SurveyMonkey docs for more details:
9
+
10
+ https://developer.surveymonkey.com/api/v3/#authentication
11
+
12
+ ## Installing
13
+
14
+ Add to your `Gemfile`:
15
+
16
+ ```ruby
17
+ gem 'omniauth-surveymonkey-oauth2'
18
+ ```
19
+
20
+ Then `bundle install`.
21
+
22
+ ## Usage
23
+
24
+ `OmniAuth::Strategies::SurveyMonkey` 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 :surveymonkey, ENV['SURVEYMONKEY_CLIENT_ID'], ENV['SURVEYMONKEY_SECRET']
31
+ end
32
+ ```
33
+
34
+ ## Authentication Hash
35
+
36
+ Here's an example *Authentication Hash* available in `request.env['omniauth.auth']`:
37
+
38
+ ```ruby
39
+ {"provider"=>"surveymonkey",
40
+ "uid"=>"23421341234",
41
+ "info"=>
42
+ {"username"=>"userx",
43
+ "account_type"=>"basic",
44
+ "email"=>"user@domain.com",
45
+ "id"=>"234123"},
46
+ "credentials"=>
47
+ {"token"=>
48
+ "hBD-ASxyjkbtY-a89sdf9a78sd9f87as9d87fa98s7df9a78sdf987asd.J8OeyCHPcRx4y1R.Q.f2O5rmpBpgxl28hxkImYihxZvKGsdZh",
49
+ "expires"=>false},
50
+ "extra"=>
51
+ {"username"=>"userx",
52
+ "scopes"=>
53
+ {"available"=>
54
+ ["users_read",
55
+ "surveys_read",
56
+ "collectors_read",
57
+ "collectors_write",
58
+ "contacts_read",
59
+ "contacts_write",
60
+ "responses_read",
61
+ "webhooks_read",
62
+ "webhooks_write",
63
+ "library_read"],
64
+ "granted"=>
65
+ ["surveys_read",
66
+ "collectors_read",
67
+ "collectors_write",
68
+ "contacts_read",
69
+ "contacts_write",
70
+ "users_read"]},
71
+ "account_type"=>"basic",
72
+ "language"=>"en",
73
+ "email"=>"user@domain.com",
74
+ "href"=>"https://api.surveymonkey.net/v3/users/me",
75
+ "date_last_login"=>"2017-05-06T15:10:37.837000+00:00",
76
+ "date_created"=>"2016-07-23T00:02:00+00:00",
77
+ "id"=>"23421341234"}}
78
+ ```
79
+
80
+ 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-surveymonkey-oauth2'
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/survey_monkey/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-surveymonkey-oauth2-#{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-surveymonkey2', :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-surveymonkey2'
4
+
5
+ SCOPE = 'email'
6
+
7
+ class App < Sinatra::Base
8
+
9
+ get '/' do
10
+ redirect '/auth/surveymonkey'
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 :surveymonkey2, 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/survey_monkey'
@@ -0,0 +1,81 @@
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 SurveyMonkey < OmniAuth::Strategies::OAuth2
27
+
28
+ option :client_options, {
29
+ :site => 'https://api.surveymonkey.net',
30
+ :authorize_url => '/oauth/authorize',
31
+ :token_url => '/oauth/token'
32
+ }
33
+
34
+ option :name, 'surveymonkey'
35
+
36
+ option :access_token_options, {
37
+ :header_format => 'Bearer %s',
38
+ :param_name => 'access_token'
39
+ }
40
+
41
+ option :authorize_options, [:scope]
42
+
43
+ uid { raw_info['id'] }
44
+
45
+ info do
46
+ prune!(
47
+ 'username' => raw_info['username'],
48
+ 'account_type' => raw_info['account_type'],
49
+ 'email' => raw_info['email'],
50
+ 'id' => raw_info['id']
51
+ )
52
+ end
53
+
54
+ extra do
55
+ prune!(raw_info)
56
+ end
57
+
58
+ def raw_info
59
+ @raw_info ||= access_token.get('/v3/users/me').parsed
60
+ end
61
+
62
+ def authorize_params
63
+ super.tap do |params|
64
+ params.merge!(:state => request.params['state']) if request.params['state']
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def prune!(hash)
71
+ hash.delete_if do |_, value|
72
+ prune!(value) if value.is_a?(Hash)
73
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
74
+ end
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+
81
+ OmniAuth.config.add_camelization 'surveymonkey', 'SurveyMonkey'
@@ -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/survey_monkey/version'
23
+ require 'omniauth/strategies/survey_monkey'
@@ -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 SurveyMonkey
24
+ VERSION = '1.0.1'
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/survey_monkey/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-surveymonkey-oauth2'
7
+ s.version = OmniAuth::SurveyMonkey::VERSION
8
+ s.authors = ['Michael Berkovich']
9
+ s.email = ['theiceberk@gmail.com']
10
+ s.summary = 'SurveyMonkey strategy for OmniAuth'
11
+ s.homepage = 'https://github.com/berk/omniauth-surveymonkey-oauth2'
12
+ s.description = 'SurveyMonkey 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,128 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-surveymonkey-oauth2'
3
+
4
+ describe OmniAuth::Strategies::SurveyMonkey 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::SurveyMonkey.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.surveymonkey.net')
26
+ end
27
+
28
+ it 'has correct authorize url' do
29
+ subject.client.options[:authorize_url].should eq('/oauth/authorize')
30
+ end
31
+
32
+ it 'has correct token url' do
33
+ subject.client.options[:token_url].should eq('/oauth/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 ||= { 'username' => '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['username'].should eq('Alex')
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#credentials' do
67
+ before :each do
68
+ @access_token = double('OAuth2::AccessToken')
69
+ @access_token.stub(:token)
70
+ @access_token.stub(:expires?)
71
+ @access_token.stub(:expires_at)
72
+ @access_token.stub(:refresh_token)
73
+ subject.stub(:access_token) { @access_token }
74
+ end
75
+
76
+ it 'returns a Hash' do
77
+ subject.credentials.should be_a(Hash)
78
+ end
79
+
80
+ it 'returns the token' do
81
+ @access_token.stub(:token) { '123' }
82
+ subject.credentials['token'].should eq('123')
83
+ end
84
+
85
+ it 'returns the expiry status' do
86
+ @access_token.stub(:expires?) { true }
87
+ subject.credentials['expires'].should eq(true)
88
+
89
+ @access_token.stub(:expires?) { false }
90
+ subject.credentials['expires'].should eq(false)
91
+ end
92
+
93
+ it 'returns the refresh token and expiry time when expiring' do
94
+ ten_mins_from_now = (Time.now + 600).to_i
95
+ @access_token.stub(:expires?) { true }
96
+ @access_token.stub(:refresh_token) { '321' }
97
+ @access_token.stub(:expires_at) { ten_mins_from_now }
98
+ subject.credentials['refresh_token'].should eq('321')
99
+ subject.credentials['expires_at'].should eq(ten_mins_from_now)
100
+ end
101
+
102
+ it 'does not return the refresh token when it is nil and expiring' do
103
+ @access_token.stub(:expires?) { true }
104
+ @access_token.stub(:refresh_token) { nil }
105
+ subject.credentials['refresh_token'].should be_nil
106
+ subject.credentials.should_not have_key('refresh_token')
107
+ end
108
+
109
+ it 'does not return the refresh token when not expiring' do
110
+ @access_token.stub(:expires?) { false }
111
+ @access_token.stub(:refresh_token) { 'XXX' }
112
+ subject.credentials['refresh_token'].should be_nil
113
+ subject.credentials.should_not have_key('refresh_token')
114
+ end
115
+ end
116
+
117
+ describe '#extra' do
118
+ before :each do
119
+ @raw_info = { 'name' => 'Fred Smith' }
120
+ subject.stub(:raw_info) { @raw_info }
121
+ end
122
+
123
+ it 'returns a Hash' do
124
+ subject.extra.should be_a(Hash)
125
+ end
126
+ end
127
+
128
+ 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-surveymonkey-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Berkovich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-06 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: SurveyMonkey 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-surveymonkey-oauth2.rb
49
+ - lib/omniauth/strategies/survey_monkey.rb
50
+ - lib/omniauth/survey_monkey.rb
51
+ - lib/omniauth/survey_monkey/version.rb
52
+ - omniauth-surveymonkey-oauth2.gemspec
53
+ - spec/omniauth/strategies/surveymonkey_spec.rb
54
+ - spec/spec_helper.rb
55
+ - spec/support/shared_examples.rb
56
+ homepage: https://github.com/berk/omniauth-surveymonkey-oauth2
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: SurveyMonkey strategy for OmniAuth
80
+ test_files:
81
+ - spec/omniauth/strategies/surveymonkey_spec.rb
82
+ - spec/spec_helper.rb
83
+ - spec/support/shared_examples.rb