omniauth-exvo 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ coverage/*
5
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-exvo.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright © 2011-2012 Exvo.com Development BV
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.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # OmniAuth Exvo
2
+
3
+ This gem contains the official Exvo strategy for OmniAuth 1.0.
4
+
5
+ It depends on the [exvo_helpers](https://github.com/Exvo/exvo_helpers) gem for its configuration.
6
+
7
+ There is also [exvo-auth](https://github.com/Exvo/exvo_auth) gem, which provides additional helper methods, which make both users and app authorizations at Exvo easier.
8
+
9
+
10
+ ## Installation
11
+
12
+ Add to your `Gemfile`:
13
+
14
+ ```ruby
15
+ gem 'omniauth-exvo'
16
+ ```
17
+
18
+ Then `bundle install`.
19
+
20
+
21
+ ## Basic usage
22
+
23
+ ```ruby
24
+ use OmniAuth::Builder do
25
+ provider :exvo, ENV['AUTH_CLIENT_ID'], ENV['AUTH_CLIENT_SECRET']
26
+ end
27
+ ```
28
+
29
+
30
+
31
+ Copyright © 2011-2012 Exvo.com Development BV, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require 'omniauth-exvo/version'
2
+ require 'omniauth/strategies/exvo'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Exvo
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,84 @@
1
+ require 'omniauth-oauth2'
2
+ require 'exvo_helpers'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Exvo < OmniAuth::Strategies::OAuth2
7
+
8
+ option :name, 'exvo'
9
+
10
+ option :client_options, {
11
+ :site => ::Exvo::Helpers.auth_uri,
12
+ :token_url => ::Exvo::Helpers.auth_uri + '/oauth/access_token'
13
+ }
14
+
15
+ def request_phase
16
+ options[:scope] = request["scope"] if request["scope"]
17
+ options[:state] = request["state"] if request["state"]
18
+ options[:x_sign_up] = request["x_sign_up"] if request["x_sign_up"]
19
+ super
20
+ end
21
+
22
+ def callback_phase
23
+ set_failure_handler
24
+ super
25
+ end
26
+
27
+ def callback_key
28
+ '_callback'
29
+ end
30
+
31
+ def callback_url
32
+ if interactive?
33
+ super
34
+ else
35
+ super + "?" + Rack::Utils.build_query(callback_key => request[callback_key])
36
+ end
37
+ end
38
+
39
+ def interactive?
40
+ !non_interactive?
41
+ end
42
+
43
+ def non_interactive?
44
+ !!request[callback_key]
45
+ end
46
+
47
+ uid { raw_info['id'] }
48
+
49
+ info do
50
+ {
51
+ 'nickname' => raw_info['nickname'],
52
+ 'email' => raw_info['email']
53
+ }
54
+ end
55
+
56
+ extra do
57
+ {
58
+ :raw_info => raw_info
59
+ }
60
+ end
61
+
62
+ def raw_info
63
+ access_token.options[:mode] = :query
64
+ access_token.options[:param_name] = :access_token
65
+ @raw_info ||= access_token.get('/user.json').parsed
66
+ end
67
+
68
+ def set_failure_handler
69
+ OmniAuth.config.on_failure =
70
+ if interactive?
71
+ Proc.new do |env|
72
+ message_key = env['omniauth.error.type']
73
+ new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
74
+ [302, { 'Location' => new_path, 'Content-Type'=> 'text/html' }, []]
75
+ end
76
+ else
77
+ OmniAuth.config.on_failure = Proc.new do |env|
78
+ [401, { 'Content-Type' => 'application/javascript' }, [MultiJson.encode(:error => env['omniauth.error.type'])]]
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-exvo/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "omniauth-exvo"
7
+ gem.version = Omniauth::Exvo::VERSION
8
+ gem.authors = ["Paweł Gościcki"]
9
+ gem.email = ["pawel.goscicki@gmail.com"]
10
+ gem.homepage = "https://github.com/Exvo/omniauth-exvo/"
11
+ gem.summary = "OmniAuth strategy for Exvo"
12
+ gem.description = "OmniAuth strategy for Exvo"
13
+
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_dependency 'omniauth', '~> 1.0'
20
+ gem.add_dependency 'omniauth-oauth2', '~> 1.0'
21
+ gem.add_dependency 'exvo_helpers', '~> 0.2'
22
+
23
+ gem.add_development_dependency 'rspec', '>= 2.8'
24
+ gem.add_development_dependency 'rack-test'
25
+ gem.add_development_dependency 'webmock'
26
+
27
+ gem.add_development_dependency 'guard', ['~> 1.0']
28
+ gem.add_development_dependency 'guard-rspec', ['>= 0.6.0']
29
+ gem.add_development_dependency "rb-fsevent"
30
+ gem.add_development_dependency "rb-inotify"
31
+
32
+ gem.add_development_dependency "simplecov"
33
+ gem.add_development_dependency "simplecov-rcov"
34
+ end
@@ -0,0 +1,158 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Exvo do
4
+
5
+ attr_accessor :app
6
+
7
+ def set_app!
8
+ self.app = Rack::Builder.app do
9
+ use Rack::Session::Cookie
10
+ use OmniAuth::Strategies::Exvo
11
+ run lambda { |env| [200, {'env' => env}, ['Hello!']] }
12
+ end
13
+ end
14
+
15
+ subject do
16
+ OmniAuth::Strategies::Exvo.new(nil, @options || {})
17
+ end
18
+
19
+ it_should_behave_like 'an oauth2 strategy'
20
+
21
+ describe '#client' do
22
+ it 'should have the correct Exvo Auth site' do
23
+ subject.client.site.should eq('https://auth.exvo.com')
24
+ end
25
+
26
+ it 'should have the correct authorization url' do
27
+ subject.client.options[:authorize_url].should eq('/oauth/authorize')
28
+ end
29
+
30
+ it 'should have the correct token url' do
31
+ subject.client.options[:token_url].should match(/\/oauth\/access_token$/)
32
+ end
33
+ end
34
+
35
+ describe '#callback_key' do
36
+ specify { subject.callback_key.should match(/callback/) }
37
+ end
38
+
39
+ describe '#callback_path' do
40
+ its(:callback_path) { should eq('/auth/exvo/callback') }
41
+ end
42
+
43
+ describe '#callback_url' do
44
+ before do
45
+ subject.request.should_receive(:url).and_return('https://auth.exvo.com')
46
+ subject.should_receive(:script_name).and_return('')
47
+ end
48
+
49
+ it 'should have the correct callback url' do
50
+ subject.should_receive(:interactive?).and_return(true)
51
+ subject.callback_url.should eq('https://auth.exvo.com/auth/exvo/callback')
52
+ end
53
+
54
+ it 'should include _callback param if it is passed in request' do
55
+ subject.should_receive(:interactive?).and_return(false)
56
+ subject.request.should_receive(:[]).with('_callback').and_return('123')
57
+ subject.callback_url.should eq('https://auth.exvo.com/auth/exvo/callback?_callback=123')
58
+ end
59
+ end
60
+
61
+ describe '#interactive? and #non_interactive? return false and true, respectively, if request has callback key' do
62
+ before do
63
+ subject.request.should_receive(:[]).with('_callback').and_return('123')
64
+ end
65
+
66
+ it { should_not be_interactive }
67
+ it { should be_non_interactive }
68
+ end
69
+
70
+ describe '#uid' do
71
+ it 'returns the uid from raw_info' do
72
+ subject.stub(:raw_info).and_return({ 'id' => '123' })
73
+ subject.uid.should eq('123')
74
+ end
75
+ end
76
+
77
+ describe '#info' do
78
+ before :each do
79
+ subject.stub(:raw_info).and_return({ 'id' => '123', 'nickname' => 'Pawel', 'email' => 'some@email.com' })
80
+ end
81
+
82
+ it 'returns the nickname' do
83
+ subject.info['nickname'].should eq('Pawel')
84
+ end
85
+
86
+ it 'returns the email' do
87
+ subject.info['email'].should eq('some@email.com')
88
+ end
89
+ end
90
+
91
+ describe '#extra' do
92
+ let(:extra) { { 'language' => 'en' } }
93
+
94
+ it 'returns a hash of extra information' do
95
+ subject.stub(:raw_info).and_return(extra)
96
+ subject.extra.should eq({ :raw_info => extra })
97
+ end
98
+ end
99
+
100
+ describe '#credentials' do
101
+ before :each do
102
+ @access_token = double('OAuth2::AccessToken')
103
+ @access_token.stub(:token).and_return('123')
104
+ @access_token.stub(:expires?).and_return(false)
105
+ subject.stub(:access_token).and_return(@access_token)
106
+ end
107
+
108
+ specify { subject.credentials.should be_a(Hash) }
109
+
110
+ specify { subject.credentials['token'].should eq('123') }
111
+
112
+ specify { subject.credentials['expires'].should eq(false) }
113
+ end
114
+
115
+ describe '#request_phase' do
116
+ before do
117
+ set_app!
118
+ end
119
+
120
+ it 'redirects to auth app with a callback param' do
121
+ get '/auth/exvo'
122
+ last_response.should be_redirect
123
+
124
+ follow_redirect!
125
+ last_request.url.should match(/^https:\/\/auth\.exvo\.com\/.+callback$/)
126
+ end
127
+ end
128
+
129
+ describe '#set_failure_handler' do
130
+ let(:env) { { 'omniauth.error.type' => 'invalid_credentials', 'SCRIPT_NAME' => 'http://example.com' } }
131
+ let(:failure) { OmniAuth.config.on_failure.call(env) }
132
+
133
+ context "interactive" do
134
+ before do
135
+ subject.should_receive(:interactive?).and_return(true)
136
+ subject.set_failure_handler
137
+ end
138
+
139
+ it 'sets a redirect Rack response array' do
140
+ failure[0].should eq(302)
141
+ failure[1]['Location'].should match(/^http:\/\/example.com\/auth\/failure/)
142
+ end
143
+ end
144
+
145
+ context "non_interactive" do
146
+ before do
147
+ subject.should_receive(:interactive?).and_return(false)
148
+ subject.set_failure_handler
149
+ end
150
+
151
+ it 'sets an unauthorized Rack response array' do
152
+ failure[0].should eq(401)
153
+ failure[2][0].should match(/invalid_credentials/)
154
+ end
155
+ end
156
+ end
157
+
158
+ end
@@ -0,0 +1,18 @@
1
+ require 'simplecov'
2
+ require 'simplecov-rcov'
3
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
4
+ SimpleCov.start
5
+
6
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $:.unshift(File.dirname(__FILE__))
8
+
9
+ require 'rack/test'
10
+ require 'omniauth-exvo'
11
+
12
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
13
+
14
+ RSpec.configure do |config|
15
+ config.mock_with :rspec
16
+ config.include Rack::Test::Methods
17
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
18
+ end
@@ -0,0 +1,38 @@
1
+ shared_examples 'an oauth2 strategy' do
2
+
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 '#authorize_params' do
11
+ it 'should include any authorize params passed in the :authorize_params option' do
12
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
13
+ subject.authorize_params['foo'].should eq('bar')
14
+ subject.authorize_params['baz'].should eq('zip')
15
+ end
16
+
17
+ it 'should include top-level options that are marked as :authorize_options' do
18
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
19
+ subject.authorize_params['scope'].should eq('bar')
20
+ subject.authorize_params['foo'].should eq('baz')
21
+ end
22
+ end
23
+
24
+ describe '#token_params' do
25
+ it 'should include any token params passed in the :token_params option' do
26
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
27
+ subject.token_params['foo'].should eq('bar')
28
+ subject.token_params['baz'].should eq('zip')
29
+ end
30
+
31
+ it 'should include top-level options that are marked as :token_options' do
32
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
33
+ subject.token_params['scope'].should eq('bar')
34
+ subject.token_params['foo'].should eq('baz')
35
+ end
36
+ end
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,253 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-exvo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "Pawe\xC5\x82 Go\xC5\x9Bcicki"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-26 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: omniauth
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 0
33
+ version: "1.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: omniauth-oauth2
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 15
45
+ segments:
46
+ - 1
47
+ - 0
48
+ version: "1.0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: exvo_helpers
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 15
60
+ segments:
61
+ - 0
62
+ - 2
63
+ version: "0.2"
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: rspec
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 19
75
+ segments:
76
+ - 2
77
+ - 8
78
+ version: "2.8"
79
+ type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: rack-test
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: webmock
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ type: :development
108
+ version_requirements: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ name: guard
111
+ prerelease: false
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ hash: 15
118
+ segments:
119
+ - 1
120
+ - 0
121
+ version: "1.0"
122
+ type: :development
123
+ version_requirements: *id007
124
+ - !ruby/object:Gem::Dependency
125
+ name: guard-rspec
126
+ prerelease: false
127
+ requirement: &id008 !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 7
133
+ segments:
134
+ - 0
135
+ - 6
136
+ - 0
137
+ version: 0.6.0
138
+ type: :development
139
+ version_requirements: *id008
140
+ - !ruby/object:Gem::Dependency
141
+ name: rb-fsevent
142
+ prerelease: false
143
+ requirement: &id009 !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ type: :development
153
+ version_requirements: *id009
154
+ - !ruby/object:Gem::Dependency
155
+ name: rb-inotify
156
+ prerelease: false
157
+ requirement: &id010 !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
165
+ version: "0"
166
+ type: :development
167
+ version_requirements: *id010
168
+ - !ruby/object:Gem::Dependency
169
+ name: simplecov
170
+ prerelease: false
171
+ requirement: &id011 !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ hash: 3
177
+ segments:
178
+ - 0
179
+ version: "0"
180
+ type: :development
181
+ version_requirements: *id011
182
+ - !ruby/object:Gem::Dependency
183
+ name: simplecov-rcov
184
+ prerelease: false
185
+ requirement: &id012 !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ hash: 3
191
+ segments:
192
+ - 0
193
+ version: "0"
194
+ type: :development
195
+ version_requirements: *id012
196
+ description: OmniAuth strategy for Exvo
197
+ email:
198
+ - pawel.goscicki@gmail.com
199
+ executables: []
200
+
201
+ extensions: []
202
+
203
+ extra_rdoc_files: []
204
+
205
+ files:
206
+ - .gitignore
207
+ - Gemfile
208
+ - MIT-LICENSE
209
+ - README.md
210
+ - Rakefile
211
+ - lib/omniauth-exvo.rb
212
+ - lib/omniauth-exvo/version.rb
213
+ - lib/omniauth/strategies/exvo.rb
214
+ - omniauth-exvo.gemspec
215
+ - spec/omniauth/strategies/exvo_spec.rb
216
+ - spec/spec_helper.rb
217
+ - spec/support/shared_examples.rb
218
+ has_rdoc: true
219
+ homepage: https://github.com/Exvo/omniauth-exvo/
220
+ licenses: []
221
+
222
+ post_install_message:
223
+ rdoc_options: []
224
+
225
+ require_paths:
226
+ - lib
227
+ required_ruby_version: !ruby/object:Gem::Requirement
228
+ none: false
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ hash: 3
233
+ segments:
234
+ - 0
235
+ version: "0"
236
+ required_rubygems_version: !ruby/object:Gem::Requirement
237
+ none: false
238
+ requirements:
239
+ - - ">="
240
+ - !ruby/object:Gem::Version
241
+ hash: 3
242
+ segments:
243
+ - 0
244
+ version: "0"
245
+ requirements: []
246
+
247
+ rubyforge_project:
248
+ rubygems_version: 1.3.7
249
+ signing_key:
250
+ specification_version: 3
251
+ summary: OmniAuth strategy for Exvo
252
+ test_files: []
253
+