omniauth-identity 3.0.2 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e337a130887896ec09b2aa2a66fa1064a87b5aad59d1e068d484a2d2666f691
4
- data.tar.gz: 7cdf49c8f0dc5db0d481233c91f9800932880d243f2c8311dc9336d3830d1296
3
+ metadata.gz: 89bd05bb3cf63c0a47e41c8f955f9b076d5c6b4ae0704eda10819f801eaa6059
4
+ data.tar.gz: a272f35f9bcc0de8937279904e2bde912865b50ac3a7752dada19f0ec7d6868c
5
5
  SHA512:
6
- metadata.gz: 83e043a28067c4e22ce4be6932901eea262846000623626e73f9b6efa3ee2cd8a63263d93240d81173533d8db4e3a86815bf653814b26ced28b16b29e4787762
7
- data.tar.gz: b12161b52c4d4f3b2d5e19d954ad965f0a7c73d4622a50f8004c2659ccd06445f19e20db23c81926f3ff9dc74930739f3f31d69c4da351e1208ea055832700a6
6
+ metadata.gz: 26286ae10ba06b45b815bd21892ac27378eb338e446f0dcbe96037a8aa51d4097b55243ae12f5feef133577b1d793ce4732f636f930a6773c6b7e154e6256b4c
7
+ data.tar.gz: 11fc92beba0b8b849c1ce15784870bf4318aeaea14e5c7172f9c26b1891e357ba9603106765a5b2554c20d177a17c5e820bdb01733de169f3e67ec192f8d42e4
data/CHANGELOG.md CHANGED
@@ -8,6 +8,80 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [3.0.7] - 2021-03-23
12
+
13
+ ### Fixed
14
+
15
+ - \[ActiveRecord\] Fixed [#110](https://github.com/omniauth/omniauth-identity/issues/110) which prevented `OmniAuth::Identity::Models::ActiveRecord`-based records from saving.
16
+ - \[CouchPotato\] Fixed `OmniAuth::Identity::Models::CouchPotato`'s `#save`.
17
+ - \[Sequel\] Fixed `OmniAuth::Identity::Models::Sequel`'s `#save`.
18
+ - \[Model\] Only define `::create`, `#save`, and `#persisted?` when not already defined.
19
+ - \[Model\] Restore original `info` functionality which set `name` based on `first_name`, `last_name`, or `nickname`
20
+
21
+ ### Changed
22
+
23
+ - Upgraded to a newer `OmniAuth::Identity::SecurePassword` ripped from [Rails 6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activemodel/lib/active_model/secure_password.rb)
24
+ - Aeons ago the original was ripped from Rails 3.1, and frozen in time.
25
+ While writing specs, it was discovered to be incompatible with this gem's Sequel adapter.
26
+ - Specs validate that the new version does work.
27
+ In any case, the ripped version is only used when the `has_secure_password` macro is not yet defined in the class.
28
+
29
+ ### Added
30
+
31
+ - New specs to cover real use cases and implementations of each ORM model adapter that ships with the gem:
32
+ - ActiveRecord (Polyglot - Many Relational Databases)
33
+ - Sequel (Polyglot - Many Relational Databases)
34
+ - CouchPotato (CouchDB)
35
+ - Mongoid (MongoDB)
36
+ - NoBrainer (RethinkDB)
37
+
38
+ ## [3.0.6] - 2021-03-20
39
+
40
+ ### Fixed
41
+
42
+ - Fix breaking changes introduced by [#108](https://github.com/omniauth/omniauth-identity/pull/108) which prevented `:on_validation` from firing
43
+
44
+ ### Added
45
+
46
+ - New (or finally documented) options:
47
+ - `:create_identity_link_text` defaults to `'Create an Identity'`
48
+ - `:registration_failure_message` defaults to `'One or more fields were invalid'`
49
+ - `:validation_failure_message` defaults to `'Validation failed'`
50
+ - `:title` defaults to `'Identity Verification'`
51
+ - `:registration_form_title` defaults to `'Register Identity'`
52
+
53
+ ## [3.0.5] - 2021-03-19
54
+
55
+ ### Fixed
56
+
57
+ - Fix breaking changes introduced by [#86's](https://github.com/omniauth/omniauth-identity/pull/86) introduction of `:on_validation`
58
+
59
+ ### Added
60
+
61
+ - Define `#save`, `#persisted?` and `::create` on `Omniauth::Identity::Model`
62
+ - Add `@since` YARD tags to interface methods
63
+ - Refactor `Omniauth::Strategies::Identity.registration_phase` to support `Omniauth::Identity::Model`-inheriting classes that do not define `#save`.
64
+ - This support will be dropped in v4.0.
65
+
66
+ ## [3.0.4] - 2021-02-14
67
+
68
+ ### Added
69
+
70
+ - Add support for [sequel ORM](http://sequel.jeremyevans.net/)
71
+
72
+ ## [3.0.3] - 2021-02-14
73
+
74
+ ### Added
75
+
76
+ - Add option `:on_validation`, which can be used to add a Captcha
77
+ - See [example here](https://github.com/omniauth/omniauth-identity/pull/86#issue-63225122)
78
+ - Add support for nobrainer, an ORM for RethinkDB
79
+ - Validation error message on invalid registration form submission
80
+
81
+ ### Removed
82
+
83
+ - ruby-head build... simply too slow
84
+
11
85
  ## [3.0.2] - 2021-02-14
12
86
 
13
87
  ### Fixed
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # OmniAuth Identity
2
2
 
3
+ [![Version](https://img.shields.io/gem/v/omniauth-identity.svg)](https://rubygems.org/gems/omniauth-identity)
4
+ [![Depfu](https://badges.depfu.com/badges/6c9b45362951b872127f9e46d39bed76/count.svg)](https://depfu.com/github/omniauth/omniauth-identity?project_id=22381)
3
5
  [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fomniauth%2Fomniauth-identity%2Fbadge&style=flat)](https://actions-badge.atrox.dev/omniauth/omniauth-identity/goto)
4
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/621d6211cb2e0959ce00/maintainability)](https://codeclimate.com/github/omniauth/omniauth-identity/maintainability)
5
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/621d6211cb2e0959ce00/test_coverage)](https://codeclimate.com/github/omniauth/omniauth-identity/test_coverage)
@@ -8,7 +10,7 @@
8
10
  [![Downloads Rank](https://img.shields.io/gem/rd/omniauth-identity.svg)](https://rubygems.org/gems/omniauth-identity)
9
11
 
10
12
  The OmniAuth Identity gem provides a way for applications to utilize a
11
- traditional login/password based authentication system without the need
13
+ traditional username/password based authentication system without the need
12
14
  to give up the simple authentication flow provided by OmniAuth. Identity
13
15
  is designed on purpose to be as featureless as possible: it provides the
14
16
  basic construct for user management and then gets out of the way.
@@ -17,7 +19,7 @@ basic construct for user management and then gets out of the way.
17
19
 
18
20
  This gem is compatible with, as of Feb 2021, version 3:
19
21
 
20
- * Latest released version of omniauth, v2.0.2
22
+ * Latest released version of omniauth, v2.0.2
21
23
  * Ruby 2.4, 2.5, 2.6, 2.7, 3.0, ruby-head
22
24
 
23
25
  ## Installation
@@ -56,6 +58,13 @@ with `:model` argument above) that will be able to persist the information
56
58
  provided by the user. Luckily for you, there are pre-built models for popular
57
59
  ORMs that make this dead simple.
58
60
 
61
+ Once you've got an `Identity` persistence model and the strategy up and
62
+ running, you can point users to `/auth/identity` and it will request
63
+ that they log in or give them the opportunity to sign up for an account.
64
+ Once they have authenticated with their identity, OmniAuth will call
65
+ through to `/auth/identity/callback` with the same kinds of information
66
+ it would had the user authenticated through an external provider.
67
+
59
68
  **Note:** OmniAuth Identity is different from many other user authentication
60
69
  systems in that it is *not* built to store authentication information in your primary
61
70
  `User` model. Instead, the `Identity` model should be **associated** with your
@@ -76,57 +85,48 @@ class Identity < OmniAuth::Identity::Models::ActiveRecord
76
85
  end
77
86
  ```
78
87
 
79
- ### Mongoid
88
+ ### Sequel
80
89
 
81
- Include the `OmniAuth::Identity::Models::Mongoid` mixin and specify
82
- fields that you will need.
90
+ [Sequel](http://sequel.jeremyevans.net/) is an alternative to ActiveRecord.
83
91
 
84
- ```ruby
85
- class Identity
86
- include Mongoid::Document
87
- include OmniAuth::Identity::Models::Mongoid
92
+ Just include `OmniAuth::Identity::Models::Sequel` mixin, and specify
93
+ whatever else you will need.
88
94
 
89
- field :email, type: String
90
- field :name, type: String
91
- field :password_digest, type: String
95
+ ```ruby
96
+ class SequelTestIdentity < Sequel::Model(:identities)
97
+ include ::OmniAuth::Identity::Models::Sequel
98
+ auth_key :email
99
+ # whatever else you want!
92
100
  end
93
101
  ```
94
102
 
95
- ### MongoMapper
96
-
97
- Unfortunately MongoMapper is **not supported** in `omniauth-identity` from >= v2.0 as a result of it
98
- not being maintained for several years.
99
-
100
- It wasn't possible to include Mongoid *and* MongoMapper due to incompatible gem version
101
- requirements. Therefore precedence was given to Mongoid as it is significantly more
102
- popular and actively maintained.
103
103
 
104
- ### DataMapper
104
+ ### Mongoid
105
105
 
106
- Include the `OmniAuth::Identity::Models::DataMapper` mixin and specify
106
+ Include the `OmniAuth::Identity::Models::Mongoid` mixin and specify
107
107
  fields that you will need.
108
108
 
109
109
  ```ruby
110
110
  class Identity
111
- include DataMapper::Resource
112
- include OmniAuth::Identity::Models::DataMapper
113
-
114
- property :id, Serial
115
- property :email, String
116
- property :password_digest, Text
111
+ include ::Mongoid::Document
112
+ include ::OmniAuth::Identity::Models::Mongoid
117
113
 
118
- attr_accessor :password_confirmation
114
+ field :email, type: String
115
+ field :name, type: String
116
+ field :password_digest, type: String
119
117
  end
120
118
  ```
121
119
 
122
120
  ### CouchPotato
123
121
 
124
- Include the `OmniAuth::Identity::Models::CouchPotatoModule` mixin and specify fields that you will need.
122
+ Include the `OmniAuth::Identity::Models::CouchPotatoModule` mixin and specify
123
+ fields that you will need.
125
124
 
126
125
  ```ruby
127
126
  class Identity
128
- include CouchPotato::Persistence
129
- include OmniAuth::Identity::Models::CouchPotatoModule
127
+ # NOTE: CouchPotato::Persistence must be included before OmniAuth::Identity::Models::CouchPotatoModule
128
+ include ::CouchPotato::Persistence
129
+ include ::OmniAuth::Identity::Models::CouchPotatoModule
130
130
 
131
131
  property :email
132
132
  property :password_digest
@@ -139,13 +139,25 @@ class Identity
139
139
  end
140
140
  ```
141
141
 
142
- Once you've got an `Identity` persistence model and the strategy up and
143
- running, you can point users to `/auth/identity` and it will request
144
- that they log in or give them the opportunity to sign up for an account.
145
- Once they have authenticated with their identity, OmniAuth will call
146
- through to `/auth/identity/callback` with the same kinds of information
147
- it would had the user authenticated through an external provider.
148
- Simple!
142
+ ### NoBrainer
143
+
144
+ [NoBrainer](http://nobrainer.io/) is an ORM for [RethinkDB](https://rethinkdb.com/).
145
+
146
+ Include the `OmniAuth::Identity::Models::NoBrainer` mixin and specify
147
+ fields that you will need.
148
+
149
+ ```ruby
150
+ class Identity
151
+ include ::NoBrainer::Document
152
+ include ::OmniAuth::Identity::Models::NoBrainer
153
+
154
+ auth_key :email
155
+ end
156
+ ```
157
+
158
+ ### Ruby Object Mapper
159
+
160
+ Would love to add a mixin for the [Ruby Object Mapper (ROM)](https://rom-rb.org/) if anyone wants to work on it!
149
161
 
150
162
  ## Custom Auth Model
151
163
 
@@ -234,12 +246,75 @@ Note: Be careful when customizing `locate_conditions`. The best way to modify t
234
246
  to copy the default value, and then add to the hash. Removing the default condition will almost
235
247
  always break things!
236
248
 
249
+ ## Customizing Other Things
250
+
251
+ From the code - here are the options we have for you, a couple of which are documented above, and the rest are documented... in the specs we hope!?
252
+ ```
253
+ option :fields, %i[name email]
254
+
255
+ # Primary Feature Switches:
256
+ option :enable_registration, true # See #other_phase and #request_phase
257
+ option :enable_login, true # See #other_phase
258
+
259
+ # Customization Options:
260
+ option :on_login, nil # See #request_phase
261
+ option :on_validation, nil # See #registration_phase
262
+ option :on_registration, nil # See #registration_phase
263
+ option :on_failed_registration, nil # See #registration_phase
264
+ option :locate_conditions, ->(req) { { model.auth_key => req['auth_key'] } }
265
+ ```
266
+
267
+ Please contribute some documentation if you have the gumption! The maintainer's time is limited, and sometimes the authors of PRs with new options don't update the _this_ readme. 😭
268
+
269
+ ## Contributing
270
+
271
+ 1. Fork it
272
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
273
+ 3. Commit your changes (`git commit -am ‘Added some feature’`)
274
+ 4. Push to the branch (`git push origin my-new-feature`)
275
+ 5. Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
276
+ - NOTE: In order to run *all* the tests you will need to have the following databases installed, configured, and running.
277
+ 1. [RethinkDB](https://rethinkdb.com), an open source, real-time, web database, [installed](https://rethinkdb.com/docs/install/) and [running](https://rethinkdb.com/docs/start-a-server/), e.g.
278
+ ```bash
279
+ brew install rethinkdb
280
+ rethinkdb
281
+ ```
282
+ 2. [MongoDB](https://docs.mongodb.com/manual/administration/install-community/)
283
+ ```bash
284
+ brew tap mongodb/brew
285
+ brew install mongodb-community@4.4
286
+ mongod --config /usr/local/etc/mongod.conf
287
+ ```
288
+ 3. [CouchDB](https://couchdb.apache.org) (download the .app)
289
+ To run all tests on all databases:
290
+ ```bash
291
+ bundle exec rake
292
+ ```
293
+ To run a specific DB:
294
+ ```bash
295
+ # CouchDB / CouchPotato
296
+ bundle exec rspec spec spec_orms --tag 'couchdb'
297
+
298
+ # ActiveRecord and Sequel, as they both use the in-memory SQLite driver.
299
+ bundle exec rspec spec spec_orms --tag 'sqlite3'
300
+
301
+ # NOTE - mongoid and nobrainer specs can't be isolated with "tag" because it still loads everything,
302
+ # and the two libraries are fundamentally incompatible.
303
+
304
+ # MongoDB / Mongoid
305
+ bundle exec rspec spec_orms/mongoid_spec.rb
306
+
307
+ # RethinkDB / NoBrainer
308
+ bundle exec rspec spec_orms/nobrainer_spec.rb
309
+ ```
310
+ 6. Create new Pull Request
311
+
237
312
  ## License
238
313
 
239
314
  MIT License. See LICENSE for details.
240
315
 
241
316
  ## Copyright
242
317
 
243
- Copyright (c) 2021 OmniAuth-Identity Maintainers
244
- Copyright (c) 2020 Peter Boling, Andrew Roberts, and Jellybooks Ltd.
245
- Copyright (c) 2010-2015 Michael Bleigh, and Intridea, Inc.
318
+ * Copyright (c) 2021 OmniAuth-Identity Maintainers
319
+ * Copyright (c) 2020 Peter Boling, Andrew Roberts, and Jellybooks Ltd.
320
+ * Copyright (c) 2010-2015 Michael Bleigh, and Intridea, Inc.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAuth
4
4
  module Identity
5
- VERSION = '3.0.2'
5
+ VERSION = '3.0.7'
6
6
  end
7
7
  end
@@ -14,6 +14,8 @@ module OmniAuth
14
14
  autoload :ActiveRecord, 'omniauth/identity/models/active_record'
15
15
  autoload :Mongoid, 'omniauth/identity/models/mongoid'
16
16
  autoload :CouchPotatoModule, 'omniauth/identity/models/couch_potato'
17
+ autoload :NoBrainer, 'omniauth/identity/models/nobrainer'
18
+ autoload :Sequel, 'omniauth/identity/models/sequel'
17
19
  end
18
20
  end
19
21
  end
@@ -4,24 +4,34 @@ module OmniAuth
4
4
  module Identity
5
5
  # This module provides an includable interface for implementing the
6
6
  # necessary API for OmniAuth Identity to properly locate identities
7
- # and provide all necessary information. All methods marked as
8
- # abstract must be implemented in the including class for things to
9
- # work properly.
7
+ # and provide all necessary information.
8
+ #
9
+ # All methods marked as abstract must be implemented in the
10
+ # including class for things to work properly.
11
+ #
12
+ ### Singleton API
13
+ #
14
+ # * locate(key)
15
+ # * create(*args) - Deprecated in v3.0.5; Will be removed in v4.0
16
+ #
17
+ ### Instance API
18
+ #
19
+ # * save
20
+ # * persisted?
21
+ # * authenticate(password)
22
+ #
10
23
  module Model
24
+ SCHEMA_ATTRIBUTES = %w[name email nickname first_name last_name location description image phone].freeze
25
+
11
26
  def self.included(base)
12
27
  base.extend ClassMethods
28
+ base.extend ClassCreateApi unless base.respond_to?(:create)
29
+ im = base.instance_methods
30
+ base.include InstanceSaveApi unless im.include?(:save)
31
+ base.include InstancePersistedApi unless im.include?(:persisted?)
13
32
  end
14
33
 
15
34
  module ClassMethods
16
- # Locate an identity given its unique login key.
17
- #
18
- # @abstract
19
- # @param [String] key The unique login key.
20
- # @return [Model] An instance of the identity model class.
21
- def locate(key)
22
- raise NotImplementedError
23
- end
24
-
25
35
  # Authenticate a user with the given key and password.
26
36
  #
27
37
  # @param [String] key The unique login key provided for a given identity.
@@ -39,10 +49,60 @@ module OmniAuth
39
49
  # @return [String] The method name.
40
50
  def auth_key(method = false)
41
51
  @auth_key = method.to_s unless method == false
42
- @auth_key = nil if @auth_key == ''
52
+ @auth_key = nil if !defined?(@auth_key) || @auth_key == ''
43
53
 
44
54
  @auth_key || 'email'
45
55
  end
56
+
57
+ # Locate an identity given its unique login key.
58
+ #
59
+ # @abstract
60
+ # @param [String] key The unique login key.
61
+ # @return [Model] An instance of the identity model class.
62
+ def locate(_key)
63
+ raise NotImplementedError
64
+ end
65
+ end
66
+
67
+ module ClassCreateApi
68
+ # Persists a new Identity object to the ORM.
69
+ # Only included if the class doesn't define create, as a reminder to define create.
70
+ # Override as needed per ORM.
71
+ #
72
+ # @deprecated v4.0 will begin using {#new} with {#save} instead.
73
+ # @abstract
74
+ # @param [Hash] args Attributes of the new instance.
75
+ # @return [Model] An instance of the identity model class.
76
+ # @since 3.0.5
77
+ def create(*_args)
78
+ raise NotImplementedError
79
+ end
80
+ end
81
+
82
+ module InstanceSaveApi
83
+ # Persists a new Identity object to the ORM.
84
+ # Default raises an error. Override as needed per ORM.
85
+ # This base version's arguments are modeled after ActiveModel
86
+ # since it is a pattern many ORMs follow
87
+ #
88
+ # @abstract
89
+ # @return [Model] An instance of the identity model class.
90
+ # @since 3.0.5
91
+ def save(**_options, &_block)
92
+ raise NotImplementedError
93
+ end
94
+ end
95
+
96
+ module InstancePersistedApi
97
+ # Checks if the Identity object is persisted in the ORM.
98
+ # Default raises an error. Override as needed per ORM.
99
+ #
100
+ # @abstract
101
+ # @return [true or false] true if object exists, false if not.
102
+ # @since 3.0.5
103
+ def persisted?
104
+ raise NotImplementedError
105
+ end
46
106
  end
47
107
 
48
108
  # Returns self if the provided password is correct, false
@@ -51,26 +111,10 @@ module OmniAuth
51
111
  # @abstract
52
112
  # @param [String] password The password to check.
53
113
  # @return [self or false] Self if authenticated, false if not.
54
- def authenticate(password)
114
+ def authenticate(_password)
55
115
  raise NotImplementedError
56
116
  end
57
117
 
58
- SCHEMA_ATTRIBUTES = %w[name email nickname first_name last_name location description image phone].freeze
59
- # A hash of as much of the standard OmniAuth schema as is stored
60
- # in this particular model. By default, this will call instance
61
- # methods for each of the attributes it needs in turn, ignoring
62
- # any for which `#respond_to?` is `false`.
63
- #
64
- # If `first_name`, `nickname`, and/or `last_name` is provided but
65
- # `name` is not, it will be automatically calculated.
66
- #
67
- # @return [Hash] A string-keyed hash of user information.
68
- def info
69
- SCHEMA_ATTRIBUTES.each_with_object({}) do |attribute, hash|
70
- hash[attribute] = send(attribute) if respond_to?(attribute)
71
- end
72
- end
73
-
74
118
  # An identifying string that must be globally unique to the
75
119
  # application. Defaults to stringifying the `id` method.
76
120
  #
@@ -113,6 +157,25 @@ module OmniAuth
113
157
  raise NotImplementedError
114
158
  end
115
159
  end
160
+
161
+ # A hash of as much of the standard OmniAuth schema as is stored
162
+ # in this particular model. By default, this will call instance
163
+ # methods for each of the attributes it needs in turn, ignoring
164
+ # any for which `#respond_to?` is `false`.
165
+ #
166
+ # If `first_name`, `nickname`, and/or `last_name` is provided but
167
+ # `name` is not, it will be automatically calculated.
168
+ #
169
+ # @return [Hash] A string-keyed hash of user information.
170
+ def info
171
+ info = {}
172
+ SCHEMA_ATTRIBUTES.each_with_object(info) do |attribute, hash|
173
+ hash[attribute] = send(attribute) if respond_to?(attribute)
174
+ end
175
+ info['name'] ||= [info['first_name'], info['last_name']].join(' ').strip if info['first_name'] || info['last_name']
176
+ info['name'] ||= info['nickname']
177
+ info
178
+ end
116
179
  end
117
180
  end
118
181
  end