omniauth-identity 1.0.0.rc1 → 2.0.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 +7 -0
- data/.gitignore +3 -1
- data/.rspec +2 -1
- data/CHANGELOG.md +27 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/README.markdown +149 -35
- data/lib/omniauth-identity/version.rb +1 -1
- data/lib/omniauth/identity.rb +6 -5
- data/lib/omniauth/identity/model.rb +9 -8
- data/lib/omniauth/identity/models/active_record.rb +3 -3
- data/lib/omniauth/identity/models/couch_potato.rb +31 -0
- data/lib/omniauth/identity/models/data_mapper.rb +32 -0
- data/lib/omniauth/identity/models/mongoid.rb +2 -2
- data/lib/omniauth/identity/secure_password.rb +1 -1
- data/lib/omniauth/strategies/identity.rb +34 -17
- data/omniauth-identity.gemspec +16 -13
- data/spec/omniauth/identity/model_spec.rb +39 -35
- data/spec/omniauth/identity/models/active_record_spec.rb +12 -12
- data/spec/omniauth/identity/models/couch_potato_spec.rb +16 -0
- data/spec/omniauth/identity/models/data_mapper_spec.rb +24 -0
- data/spec/omniauth/identity/models/mongoid_spec.rb +14 -9
- data/spec/omniauth/identity/secure_password_spec.rb +3 -5
- data/spec/omniauth/strategies/identity_spec.rb +30 -19
- data/spec/spec_helper.rb +6 -0
- metadata +147 -69
- data/Gemfile.lock +0 -88
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3ae0c6e9acba482e20f1284d42f157beb243b7efe00913b420e1d97ee158d0d2
|
4
|
+
data.tar.gz: c113d2a6e9f701ae8b7a524e7aede16bfce000f593f194e577b38a2cb02a10c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f8cbd06676c3b16661651bf161e4bf819e8b48529aec572d2a7ddb52e5a4dde87bf52e71933be86af22486f03b4a4d5710417db79803b1bba93357258122330
|
7
|
+
data.tar.gz: 36a5d520208b6d0754d5d3e7fb7990b27b9bd967b598039bf6d37bf0e8167e2e8c7689df79a8aeee9a6d9187b2a1d2653d02e99025444157183d0072323807ae
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
|
6
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
7
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
8
|
+
|
9
|
+
## [2.0] - 2020-09-01
|
10
|
+
|
11
|
+
### Added
|
12
|
+
- CHANGELOG to maintain a history of changes.
|
13
|
+
- Include mongoid-rspec gem.
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
- Fix failing Specs
|
17
|
+
- Update Spec syntax to RSpec 3
|
18
|
+
- Fix deprecation Warnings
|
19
|
+
- Updated mongoid_spec.rb to leverage mongoid-rspec features.
|
20
|
+
- Fix security warning about missing secret in session cookie.
|
21
|
+
- Dependency version limits so that the most up-to-date gem dependencies are used. (rspec 3+, mongo 2+, mongoid 7+, rake 13+, rack 2+, json 2+)
|
22
|
+
- Updated copyright information.
|
23
|
+
- Updated MongoMapper section of README to reflect its discontinued support.
|
24
|
+
|
25
|
+
### Removed
|
26
|
+
- Gemfile.lock file
|
27
|
+
- MongoMapper support; unable to satisfy dependencies of both MongoMapper and Mongoig now that MongoMapper is no longer actively maintained.
|
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2020- Andrew Roberts, and Jellybooks Ltd.
|
2
|
+
Copyright (c) 2010-2015 Michael Bleigh and Intridea, Inc.
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
CHANGED
@@ -8,26 +8,103 @@ basic construct for user management and then gets out of the way.
|
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
11
|
-
|
11
|
+
This can be a bit hard to understand the first time. Luckily, Ryan Bates made
|
12
|
+
a [Railscast](http://railscasts.com/episodes/304-omniauth-identity) about it!
|
13
|
+
|
14
|
+
You use `omniauth-identity` just like you would any other OmniAuth provider: as a
|
12
15
|
Rack middleware. The basic setup for a email/password authentication would
|
13
16
|
look something like this:
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
```ruby
|
19
|
+
use OmniAuth::Builder do
|
20
|
+
provider :identity, :fields => [:email]
|
21
|
+
end
|
22
|
+
```
|
18
23
|
|
19
24
|
Next, you need to create a model (called `Identity by default`) that will be
|
20
25
|
able to persist the information provided by the user. Luckily for you, there
|
21
|
-
are pre-built models for popular ORMs that make this dead simple.
|
22
|
-
|
26
|
+
are pre-built models for popular ORMs that make this dead simple.
|
27
|
+
|
28
|
+
**Note:** OmniAuth Identity is different from many other user authentication
|
29
|
+
systems in that it is *not* built to store authentication information in your primary
|
30
|
+
`User` model. Instead, the `Identity` model should be **associated** with your
|
31
|
+
`User` model giving you maximum flexibility to include other authentication
|
32
|
+
strategies such as Facebook, Twitter, etc.
|
33
|
+
|
34
|
+
### ActiveRecord
|
35
|
+
|
36
|
+
Just subclass `OmniAuth::Identity::Models::ActiveRecord` and provide fields
|
37
|
+
in the database for all of the fields you are using.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class Identity < OmniAuth::Identity::Models::ActiveRecord
|
41
|
+
# Add whatever you like!
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
### Mongoid
|
46
|
+
|
47
|
+
Include the `OmniAuth::Identity::Models::Mongoid` mixin and specify
|
48
|
+
fields that you will need.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
class Identity
|
52
|
+
include Mongoid::Document
|
53
|
+
include OmniAuth::Identity::Models::Mongoid
|
54
|
+
|
55
|
+
field :email, type: String
|
56
|
+
field :name, type: String
|
57
|
+
field :password_digest, type: String
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
### MongoMapper
|
62
|
+
|
63
|
+
Unfortunately MongoMapper is **not supported** in `omniauth-identity` from >= v2.0 as a result of it
|
64
|
+
not being maintained for several years.
|
65
|
+
|
66
|
+
It wasn't possible to include Mongoid *and* MongoMapper due to incompatible gem version
|
67
|
+
requirements. Therefore precedence was given to Mongoid as it is significantly more
|
68
|
+
popular and actively maintained.
|
69
|
+
|
70
|
+
### DataMapper
|
71
|
+
|
72
|
+
Include the `OmniAuth::Identity::Models::DataMapper` mixin and specify
|
73
|
+
fields that you will need.
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
class Identity
|
77
|
+
include DataMapper::Resource
|
78
|
+
include OmniAuth::Identity::Models::DataMapper
|
79
|
+
|
80
|
+
property :id, Serial
|
81
|
+
property :email, String
|
82
|
+
property :password_digest, Text
|
23
83
|
|
24
|
-
|
25
|
-
# Add whatever you like!
|
26
|
-
end
|
84
|
+
attr_accessor :password_confirmation
|
27
85
|
|
28
|
-
|
29
|
-
|
30
|
-
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
### CouchPotato
|
90
|
+
|
91
|
+
Include the `OmniAuth::Identity::Models::CouchPotatoModule` mixin and specify fields that you will need.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
class Identity
|
95
|
+
include CouchPotato::Persistence
|
96
|
+
include OmniAuth::Identity::Models::CouchPotatoModule
|
97
|
+
|
98
|
+
property :email
|
99
|
+
property :password_digest
|
100
|
+
|
101
|
+
def self.where search_hash
|
102
|
+
CouchPotato.database.view Identity.by_email(:key => search_hash)
|
103
|
+
end
|
104
|
+
|
105
|
+
view :by_email, :key => :email
|
106
|
+
end
|
107
|
+
```
|
31
108
|
|
32
109
|
Once you've got an Identity persistence model and the strategy up and
|
33
110
|
running, you can point users to `/auth/identity` and it will request
|
@@ -42,9 +119,11 @@ Simple!
|
|
42
119
|
To use a class other than the default, specify the <tt>:model</tt> option to a
|
43
120
|
different class.
|
44
121
|
|
45
|
-
|
46
|
-
|
47
|
-
|
122
|
+
```ruby
|
123
|
+
use OmniAuth::Builder do
|
124
|
+
provider :identity, :fields => [:email], :model => MyCustomClass
|
125
|
+
end
|
126
|
+
```
|
48
127
|
|
49
128
|
## Customizing Registration Failure
|
50
129
|
|
@@ -52,39 +131,74 @@ To use your own custom registration form, create a form that POSTs to
|
|
52
131
|
'/auth/identity/register' with 'password', 'password_confirmation', and your
|
53
132
|
other fields.
|
54
133
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
134
|
+
```erb
|
135
|
+
<%= form_tag '/auth/identity/register' do |f| %>
|
136
|
+
<h1>Create an Account</h1>
|
137
|
+
<%= text_field_tag :email %>
|
138
|
+
<%= password_field_tag :password %>
|
139
|
+
<%= password_field_tag :password_confirmation %>
|
140
|
+
<%= submit_tag %>
|
141
|
+
<% end %>
|
142
|
+
```
|
62
143
|
|
63
144
|
Beware not to nest your form parameters within a namespace. This strategy
|
64
145
|
looks for the form parameters at the top level of the post params. If you are
|
65
146
|
using [simple\_form](https://github.com/plataformatec/simple_form), then you
|
66
147
|
can avoid the params nesting by specifying <tt>:input_html</tt>.
|
67
148
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
149
|
+
```erb
|
150
|
+
<%= simple_form_for @identity, :url => '/auth/identity/register' do |f| %>
|
151
|
+
<h1>Create an Account</h1>
|
152
|
+
<%# specify :input_html to avoid params nesting %>
|
153
|
+
<%= f.input :email, :input_html => {:name => 'email'} %>
|
154
|
+
<%= f.input :password, :as => 'password', :input_html => {:name => 'password'} %>
|
155
|
+
<%= f.input :password_confirmation, :label => "Confirm Password", :as => 'password', :input_html => {:name => 'password_confirmation'} %>
|
156
|
+
<button type='submit'>Sign Up</button>
|
157
|
+
<% end %>
|
158
|
+
```
|
76
159
|
|
77
160
|
Next you'll need to let OmniAuth know what action to call when a registration
|
78
161
|
fails. In your OmniAuth configuration, specify any valid rack endpoint in the
|
79
162
|
<tt>:on_failed_registration</tt> option.
|
80
163
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
164
|
+
```ruby
|
165
|
+
use OmniAuth::Builder do
|
166
|
+
provider :identity,
|
167
|
+
:fields => [:email],
|
168
|
+
:on_failed_registration => UsersController.action(:new)
|
169
|
+
end
|
170
|
+
```
|
86
171
|
|
87
172
|
For more information on rack endpoints, check out [this
|
88
173
|
introduction](http://library.edgecase.com/Rails/2011/01/04/rails-routing-and-rack-endpoints.html)
|
89
174
|
and
|
90
175
|
[ActionController::Metal](http://rubydoc.info/docs/rails/ActionController/Metal)
|
176
|
+
|
177
|
+
## Customizing Locate Conditions
|
178
|
+
|
179
|
+
You can customize the way that matching records are found when authenticating.
|
180
|
+
For example, for a site with multiple domains, you may wish to scope the search
|
181
|
+
within a particular subdomain. To do so, add :locate_conditions to your config.
|
182
|
+
The default value is:
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
:locate_conditions => lambda { |req| { model.auth_key => req['auth_key']} }
|
186
|
+
```
|
187
|
+
|
188
|
+
locate_conditions takes a Proc object, and must return a hash. The resulting hash is used
|
189
|
+
as a parameter in the locate method for your ORM. The proc is evaluated in the
|
190
|
+
callback context, and has access to the Identity model (using `model`) and receives the request
|
191
|
+
object as a parameter. Note that model.auth_key defaults to 'email', but is also configurable.
|
192
|
+
|
193
|
+
Note: Be careful when customizing locate_conditions. The best way to modify the conditions is
|
194
|
+
to copy the default value, and then add to the hash. Removing the default condition will almost
|
195
|
+
always break things!
|
196
|
+
|
197
|
+
## License
|
198
|
+
|
199
|
+
MIT License. See LICENSE for details.
|
200
|
+
|
201
|
+
## Copyright
|
202
|
+
|
203
|
+
Copyright (c) 2020- Andrew Roberts, and Jellybooks Ltd.
|
204
|
+
Copyright (c) 2010-2015 Michael Bleigh, and Intridea, Inc.
|
data/lib/omniauth/identity.rb
CHANGED
@@ -6,12 +6,13 @@ module OmniAuth
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module Identity
|
9
|
-
autoload :Model,
|
10
|
-
autoload :SecurePassword,
|
9
|
+
autoload :Model, 'omniauth/identity/model'
|
10
|
+
autoload :SecurePassword, 'omniauth/identity/secure_password'
|
11
11
|
module Models
|
12
|
-
autoload :ActiveRecord,
|
13
|
-
|
14
|
-
autoload :
|
12
|
+
autoload :ActiveRecord, 'omniauth/identity/models/active_record'
|
13
|
+
autoload :Mongoid, 'omniauth/identity/models/mongoid'
|
14
|
+
autoload :DataMapper, 'omniauth/identity/models/data_mapper'
|
15
|
+
autoload :CouchPotatoModule, 'omniauth/identity/models/couch_potato'
|
15
16
|
end
|
16
17
|
end
|
17
18
|
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(
|
29
|
-
instance = locate(
|
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.
|
@@ -75,7 +75,7 @@ module OmniAuth
|
|
75
75
|
#
|
76
76
|
# @return [String] An identifier string unique to this identity.
|
77
77
|
def uid
|
78
|
-
if respond_to?(
|
78
|
+
if respond_to?(:id)
|
79
79
|
return nil if self.id.nil?
|
80
80
|
self.id.to_s
|
81
81
|
else
|
@@ -90,7 +90,7 @@ module OmniAuth
|
|
90
90
|
# @return [String] An identifying string that will be entered by
|
91
91
|
# users upon sign in.
|
92
92
|
def auth_key
|
93
|
-
if respond_to?(self.class.auth_key)
|
93
|
+
if respond_to?(self.class.auth_key.to_sym)
|
94
94
|
send(self.class.auth_key)
|
95
95
|
else
|
96
96
|
raise NotImplementedError
|
@@ -104,8 +104,9 @@ module OmniAuth
|
|
104
104
|
# @param [String] value The value to which the auth key should be
|
105
105
|
# set.
|
106
106
|
def auth_key=(value)
|
107
|
-
|
108
|
-
|
107
|
+
auth_key_setter = (self.class.auth_key + '=').to_sym
|
108
|
+
if respond_to?(auth_key_setter)
|
109
|
+
send(auth_key_setter, value)
|
109
110
|
else
|
110
111
|
raise NotImplementedError
|
111
112
|
end
|
@@ -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(
|
19
|
-
where(
|
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
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
require 'dm-validations'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Identity
|
6
|
+
module Models
|
7
|
+
module DataMapper
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval do
|
10
|
+
include OmniAuth::Identity::Model
|
11
|
+
include OmniAuth::Identity::SecurePassword
|
12
|
+
|
13
|
+
# http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-persisted-3F
|
14
|
+
# http://rubydoc.info/github/mongoid/mongoid/master/Mongoid/State#persisted%3F-instance_method
|
15
|
+
alias persisted? valid?
|
16
|
+
|
17
|
+
has_secure_password
|
18
|
+
|
19
|
+
def self.auth_key=(key)
|
20
|
+
super
|
21
|
+
validates_uniqueness_of :key
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.locate(search_hash)
|
25
|
+
all(search_hash).first
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end # DataMapper
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|