omniauth-accounts 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODA3YjFiYTMxODIwZjU1NDQxN2RjZGZiZjY2MjBjZmU1MmUwY2JhOQ==
5
+ data.tar.gz: !binary |-
6
+ ODc3ZDE1YzYyYjE0Y2NhZmE3NWEyNjQ5MTlkNTFiNTBhNmMyYjM5MA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZDg0YzYxNDAxNzUzYjA0ZTEyM2UzMmQwNTQzYWJhZDZkZTc2MjM4N2JhNGE2
10
+ MWQzY2UxYTVjNmM3MGU2YTEwMWYzNzgwNDE1ZjlkMmY0MTYwNWU0YWIzMjQ0
11
+ OTJjMDBmY2RiM2FlYzdjZjU4NjhlZjFkMmRlNjI5ZmRkOTJmNWQ=
12
+ data.tar.gz: !binary |-
13
+ ODFmOTFjNDJkMzZjYWQyYWYwYmMyNmYxMzE4NzFkNWVhOWY0ODJjY2U1YzMw
14
+ MDJhZDgwN2FlM2JjMjg5M2VjMDg0YzhjZGQ4ZWQ3NDhmNzRkZGFiNGU5OGE2
15
+ MGQ1Y2QwMzJmZGI1MDQ5YjNlNDFhMTNlMDczMmNhMDlkZDEwZTY=
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .powenv
19
+ .idea/
20
+ *.sublime-project
21
+ *.sublime-workspace
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@omniauth-accounts --create
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # OmniAuth Accounts Strategy
2
+
3
+ Strategy to authenticate via OAuth2 in OmniAuth.
4
+
5
+ Worked with some demo-projects:
6
+
7
+ - [provider-site](http://github.com/gambala/demo-sso-provider)
8
+ - [client-site](http://github.com/gambala/demo-sso-client)
9
+
10
+ ## Installation
11
+
12
+ Add to your `Gemfile`:
13
+
14
+ ```ruby
15
+ gem "omniauth-accounts"
16
+ ```
17
+
18
+ Then `bundle install`.
19
+
20
+ ## Usage
21
+
22
+ Here's an example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
23
+
24
+ ```ruby
25
+ Rails.application.config.middleware.use OmniAuth::Builder do
26
+ provider :accounts, ENV["ACCOUNTS_KEY"], ENV["ACCOUNTS_SECRET"]
27
+ end
28
+ ```
29
+
30
+ You can now access the OmniAuth Accounts URL: `/auth/accounts`
31
+
32
+ ## License
33
+
34
+ Copyright (c) 2012 by Josh Ellithorpe
35
+
36
+ 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:
37
+
38
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
39
+
40
+ 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,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Accounts
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'omniauth/strategies/accounts'
@@ -0,0 +1,44 @@
1
+ require 'omniauth-oauth2'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Accounts < OmniAuth::Strategies::OAuth2
7
+
8
+ option :name, "accounts"
9
+ option :client_options, {
10
+ :site => 'http://accounts.fromfuture.net',
11
+ :authorize_url => "/authorize",
12
+ :access_token_url => "/token"
13
+ }
14
+
15
+ uid{ raw_info['id'] }
16
+
17
+ info do
18
+ {
19
+ email: raw_info['email'],
20
+ name: raw_info['name'],
21
+ nickname: raw_info['nickname'],
22
+ first_name: raw_info['first_name'],
23
+ last_name: raw_info['last_name'],
24
+ image: raw_info['image'],
25
+ urls: raw_info['urls'],
26
+ location: raw_info['location'],
27
+ sex: raw_info['sex'],
28
+ born_date: raw_info['born_date']
29
+ }
30
+ end
31
+
32
+ extra do
33
+ {
34
+ 'raw_info' => raw_info
35
+ }
36
+ end
37
+
38
+ def raw_info
39
+ @raw_info ||= access_token.get('/get_info.json?access_token='+access_token.token+'&client='+access_token.client.id).parsed
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1 @@
1
+ require "omniauth/accounts"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth/accounts/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency 'omniauth', '~> 1.0'
6
+
7
+ gem.authors = ["Vitaliy Emeliyatsev"]
8
+ gem.email = ["gambala.rus@gmail.com"]
9
+ gem.description = %q{A Accounts from the Future oauth2 strategy for OmniAuth 1.0}
10
+ gem.summary = %q{A simple oauth 2.0 strategy}
11
+ gem.homepage = "https://github.com/gambala/omniauth-accounts"
12
+
13
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.name = "omniauth-accounts"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = OmniAuth::Accounts::VERSION
19
+
20
+ gem.add_runtime_dependency 'omniauth-oauth2'
21
+
22
+ gem.add_development_dependency 'rspec', '~> 2.6.0'
23
+ gem.add_development_dependency 'rake'
24
+ end
@@ -0,0 +1,219 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-accounts'
3
+
4
+ describe OmniAuth::Strategies::Accounts do
5
+ def app; lambda{|env| [200, {}, ["Hello."]]} end
6
+
7
+ before :each do
8
+ OmniAuth.config.test_mode = true
9
+ @request = double('Request')
10
+ @request.stub(:params) { {} }
11
+ @request.stub(:cookies) { {} }
12
+ @request.stub(:env) { {} }
13
+ end
14
+
15
+ after do
16
+ OmniAuth.config.test_mode = false
17
+ end
18
+
19
+ subject do
20
+ args = ['appid', 'secret', @options || {}].compact
21
+ OmniAuth::Strategies::Accounts.new(app, *args).tap do |strategy|
22
+ strategy.stub(:request) { @request }
23
+ end
24
+ end
25
+
26
+ it_should_behave_like 'an oauth2 strategy'
27
+
28
+ describe '#client' do
29
+ it 'has correct Google site' do
30
+ subject.client.site.should eq('https://accounts.google.com')
31
+ end
32
+
33
+ it 'has correct authorize url' do
34
+ subject.client.options[:authorize_url].should eq('/o/oauth2/auth')
35
+ end
36
+
37
+ it 'has correct token url' do
38
+ subject.client.options[:token_url].should eq('/o/oauth2/token')
39
+ end
40
+ end
41
+
42
+ describe '#callback_path' do
43
+ it 'has the correct callback path' do
44
+ subject.callback_path.should eq('/auth/google_oauth2/callback')
45
+ end
46
+ end
47
+
48
+ describe '#authorize_params' do
49
+ %w(approval_prompt access_type state hd any_other).each do |k|
50
+ it "should set the #{k} authorize option dynamically in the request" do
51
+ @options = {:authorize_options => [k.to_sym], k.to_sym => ''}
52
+ subject.stub(:request) { double('Request', {:params => { k => 'something' }, :env => {}}) }
53
+ subject.authorize_params[k].should eq('something')
54
+ end
55
+ end
56
+
57
+ describe 'scope' do
58
+ it 'should expand scope shortcuts' do
59
+ @options = { :authorize_options => [:scope], :scope => 'userinfo.email'}
60
+ subject.authorize_params['scope'].should eq('https://www.googleapis.com/auth/userinfo.email')
61
+ end
62
+
63
+ it 'should leave full scopes as is' do
64
+ @options = { :authorize_options => [:scope], :scope => 'https://www.googleapis.com/auth/userinfo.profile'}
65
+ subject.authorize_params['scope'].should eq('https://www.googleapis.com/auth/userinfo.profile')
66
+ end
67
+
68
+ it 'should join scopes' do
69
+ @options = { :authorize_options => [:scope], :scope => 'userinfo.profile,userinfo.email'}
70
+ subject.authorize_params['scope'].should eq('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email')
71
+ end
72
+
73
+ it 'should set default scope to userinfo.email,userinfo.profile' do
74
+ @options = { :authorize_options => [:scope]}
75
+ subject.authorize_params['scope'].should eq('https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile')
76
+ end
77
+
78
+ it 'should dynamically set the scope in the request' do
79
+ @options = {:scope => 'http://example.com'}
80
+ subject.stub(:request) { double('Request', {:params => { 'scope' => 'userinfo.email' }, :env => {}}) }
81
+ subject.authorize_params['scope'].should eq('https://www.googleapis.com/auth/userinfo.email')
82
+ end
83
+ end
84
+
85
+ describe 'approval_prompt' do
86
+ it 'should set the approval_prompt parameter if present' do
87
+ @options = {:approval_prompt => 'prompt'}
88
+ subject.authorize_params['approval_prompt'].should eq('prompt')
89
+ end
90
+
91
+ it 'should default to "force"' do
92
+ @options = {}
93
+ subject.authorize_params['approval_prompt'].should eq('force')
94
+ end
95
+ end
96
+
97
+ describe 'access_type' do
98
+ it 'should set the access_type parameter if present' do
99
+ @options = {:access_type => 'type'}
100
+ subject.authorize_params['access_type'].should eq('type')
101
+ end
102
+
103
+ it 'should default to "offline"' do
104
+ @options = {}
105
+ subject.authorize_params['access_type'].should eq('offline')
106
+ end
107
+ end
108
+
109
+ describe 'state' do
110
+ it 'should set the state parameter' do
111
+ @options = {:state => 'some_state'}
112
+ subject.authorize_params['state'].should eq('some_state')
113
+ subject.session['omniauth.state'].should eq('some_state')
114
+ end
115
+
116
+ it 'should set the omniauth.state dynamically' do
117
+ subject.stub(:request) { double('Request', {:params => { 'state' => 'some_state' }, :env => {}}) }
118
+ subject.authorize_params['state'].should eq('some_state')
119
+ subject.session['omniauth.state'].should eq('some_state')
120
+ end
121
+ end
122
+
123
+ describe 'hd' do
124
+ it 'should set the hd (hosted domain) parameter if present' do
125
+ @options = {:hd => 'example.com'}
126
+ subject.authorize_params['hd'].should eq('example.com')
127
+ end
128
+ end
129
+
130
+ describe 'login_hint' do
131
+ it 'should set the login_hint parameter if present' do
132
+ subject.stub(:request) { double('Request', {:params => { 'login_hint' => 'example@example.com' }, :env => {}}) }
133
+ subject.authorize_params['login_hint'].should eq('example@example.com')
134
+ end
135
+ end
136
+ end
137
+
138
+ describe 'raw info' do
139
+ it 'should include raw_info in extras hash by default' do
140
+ subject.stub(:raw_info) { { :foo => 'bar' } }
141
+ subject.extra[:raw_info].should eq({ :foo => 'bar' })
142
+ end
143
+
144
+ it 'should not include raw_info in extras hash when skip_info is specified' do
145
+ @options = { :skip_info => true }
146
+ subject.extra.should_not have_key(:raw_info)
147
+ end
148
+ end
149
+
150
+ describe 'populate auth hash url' do
151
+ it 'should populate url map in auth hash if link present in raw_info' do
152
+ subject.stub(:raw_info) { { 'name' => 'Foo', 'link' => 'https://plus.google.com/123456' } }
153
+ subject.info[:urls]['Google'].should eq('https://plus.google.com/123456')
154
+ end
155
+
156
+ it 'should not populate url map in auth hash if no link present in raw_info' do
157
+ subject.stub(:raw_info) { { 'name' => 'Foo' } }
158
+ subject.info.should_not have_key(:urls)
159
+ end
160
+ end
161
+
162
+ describe 'build_access_token' do
163
+ it 'should read access_token from hash' do
164
+ @request.stub(:params).and_return('id_token' => 'valid_id_token', 'access_token' => 'valid_access_token')
165
+ subject.should_receive(:verify_token).with('valid_id_token', 'valid_access_token').and_return true
166
+ subject.should_receive(:client).and_return(:client)
167
+
168
+ token = subject.build_access_token
169
+ token.should be_instance_of(::OAuth2::AccessToken)
170
+ token.token.should eq('valid_access_token')
171
+ token.client.should eq(:client)
172
+ end
173
+
174
+ it 'should call super' do
175
+ subject.should_receive(:build_access_token_without_access_token)
176
+ subject.build_access_token
177
+ end
178
+ end
179
+
180
+ describe 'verify_token' do
181
+ before(:each) do
182
+ subject.options.client_options[:connection_build] = proc do |builder|
183
+ builder.request :url_encoded
184
+ builder.adapter :test do |stub|
185
+ stub.get('/oauth2/v2/tokeninfo?id_token=valid_id_token&access_token=valid_access_token') do |env|
186
+ [200, {'Content-Type' => 'application/json; charset=UTF-8'}, MultiJson.encode(
187
+ :issued_to => '000000000000.apps.googleusercontent.com',
188
+ :audience => '000000000000.apps.googleusercontent.com',
189
+ :user_id => '000000000000000000000',
190
+ :scope => 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email',
191
+ :expires_in => 3514,
192
+ :email => 'me@example.com',
193
+ :verified_email => true,
194
+ :access_type => 'online'
195
+ )]
196
+ end
197
+ stub.get('/oauth2/v2/tokeninfo?id_token=invalid_id_token&access_token=invalid_access_token') do |env|
198
+ [400, {'Content-Type' => 'application/json; charset=UTF-8'}, MultiJson.encode(:error_description => 'Invalid Value')]
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ it 'should verify token if access_token and id_token are valid and app_id equals' do
205
+ subject.options.client_id = '000000000000.apps.googleusercontent.com'
206
+ subject.send(:verify_token, 'valid_id_token', 'valid_access_token').should == true
207
+ end
208
+
209
+ it 'should not verify token if access_token and id_token are valid but app_id is false' do
210
+ subject.send(:verify_token, 'valid_id_token', 'valid_access_token').should == false
211
+ end
212
+
213
+ it 'should raise error if access_token or id_token is invalid' do
214
+ expect {
215
+ subject.send(:verify_token, 'invalid_id_token', 'invalid_access_token')
216
+ }.to raise_error(OAuth2::Error)
217
+ end
218
+ end
219
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+
4
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
5
+
6
+ RSpec.configure do |config|
7
+ end
@@ -0,0 +1,37 @@
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 '#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 => 'http://bar', :foo => 'baz' }
19
+ subject.authorize_params['scope'].should eq('http://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
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-accounts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Vitaliy Emeliyatsev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-07 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: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.6.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.6.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A Accounts from the Future oauth2 strategy for OmniAuth 1.0
70
+ email:
71
+ - gambala.rus@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rvmrc
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - lib/omniauth-accounts.rb
82
+ - lib/omniauth/accounts.rb
83
+ - lib/omniauth/accounts/version.rb
84
+ - lib/omniauth/strategies/accounts.rb
85
+ - omniauth-contrib.gemspec
86
+ - spec/omniauth/strategies/google_oauth2_spec.rb
87
+ - spec/spec_helper.rb
88
+ - spec/support/shared_examples.rb
89
+ homepage: https://github.com/gambala/omniauth-accounts
90
+ licenses: []
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.6
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A simple oauth 2.0 strategy
112
+ test_files: []