surveymonkey-omniauth 1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f9d404166081d6bc7a8d74354a3917dd5c23e16937e6d74b45b5f9727276c0b1
4
+ data.tar.gz: 05e297f4fc6e5bf87825803b2eb519eddec10a388c2ec10f90db5678eb8fae4a
5
+ SHA512:
6
+ metadata.gz: 266fa0946b892e7331663cec12628606412edf5dd5986151c57769e02270c7b8a21b2913701ed74f7274a003f6c2b8f8ddd13abba67757124d33ef2e67167959
7
+ data.tar.gz: 579698b1e82c6af5c4449f2b3d62bce13ed1061052571d7dd792020b39d501b95250bff3c8d23b80c2387fed611611c4da01b58bb8853fa425ba967cf8f3afe6
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'omniauth-oauth2'
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ faraday (2.2.0)
5
+ faraday-net_http (~> 2.0)
6
+ ruby2_keywords (>= 0.0.4)
7
+ faraday-net_http (2.0.1)
8
+ hashie (5.0.0)
9
+ jwt (2.3.0)
10
+ multi_json (1.15.0)
11
+ multi_xml (0.6.0)
12
+ oauth2 (1.4.9)
13
+ faraday (>= 0.17.3, < 3.0)
14
+ jwt (>= 1.0, < 3.0)
15
+ multi_json (~> 1.3)
16
+ multi_xml (~> 0.5)
17
+ rack (>= 1.2, < 3)
18
+ omniauth (2.0.4)
19
+ hashie (>= 3.4.6)
20
+ rack (>= 1.6.2, < 3)
21
+ rack-protection
22
+ omniauth-oauth2 (1.7.2)
23
+ oauth2 (~> 1.4)
24
+ omniauth (>= 1.9, < 3)
25
+ rack (2.2.3)
26
+ rack-protection (2.2.0)
27
+ rack
28
+ ruby2_keywords (0.0.5)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ omniauth-oauth2
35
+
36
+ BUNDLED WITH
37
+ 2.2.22
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2022 Ahmad Ali
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Surveymonkey Strategy for OmniAuth
2
+
3
+ SurveyMonkey OAuth2 strategy for OmniAuth
4
+ ## Get Started
5
+ ```ruby
6
+ gem 'surveymonkey-omniauth'
7
+ ```
8
+ ## Usage
9
+
10
+ In your config/initializers/omniauth.rb:
11
+
12
+ OmniAuth.config.logger = Rails.logger
13
+ Rails.application.config.middleware.use OmniAuth::Builder do
14
+ provider :surveymonkey, api_key: SURVEYMONKEY_API_KEY, client_secret: SURVEYMONKEY_API_SECRET, client_id: SURVEYMONKEY_CLIENT_ID
15
+ end
16
+
17
+ Note that this differs from normal Omniauth configurations!
18
+ Note that this gem is an extended work on surveymonkey-with-omniauth gem
19
+
20
+ # License
21
+
22
+ Copyright (c) 2022 Ahmad Ali
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
25
+
26
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
27
+
28
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ desc "Build the gem"
4
+ task :build do
5
+ system "gem build surveymonkey-omniauth.gemspec"
6
+ end
7
+
8
+ desc "Build and release the gem"
9
+ task :release => :build do
10
+ system "gem push surveymonkey-omniauth-#{OmniAuth::Surveymonkey::VERSION}.gem"
11
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'surveymonkey-omniauth'
@@ -0,0 +1,103 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Surveymonkey < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_RESPONSE_TYPE = 'code'
7
+ DEFAULT_GRANT = 'authorization_code'
8
+ option :name, 'surveymonkey'
9
+
10
+ option :client_options, {
11
+ site: 'https://api.surveymonkey.net',
12
+ authorize_url: '/oauth/authorize',
13
+ token_url: '/oauth/token'
14
+ }
15
+
16
+ option :authorize_options, [:api_key, :client_id]
17
+
18
+ uid { raw_info['id'] }
19
+
20
+ info do
21
+ {
22
+ 'username' => raw_info['username'],
23
+ 'name' => [raw_info['first_name'], raw_info['last_name']].join(' '),
24
+ 'email' => raw_info['email']
25
+ }
26
+ end
27
+
28
+ def raw_info
29
+ @raw_info ||= access_token.get('/v3/users/me').parsed
30
+ end
31
+
32
+ def authorize_params
33
+ super.tap do |params|
34
+ params[:response_type] ||= DEFAULT_RESPONSE_TYPE
35
+ params[:client_id] = options[:client_id]
36
+ params[:api_key] = options[:api_key]
37
+ end
38
+ end
39
+
40
+ def build_access_token
41
+ verifier = request.params['code']
42
+ token = client.auth_code.get_token(verifier, token_params)
43
+ end
44
+
45
+ def callback_phase
46
+ options[:client_options][:token_url] = "/oauth/token?api_key=#{options[:api_key]}"
47
+ self.access_token = build_access_token
48
+ self.env['omniauth.auth'] = auth_hash
49
+ call_app!
50
+
51
+ rescue ::OAuth2::Error, CallbackError => e
52
+ fail!(:invalid_credentials, e)
53
+ rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
54
+ fail!(:timeout, e)
55
+ rescue ::SocketError => e
56
+ fail!(:failed_to_connect, e)
57
+ end
58
+
59
+ def token_params
60
+ super.tap do |params|
61
+ params[:grant_type] ||= DEFAULT_GRANT
62
+ params[:client_id] = options[:client_id]
63
+ params[:client_secret] = options[:client_secret]
64
+ params[:redirect_uri] = callback_url
65
+ end
66
+ end
67
+
68
+ def callback_url
69
+ full_host + script_name + callback_path
70
+ end
71
+
72
+ def full_host
73
+ case OmniAuth.config.full_host
74
+ when String
75
+ OmniAuth.config.full_host
76
+ when Proc
77
+ OmniAuth.config.full_host.call(env)
78
+ else
79
+ if request.scheme && request.url.match(URI::ABS_URI)
80
+ uri = URI.parse(request.url.gsub(/\?.*$/, ''))
81
+ uri.path = ''
82
+ uri.scheme = 'https' if ssl?
83
+ uri.to_s
84
+ end
85
+ end
86
+ end
87
+
88
+ def script_name
89
+ @env['SCRIPT_NAME'] || ''
90
+ end
91
+
92
+ def callback_path
93
+ @callback_path ||= begin
94
+ path = options[:callback_path] if options[:callback_path].is_a?(String)
95
+ path ||= current_path if options[:callback_path].respond_to?(:call) && options[:callback_path].call(env)
96
+ path ||= custom_path(:request_path)
97
+ path ||= "#{path_prefix}/#{name}/callback"
98
+ path
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Surveymonkey
3
+ VERSION = "1.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'omniauth/strategies/surveymonkey'
@@ -0,0 +1 @@
1
+ require "omniauth/surveymonkey"
@@ -0,0 +1,73 @@
1
+ require 'surveymonkey-omniauth'
2
+
3
+ describe OmniAuth::Strategies::Surveymonkey do
4
+ context 'with url context' do
5
+ subject do
6
+ OmniAuth::Strategies::Surveymonkey.new(nil, {})
7
+ end
8
+
9
+ describe '#client' do
10
+ it 'has correct surveymonkey api site' do
11
+ subject.options.client_options.site.should == ('https://api.surveymonkey.net')
12
+ end
13
+
14
+ it 'has correct access token path' do
15
+ subject.options.client_options.token_url.should == ('/oauth/token')
16
+ end
17
+
18
+ it 'has correct authorize url' do
19
+ subject.options.client_options.authorize_url.should == ('/oauth/authorize')
20
+ end
21
+ end
22
+
23
+ describe '#callback_path' do
24
+ it 'should have the correct callback path' do
25
+ subject.callback_path.should == ('/auth/surveymonkey/callback')
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'with auth info' do
31
+ subject do
32
+ args = ['client_id', 'secret']
33
+
34
+ OmniAuth::Strategies::Surveymonkey.new(nil, *args).tap do |strategy|
35
+ strategy.stub(:request) { @request }
36
+ end
37
+ end
38
+
39
+ describe '#uid' do
40
+ before do
41
+ subject.stub(:raw_info) do
42
+ { 'id' => '123' }
43
+ end
44
+ end
45
+
46
+ it 'returns the id from raw_info' do
47
+ subject.uid.should eq('123')
48
+ end
49
+ end
50
+
51
+ describe '#info' do
52
+ before do
53
+ subject.stub(:raw_info) do
54
+ {
55
+ 'username' => 'ahmad',
56
+ 'first_name' => 'Ahmad',
57
+ 'last_name' => 'Ali',
58
+ 'email' => 'ahmad.ali@sendoso.com'
59
+ }
60
+ end
61
+ end
62
+
63
+ context 'when optional data is present in raw info' do
64
+ it 'has all the expecting attributes' do
65
+ subject.info.keys.should eq(['username', 'name', 'email'])
66
+ subject.info['username'].should eq('ahmad')
67
+ subject.info['name'].should eq('Ahmad Ali')
68
+ subject.info['email'].should eq('ahmad.ali@sendoso.com')
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../lib/omniauth/surveymonkey/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.add_dependency 'omniauth'
5
+ gem.add_dependency 'oauth2'
6
+ gem.add_dependency 'omniauth-oauth2'
7
+
8
+ gem.add_development_dependency 'rspec', '~> 2.7'
9
+ gem.add_development_dependency 'rack-test'
10
+
11
+ gem.authors = ["Ahmad Ali"]
12
+ gem.email = ["ahmad.ali@sendoso.com"]
13
+ gem.description = %q{Survemonkey OAuth2 strategy for OmniAuth}
14
+ gem.summary = %q{Survemonkey OAuth2 strategy for OmniAuth}
15
+
16
+
17
+ gem.files = `git ls-files`.split("\n")
18
+ gem.test_files = `git ls-files spec/*`.split("\n")
19
+ gem.name = "surveymonkey-omniauth"
20
+ gem.require_paths = ["lib"]
21
+ gem.version = OmniAuth::Surveymonkey::VERSION
22
+ gem.homepage = "https://github.com/sendoso/omniauth-surveymonkey"
23
+ gem.license = 'MIT'
24
+ end
@@ -0,0 +1 @@
1
+ require 'surveymonkey-omniauth'
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: surveymonkey-omniauth
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Ahmad Ali
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: omniauth-oauth2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Survemonkey OAuth2 strategy for OmniAuth
84
+ email:
85
+ - ahmad.ali@sendoso.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - init.rb
96
+ - lib/omniauth/strategies/surveymonkey.rb
97
+ - lib/omniauth/surveymonkey.rb
98
+ - lib/omniauth/surveymonkey/version.rb
99
+ - lib/surveymonkey-omniauth.rb
100
+ - spec/omniauth/strategies/surveymonkey_spec.rb
101
+ - surveymonkey-omniauth.gemspec
102
+ - surveymonkey-omniauth.rb
103
+ homepage: https://github.com/sendoso/omniauth-surveymonkey
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.2.22
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Survemonkey OAuth2 strategy for OmniAuth
126
+ test_files:
127
+ - spec/omniauth/strategies/surveymonkey_spec.rb