omniauth-identity 1.1.0 → 1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f63f80480a42c6089f050cae1a70ebe9195f925d
4
+ data.tar.gz: 3b229b38d48396559ac41f65712c931bc4f76590
5
+ SHA512:
6
+ metadata.gz: 91cbf121086311eb85cf68345b58eeac85e165ce3119a58bc148ddf470e77050664efc986e40eb2099b7b1f306b7119457445535fa1d1512bae9c975e54fbae2
7
+ data.tar.gz: 729a821aa7e9cf31e847fe1f98e87ac04e2ffb031c45405e3421617edd3ac841412840670bbdb333c806fa9330adde986bbc28bf7ecd60a4aa5e45673d2907b9
@@ -1,31 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- omniauth-identity (1.0.0)
4
+ omniauth-identity (1.1.1)
5
5
  bcrypt-ruby (~> 3.0)
6
6
  omniauth (~> 1.0)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- activemodel (3.2.1)
12
- activesupport (= 3.2.1)
11
+ activemodel (3.2.13)
12
+ activesupport (= 3.2.13)
13
13
  builder (~> 3.0.0)
14
- activerecord (3.2.1)
15
- activemodel (= 3.2.1)
16
- activesupport (= 3.2.1)
17
- arel (~> 3.0.0)
14
+ activerecord (3.2.13)
15
+ activemodel (= 3.2.13)
16
+ activesupport (= 3.2.13)
17
+ arel (~> 3.0.2)
18
18
  tzinfo (~> 0.3.29)
19
- activesupport (3.2.1)
20
- i18n (~> 0.6)
19
+ activesupport (3.2.13)
20
+ i18n (= 0.6.1)
21
21
  multi_json (~> 1.0)
22
- addressable (2.2.6)
23
- arel (3.0.0)
22
+ addressable (2.3.5)
23
+ arel (3.0.2)
24
24
  bcrypt-ruby (3.0.1)
25
- bson (1.5.2)
26
- bson_ext (1.5.2)
27
- bson (= 1.5.2)
28
- builder (3.0.0)
25
+ bson (1.9.0)
26
+ bson_ext (1.9.0)
27
+ bson (~> 1.9.0)
28
+ builder (3.0.4)
29
+ coderay (1.0.9)
30
+ couch_potato (1.0.1)
31
+ activemodel
32
+ couchrest (~> 1.2.0)
33
+ json (~> 1.6)
34
+ couchrest (1.2.0)
35
+ mime-types (~> 1.15)
36
+ multi_json (~> 1.0)
37
+ rest-client (~> 1.6.1)
29
38
  datamapper (1.2.0)
30
39
  dm-aggregates (~> 1.2.0)
31
40
  dm-constraints (~> 1.2.0)
@@ -36,90 +45,116 @@ GEM
36
45
  dm-transactions (~> 1.2.0)
37
46
  dm-types (~> 1.2.0)
38
47
  dm-validations (~> 1.2.0)
39
- diff-lcs (1.1.3)
48
+ diff-lcs (1.2.4)
40
49
  dm-aggregates (1.2.0)
41
50
  dm-core (~> 1.2.0)
42
51
  dm-constraints (1.2.0)
43
52
  dm-core (~> 1.2.0)
44
- dm-core (1.2.0)
45
- addressable (~> 2.2.6)
53
+ dm-core (1.2.1)
54
+ addressable (~> 2.3)
46
55
  dm-migrations (1.2.0)
47
56
  dm-core (~> 1.2.0)
48
- dm-serializer (1.2.1)
57
+ dm-serializer (1.2.2)
49
58
  dm-core (~> 1.2.0)
50
- fastercsv (~> 1.5.4)
51
- json (~> 1.6.1)
52
- json_pure (~> 1.6.1)
53
- multi_json (~> 1.0.3)
59
+ fastercsv (~> 1.5)
60
+ json (~> 1.6)
61
+ json_pure (~> 1.6)
62
+ multi_json (~> 1.0)
54
63
  dm-timestamps (1.2.0)
55
64
  dm-core (~> 1.2.0)
56
65
  dm-transactions (1.2.0)
57
66
  dm-core (~> 1.2.0)
58
- dm-types (1.2.1)
59
- bcrypt-ruby (~> 3.0.0)
67
+ dm-types (1.2.2)
68
+ bcrypt-ruby (~> 3.0)
60
69
  dm-core (~> 1.2.0)
61
- fastercsv (~> 1.5.4)
62
- json (~> 1.6.1)
63
- multi_json (~> 1.0.3)
64
- stringex (~> 1.3.0)
65
- uuidtools (~> 2.1.2)
70
+ fastercsv (~> 1.5)
71
+ json (~> 1.6)
72
+ multi_json (~> 1.0)
73
+ stringex (~> 1.4)
74
+ uuidtools (~> 2.1)
66
75
  dm-validations (1.2.0)
67
76
  dm-core (~> 1.2.0)
68
- fastercsv (1.5.4)
69
- ffi (1.0.11)
77
+ fastercsv (1.5.5)
78
+ ffi (1.9.0)
79
+ formatador (0.2.4)
70
80
  growl (1.0.3)
71
- guard (1.0.0)
72
- ffi (>= 0.5.0)
73
- thor (~> 0.14.6)
74
- guard-bundler (0.1.3)
75
- bundler (>= 1.0.0)
76
- guard (>= 0.2.2)
77
- guard-rspec (0.6.0)
78
- guard (>= 0.10.0)
79
- hashie (1.2.0)
80
- i18n (0.6.0)
81
- json (1.6.5)
82
- json_pure (1.6.5)
83
- maruku (0.6.0)
81
+ guard (1.8.1)
82
+ formatador (>= 0.2.4)
83
+ listen (>= 1.0.0)
84
+ lumberjack (>= 1.0.2)
85
+ pry (>= 0.9.10)
86
+ thor (>= 0.14.6)
87
+ guard-bundler (1.0.0)
88
+ bundler (~> 1.0)
89
+ guard (~> 1.1)
90
+ guard-rspec (3.0.2)
91
+ guard (>= 1.8)
92
+ rspec (~> 2.13)
93
+ hashie (2.0.5)
94
+ i18n (0.6.1)
95
+ json (1.8.0)
96
+ json_pure (1.8.0)
97
+ listen (1.2.2)
98
+ rb-fsevent (>= 0.9.3)
99
+ rb-inotify (>= 0.9)
100
+ rb-kqueue (>= 0.2)
101
+ lumberjack (1.0.4)
102
+ maruku (0.6.1)
84
103
  syntax (>= 1.0.0)
85
- mongo (1.5.2)
86
- bson (= 1.5.2)
87
- mongo_mapper (0.11.0)
104
+ method_source (0.8.1)
105
+ mime-types (1.23)
106
+ mongo (1.9.0)
107
+ bson (~> 1.9.0)
108
+ mongo_mapper (0.12.0)
88
109
  activemodel (~> 3.0)
89
110
  activesupport (~> 3.0)
90
- plucky (~> 0.4.0)
91
- mongoid (2.4.4)
92
- activemodel (~> 3.1)
93
- mongo (~> 1.3)
111
+ plucky (~> 0.5.2)
112
+ mongoid (3.1.4)
113
+ activemodel (~> 3.2)
114
+ moped (~> 1.4)
115
+ origin (~> 1.0)
94
116
  tzinfo (~> 0.3.22)
95
- multi_json (1.0.4)
96
- omniauth (1.1.0)
97
- hashie (~> 1.2)
117
+ moped (1.5.0)
118
+ multi_json (1.7.7)
119
+ omniauth (1.1.4)
120
+ hashie (>= 1.2, < 3)
98
121
  rack
99
- plucky (0.4.4)
122
+ origin (1.1.0)
123
+ plucky (0.5.2)
100
124
  mongo (~> 1.5)
101
- rack (1.4.1)
102
- rack-test (0.6.1)
125
+ pry (0.9.12.2)
126
+ coderay (~> 1.0.5)
127
+ method_source (~> 0.8)
128
+ slop (~> 3.4)
129
+ rack (1.5.2)
130
+ rack-test (0.6.2)
103
131
  rack (>= 1.0)
104
- rake (0.9.2.2)
105
- rb-fsevent (0.9.0)
106
- rspec (2.8.0)
107
- rspec-core (~> 2.8.0)
108
- rspec-expectations (~> 2.8.0)
109
- rspec-mocks (~> 2.8.0)
110
- rspec-core (2.8.0)
111
- rspec-expectations (2.8.0)
112
- diff-lcs (~> 1.1.2)
113
- rspec-mocks (2.8.0)
114
- simplecov (0.5.4)
115
- multi_json (~> 1.0.3)
116
- simplecov-html (~> 0.5.3)
117
- simplecov-html (0.5.3)
118
- stringex (1.3.2)
132
+ rake (0.9.6)
133
+ rb-fsevent (0.9.3)
134
+ rb-inotify (0.9.0)
135
+ ffi (>= 0.5.0)
136
+ rb-kqueue (0.2.0)
137
+ ffi (>= 0.5.0)
138
+ rest-client (1.6.7)
139
+ mime-types (>= 1.16)
140
+ rspec (2.13.0)
141
+ rspec-core (~> 2.13.0)
142
+ rspec-expectations (~> 2.13.0)
143
+ rspec-mocks (~> 2.13.0)
144
+ rspec-core (2.13.1)
145
+ rspec-expectations (2.13.0)
146
+ diff-lcs (>= 1.1.3, < 2.0)
147
+ rspec-mocks (2.13.1)
148
+ simplecov (0.7.1)
149
+ multi_json (~> 1.0)
150
+ simplecov-html (~> 0.7.1)
151
+ simplecov-html (0.7.1)
152
+ slop (3.4.5)
153
+ stringex (1.5.1)
119
154
  syntax (1.0.0)
120
- thor (0.14.6)
121
- tzinfo (0.3.31)
122
- uuidtools (2.1.2)
155
+ thor (0.18.1)
156
+ tzinfo (0.3.37)
157
+ uuidtools (2.1.4)
123
158
 
124
159
  PLATFORMS
125
160
  ruby
@@ -127,6 +162,7 @@ PLATFORMS
127
162
  DEPENDENCIES
128
163
  activerecord (~> 3.1)
129
164
  bson_ext
165
+ couch_potato
130
166
  datamapper
131
167
  growl
132
168
  guard
@@ -26,7 +26,7 @@ able to persist the information provided by the user. Luckily for you, there
26
26
  are pre-built models for popular ORMs that make this dead simple.
27
27
 
28
28
  **Note:** OmniAuth Identity is different from many other user authentication
29
- systems in that it is *not* intended to be associated with your primary
29
+ systems in that it is *not* built to store authentication information in your primary
30
30
  `User` model. Instead, the `Identity` model should be **associated** with your
31
31
  `User` model giving you maximum flexibility to include other authentication
32
32
  strategies such as Facebook, Twitter, etc.
@@ -93,6 +93,26 @@ class Identity
93
93
  end
94
94
  ```
95
95
 
96
+ ### CouchPotato
97
+
98
+ Include the `OmniAuth::Identity::Models::CouchPotatoModule` mixin and specify fields that you will need.
99
+
100
+ ```ruby
101
+ class Identity
102
+ include CouchPotato::Persistence
103
+ include OmniAuth::Identity::Models::CouchPotatoModule
104
+
105
+ property :email
106
+ property :password_digest
107
+
108
+ def self.where search_hash
109
+ CouchPotato.database.view Identity.by_email(:key => search_hash)
110
+ end
111
+
112
+ view :by_email, :key => :email
113
+ end
114
+ ```
115
+
96
116
  Once you've got an Identity persistence model and the strategy up and
97
117
  running, you can point users to `/auth/identity` and it will request
98
118
  that they log in or give them the opportunity to sign up for an account.
@@ -160,3 +180,23 @@ For more information on rack endpoints, check out [this
160
180
  introduction](http://library.edgecase.com/Rails/2011/01/04/rails-routing-and-rack-endpoints.html)
161
181
  and
162
182
  [ActionController::Metal](http://rubydoc.info/docs/rails/ActionController/Metal)
183
+
184
+ ## Customizing Locate Conditions
185
+
186
+ You can customize the way that matching records are found when authenticating.
187
+ For example, for a site with multiple domains, you may wish to scope the search
188
+ within a particular subdomain. To do so, add :locate_conditions to your config.
189
+ The default value is:
190
+
191
+ ```ruby
192
+ :locate_conditions => lambda { |req| { model.auth_key => req['auth_key']} }
193
+ ```
194
+
195
+ locate_conditions takes a Proc object, and must return a hash. The resulting hash is used
196
+ as a parameter in the locate method for your ORM. The proc is evaluated in the
197
+ callback context, and has access to the Identity model (using `model`) and receives the request
198
+ object as a parameter. Note that model.auth_key defaults to 'email', but is also configurable.
199
+
200
+ Note: Be careful when customizing locate_conditions. The best way to modify the conditions is
201
+ to copy the default value, and then add to the hash. Removing the default condition will almost
202
+ always break things!
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Identity
3
- VERSION = '1.1.0'
3
+ VERSION = '1.1.1'
4
4
  end
5
5
  end
@@ -6,13 +6,14 @@ module OmniAuth
6
6
  end
7
7
 
8
8
  module Identity
9
- autoload :Model, 'omniauth/identity/model'
10
- autoload :SecurePassword, 'omniauth/identity/secure_password'
9
+ autoload :Model, 'omniauth/identity/model'
10
+ autoload :SecurePassword, 'omniauth/identity/secure_password'
11
11
  module Models
12
- autoload :ActiveRecord, 'omniauth/identity/models/active_record'
13
- autoload :MongoMapper, 'omniauth/identity/models/mongo_mapper'
14
- autoload :Mongoid, 'omniauth/identity/models/mongoid'
15
- autoload :DataMapper, 'omniauth/identity/models/data_mapper'
12
+ autoload :ActiveRecord, 'omniauth/identity/models/active_record'
13
+ autoload :MongoMapper, 'omniauth/identity/models/mongo_mapper'
14
+ autoload :Mongoid, 'omniauth/identity/models/mongoid'
15
+ autoload :DataMapper, 'omniauth/identity/models/data_mapper'
16
+ autoload :CouchPotatoModule, 'omniauth/identity/models/couch_potato'
16
17
  end
17
18
  end
18
19
  end
@@ -23,14 +23,14 @@ module OmniAuth
23
23
  # Authenticate a user with the given key and password.
24
24
  #
25
25
  # @param [String] key The unique login key provided for a given identity.
26
- # @param [String] password The presumed password for the identity.
26
+ # @param [String] password The presumed password for the identity.
27
27
  # @return [Model] An instance of the identity model class.
28
- def authenticate(key, password)
29
- instance = locate(key)
28
+ def authenticate(conditions, password)
29
+ instance = locate(conditions)
30
30
  return false unless instance
31
31
  instance.authenticate(password)
32
32
  end
33
-
33
+
34
34
  # Used to set or retrieve the method that will be used to get
35
35
  # and set the user-supplied authentication key.
36
36
  # @return [String] The method name.
@@ -9,14 +9,14 @@ module OmniAuth
9
9
 
10
10
  self.abstract_class = true
11
11
  has_secure_password
12
-
12
+
13
13
  def self.auth_key=(key)
14
14
  super
15
15
  validates_uniqueness_of key, :case_sensitive => false
16
16
  end
17
17
 
18
- def self.locate(key)
19
- where(auth_key => key).first
18
+ def self.locate(search_hash)
19
+ where(search_hash).first
20
20
  end
21
21
  end
22
22
  end
@@ -0,0 +1,31 @@
1
+ require 'couch_potato'
2
+
3
+ module OmniAuth
4
+ module Identity
5
+ module Models
6
+ # can not be named CouchPotato since there is a class with that name
7
+ module CouchPotatoModule
8
+
9
+ def self.included(base)
10
+
11
+ base.class_eval do
12
+
13
+ include ::OmniAuth::Identity::Model
14
+ include ::OmniAuth::Identity::SecurePassword
15
+
16
+ has_secure_password
17
+
18
+ def self.auth_key=(key)
19
+ super
20
+ validates_uniqueness_of key, :case_sensitive => false
21
+ end
22
+
23
+ def self.locate(search_hash)
24
+ where(search_hash).first
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -21,8 +21,8 @@ module OmniAuth
21
21
  validates_uniqueness_of :key
22
22
  end
23
23
 
24
- def self.locate(key)
25
- all(auth_key => key).first
24
+ def self.locate(search_hash)
25
+ all(search_hash).first
26
26
  end
27
27
  end
28
28
  end
@@ -16,8 +16,8 @@ module OmniAuth
16
16
  validates_uniqueness_of key, :case_sensitive => false
17
17
  end
18
18
 
19
- def self.locate(key)
20
- where(auth_key => key).first
19
+ def self.locate(search_hash)
20
+ where(search_hash).first
21
21
  end
22
22
  end
23
23
  end
@@ -19,8 +19,8 @@ module OmniAuth
19
19
  validates_uniqueness_of key, :case_sensitive => false
20
20
  end
21
21
 
22
- def self.locate(key)
23
- where(auth_key => key).first
22
+ def self.locate(search_hash)
23
+ where(search_hash).first
24
24
  end
25
25
 
26
26
  end
@@ -68,7 +68,7 @@ module OmniAuth
68
68
  # Encrypts the password into the password_digest attribute.
69
69
  def password=(unencrypted_password)
70
70
  @password = unencrypted_password
71
- unless unencrypted_password.empty?
71
+ if unencrypted_password && !unencrypted_password.empty?
72
72
  self.password_digest = BCrypt::Password.create(unencrypted_password)
73
73
  end
74
74
  end
@@ -1,23 +1,30 @@
1
1
  module OmniAuth
2
2
  module Strategies
3
- # The identity strategy allows you to provide simple internal
3
+ # The identity strategy allows you to provide simple internal
4
4
  # user authentication using the same process flow that you
5
5
  # use for external OmniAuth providers.
6
6
  class Identity
7
7
  include OmniAuth::Strategy
8
8
 
9
9
  option :fields, [:name, :email]
10
+ option :on_login, nil
11
+ option :on_registration, nil
10
12
  option :on_failed_registration, nil
13
+ option :locate_conditions, lambda{|req| {model.auth_key => req['auth_key']} }
11
14
 
12
15
  def request_phase
13
- OmniAuth::Form.build(
14
- :title => (options[:title] || "Identity Verification"),
15
- :url => callback_path
16
- ) do |f|
17
- f.text_field 'Login', 'auth_key'
18
- f.password_field 'Password', 'password'
19
- f.html "<p align='center'><a href='#{registration_path}'>Create an Identity</a></p>"
20
- end.to_response
16
+ if options[:on_login]
17
+ options[:on_login].call(self.env)
18
+ else
19
+ OmniAuth::Form.build(
20
+ :title => (options[:title] || "Identity Verification"),
21
+ :url => callback_path
22
+ ) do |f|
23
+ f.text_field 'Login', 'auth_key'
24
+ f.password_field 'Password', 'password'
25
+ f.html "<p align='center'><a href='#{registration_path}'>Create an Identity</a></p>"
26
+ end.to_response
27
+ end
21
28
  end
22
29
 
23
30
  def callback_phase
@@ -38,13 +45,17 @@ module OmniAuth
38
45
  end
39
46
 
40
47
  def registration_form
41
- OmniAuth::Form.build(:title => 'Register Identity') do |f|
42
- options[:fields].each do |field|
43
- f.text_field field.to_s.capitalize, field.to_s
44
- end
45
- f.password_field 'Password', 'password'
46
- f.password_field 'Confirm Password', 'password_confirmation'
47
- end.to_response
48
+ if options[:on_registration]
49
+ options[:on_registration].call(self.env)
50
+ else
51
+ OmniAuth::Form.build(:title => 'Register Identity') do |f|
52
+ options[:fields].each do |field|
53
+ f.text_field field.to_s.capitalize, field.to_s
54
+ end
55
+ f.password_field 'Password', 'password'
56
+ f.password_field 'Confirm Password', 'password_confirmation'
57
+ end.to_response
58
+ end
48
59
  end
49
60
 
50
61
  def registration_phase
@@ -75,7 +86,13 @@ module OmniAuth
75
86
  end
76
87
 
77
88
  def identity
78
- @identity ||= model.authenticate(request['auth_key'], request['password'])
89
+ if options.locate_conditions.is_a? Proc
90
+ conditions = instance_exec(request, &options.locate_conditions)
91
+ conditions.to_hash
92
+ else
93
+ conditions = options.locate_conditions.to_hash
94
+ end
95
+ @identity ||= model.authenticate(conditions, request['password'] )
79
96
  end
80
97
 
81
98
  def model
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.add_development_dependency 'mongo_mapper'
16
16
  gem.add_development_dependency 'datamapper'
17
17
  gem.add_development_dependency 'bson_ext'
18
+ gem.add_development_dependency 'couch_potato'
18
19
 
19
20
  gem.name = 'omniauth-identity'
20
21
  gem.version = OmniAuth::Identity::VERSION
@@ -15,8 +15,14 @@ describe OmniAuth::Identity::Model do
15
15
  describe '.authenticate' do
16
16
  it 'should call locate and then authenticate' do
17
17
  mocked_instance = mock('ExampleModel', :authenticate => 'abbadoo')
18
- subject.should_receive(:locate).with('example').and_return(mocked_instance)
19
- subject.authenticate('example','pass').should == 'abbadoo'
18
+ subject.should_receive(:locate).with('email' => 'example').and_return(mocked_instance)
19
+ subject.authenticate({'email' => 'example'},'pass').should == 'abbadoo'
20
+ end
21
+
22
+ it 'should call locate with additional scopes when provided' do
23
+ mocked_instance = mock('ExampleModel', :authenticate => 'abbadoo')
24
+ subject.should_receive(:locate).with('email' => 'example', 'user_type' => 'admin').and_return(mocked_instance)
25
+ subject.authenticate({'email' => 'example', 'user_type' => 'admin'}, 'pass').should == 'abbadoo'
20
26
  end
21
27
 
22
28
  it 'should recover gracefully if locate is nil' do
@@ -1,15 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe(OmniAuth::Identity::Models::ActiveRecord, :db => true) do
4
- class TestIdentity < OmniAuth::Identity::Models::ActiveRecord
5
- auth_key :ham_sandwich
6
- end
4
+ class TestIdentity < OmniAuth::Identity::Models::ActiveRecord; end
7
5
 
8
- it 'should locate using the auth key using a where query' do
9
- TestIdentity.should_receive(:where).with('ham_sandwich' => 'open faced').and_return(['wakka'])
10
- TestIdentity.locate('open faced').should == 'wakka'
6
+ it 'should delegate locate to the where query method' do
7
+ TestIdentity.should_receive(:where).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
8
+ TestIdentity.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches').should == 'wakka'
11
9
  end
12
-
10
+
13
11
  it 'should not use STI rules for its table name' do
14
12
  TestIdentity.table_name.should == 'test_identities'
15
13
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe(OmniAuth::Identity::Models::CouchPotatoModule, :db => true) do
4
+ class CouchPotatoTestIdentity
5
+ include CouchPotato::Persistence
6
+ include OmniAuth::Identity::Models::CouchPotatoModule
7
+ auth_key :ham_sandwich
8
+ end
9
+
10
+ it 'should delegate locate to the where query method' do
11
+ CouchPotatoTestIdentity.should_receive(:where).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
12
+ CouchPotatoTestIdentity.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches').should == 'wakka'
13
+ end
14
+
15
+ end
@@ -15,8 +15,8 @@ describe(OmniAuth::Identity::Models::DataMapper, :db => true) do
15
15
  @resource = DataMapperTestIdentity.new
16
16
  end
17
17
 
18
- it 'should locate using the auth key using a all query' do
19
- DataMapperTestIdentity.should_receive(:all).with('ham_sandwich' => 'open faced').and_return(['wakka'])
20
- DataMapperTestIdentity.locate('open faced').should == 'wakka'
18
+ it 'should delegate locate to the all query method' do
19
+ DataMapperTestIdentity.should_receive(:all).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
20
+ DataMapperTestIdentity.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches').should == 'wakka'
21
21
  end
22
22
  end
@@ -7,8 +7,9 @@ describe(OmniAuth::Identity::Models::MongoMapper, :db => true) do
7
7
  auth_key :ham_sandwich
8
8
  end
9
9
 
10
- it 'should locate using the auth key using a where query' do
11
- MongoMapperTestIdentity.should_receive(:where).with('ham_sandwich' => 'open faced').and_return(['wakka'])
12
- MongoMapperTestIdentity.locate('open faced').should == 'wakka'
10
+
11
+ it 'should delegate locate to the where query method' do
12
+ MongoMapperTestIdentity.should_receive(:where).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
13
+ MongoMapperTestIdentity.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches').should == 'wakka'
13
14
  end
14
15
  end
@@ -7,11 +7,11 @@ describe(OmniAuth::Identity::Models::Mongoid, :db => true) do
7
7
  auth_key :ham_sandwich
8
8
  end
9
9
 
10
- it 'should locate using the auth key using a where query' do
11
- MongoidTestIdentity.should_receive(:where).with('ham_sandwich' => 'open faced').and_return(['wakka'])
12
- MongoidTestIdentity.locate('open faced').should == 'wakka'
10
+ it 'should delegate locate to the where query method' do
11
+ MongoidTestIdentity.should_receive(:where).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
12
+ MongoidTestIdentity.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches').should == 'wakka'
13
13
  end
14
-
14
+
15
15
  it 'should not use STI rules for its collection name' do
16
16
  MongoidTestIdentity.collection.name.should == 'mongoid_test_identities'
17
17
  end
@@ -41,7 +41,8 @@ describe OmniAuth::Strategies::Identity do
41
41
 
42
42
  context 'with valid credentials' do
43
43
  before do
44
- MockIdentity.should_receive('authenticate').with('john','awesome').and_return(user)
44
+ MockIdentity.stub('auth_key').and_return('email')
45
+ MockIdentity.should_receive('authenticate').with({'email' => 'john'},'awesome').and_return(user)
45
46
  post '/auth/identity/callback', :auth_key => 'john', :password => 'awesome'
46
47
  end
47
48
 
@@ -60,8 +61,9 @@ describe OmniAuth::Strategies::Identity do
60
61
 
61
62
  context 'with invalid credentials' do
62
63
  before do
64
+ MockIdentity.stub('auth_key').and_return('email')
63
65
  OmniAuth.config.on_failure = lambda{|env| [401, {}, [env['omniauth.error.type'].inspect]]}
64
- MockIdentity.should_receive(:authenticate).with('wrong','login').and_return(false)
66
+ MockIdentity.should_receive(:authenticate).with({'email' => 'wrong'},'login').and_return(false)
65
67
  post '/auth/identity/callback', :auth_key => 'wrong', :password => 'login'
66
68
  end
67
69
 
@@ -69,6 +71,16 @@ describe OmniAuth::Strategies::Identity do
69
71
  last_response.body.should == ':invalid_credentials'
70
72
  end
71
73
  end
74
+
75
+ context 'with auth scopes' do
76
+
77
+ it 'should evaluate and pass through conditions proc' do
78
+ MockIdentity.stub('auth_key').and_return('email')
79
+ set_app!( :locate_conditions => lambda{|req| {model.auth_key => req['auth_key'], 'user_type' => 'admin'} } )
80
+ MockIdentity.should_receive('authenticate').with( {'email' => 'john', 'user_type' => 'admin'}, 'awesome' ).and_return(user)
81
+ post '/auth/identity/callback', :auth_key => 'john', :password => 'awesome'
82
+ end
83
+ end
72
84
  end
73
85
 
74
86
  describe '#registration_form' do
@@ -81,13 +93,14 @@ describe OmniAuth::Strategies::Identity do
81
93
  describe '#registration_phase' do
82
94
  context 'with successful creation' do
83
95
  let(:properties){ {
84
- :name => 'Awesome Dude',
96
+ :name => 'Awesome Dude',
85
97
  :email => 'awesome@example.com',
86
98
  :password => 'face',
87
99
  :password_confirmation => 'face'
88
100
  } }
89
101
 
90
102
  before do
103
+ MockIdentity.stub('auth_key').and_return('email')
91
104
  m = mock(:uid => 'abc', :name => 'Awesome Dude', :email => 'awesome@example.com', :info => {:name => 'DUUUUDE!'}, :persisted? => true)
92
105
  MockIdentity.should_receive(:create).with(properties).and_return(m)
93
106
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-identity
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michael Bleigh
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-06 00:00:00.000000000 Z
11
+ date: 2013-07-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: omniauth
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bcrypt-ruby
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: maruku
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: simplecov
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rack-test
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rake
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ~>
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ~>
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: rspec
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ~>
124
109
  - !ruby/object:Gem::Version
@@ -126,7 +111,6 @@ dependencies:
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: activerecord
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ~>
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ~>
140
123
  - !ruby/object:Gem::Version
@@ -142,65 +125,71 @@ dependencies:
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: mongoid
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
- - - ! '>='
129
+ - - '>='
148
130
  - !ruby/object:Gem::Version
149
131
  version: '0'
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
- - - ! '>='
136
+ - - '>='
156
137
  - !ruby/object:Gem::Version
157
138
  version: '0'
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: mongo_mapper
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
- - - ! '>='
143
+ - - '>='
164
144
  - !ruby/object:Gem::Version
165
145
  version: '0'
166
146
  type: :development
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
- - - ! '>='
150
+ - - '>='
172
151
  - !ruby/object:Gem::Version
173
152
  version: '0'
174
153
  - !ruby/object:Gem::Dependency
175
154
  name: datamapper
176
155
  requirement: !ruby/object:Gem::Requirement
177
- none: false
178
156
  requirements:
179
- - - ! '>='
157
+ - - '>='
180
158
  - !ruby/object:Gem::Version
181
159
  version: '0'
182
160
  type: :development
183
161
  prerelease: false
184
162
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
163
  requirements:
187
- - - ! '>='
164
+ - - '>='
188
165
  - !ruby/object:Gem::Version
189
166
  version: '0'
190
167
  - !ruby/object:Gem::Dependency
191
168
  name: bson_ext
192
169
  requirement: !ruby/object:Gem::Requirement
193
- none: false
194
170
  requirements:
195
- - - ! '>='
171
+ - - '>='
196
172
  - !ruby/object:Gem::Version
197
173
  version: '0'
198
174
  type: :development
199
175
  prerelease: false
200
176
  version_requirements: !ruby/object:Gem::Requirement
201
- none: false
202
177
  requirements:
203
- - - ! '>='
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: couch_potato
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '>='
204
193
  - !ruby/object:Gem::Version
205
194
  version: '0'
206
195
  description: Internal authentication handlers for OmniAuth.
@@ -222,6 +211,7 @@ files:
222
211
  - lib/omniauth/identity.rb
223
212
  - lib/omniauth/identity/model.rb
224
213
  - lib/omniauth/identity/models/active_record.rb
214
+ - lib/omniauth/identity/models/couch_potato.rb
225
215
  - lib/omniauth/identity/models/data_mapper.rb
226
216
  - lib/omniauth/identity/models/mongo_mapper.rb
227
217
  - lib/omniauth/identity/models/mongoid.rb
@@ -230,6 +220,7 @@ files:
230
220
  - omniauth-identity.gemspec
231
221
  - spec/omniauth/identity/model_spec.rb
232
222
  - spec/omniauth/identity/models/active_record_spec.rb
223
+ - spec/omniauth/identity/models/couch_potato_spec.rb
233
224
  - spec/omniauth/identity/models/data_mapper_spec.rb
234
225
  - spec/omniauth/identity/models/mongo_mapper_spec.rb
235
226
  - spec/omniauth/identity/models/mongoid_spec.rb
@@ -238,26 +229,26 @@ files:
238
229
  - spec/spec_helper.rb
239
230
  homepage: http://github.com/intridea/omniauth-identity
240
231
  licenses: []
232
+ metadata: {}
241
233
  post_install_message:
242
234
  rdoc_options: []
243
235
  require_paths:
244
236
  - lib
245
237
  required_ruby_version: !ruby/object:Gem::Requirement
246
- none: false
247
238
  requirements:
248
- - - ! '>='
239
+ - - '>='
249
240
  - !ruby/object:Gem::Version
250
241
  version: '0'
251
242
  required_rubygems_version: !ruby/object:Gem::Requirement
252
- none: false
253
243
  requirements:
254
- - - ! '>='
244
+ - - '>='
255
245
  - !ruby/object:Gem::Version
256
246
  version: 1.3.6
257
247
  requirements: []
258
248
  rubyforge_project:
259
- rubygems_version: 1.8.24
249
+ rubygems_version: 2.0.0
260
250
  signing_key:
261
- specification_version: 3
251
+ specification_version: 4
262
252
  summary: Internal authentication handlers for OmniAuth.
263
253
  test_files: []
254
+ has_rdoc: