omniauth-identity 3.0.4 → 3.0.9

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: e5de20f544ddaf124fc1b80a0ea15d97d56572034cc985e72001e177c3da2c92
4
- data.tar.gz: 21e59364dcba511bd658c7503b4dce12fb7c26e37b7f4bec3b05c91d0d1dd4c4
3
+ metadata.gz: 3eaf9c4edfdb4716551abeeb233e63716d4bbb6a2c90d921129d05e06434c3ed
4
+ data.tar.gz: ccb786b04aa010387b3d4d7ae369038a3760d52a1b9a7077e76e3051d364ca1f
5
5
  SHA512:
6
- metadata.gz: ef710bfa64cef76922f89e93ca4292c106bda7e61cb8a49133452227f65163d2c5be70fade9ecc8d973ce35281a812d837edffe27be24689b34646c48109b07a
7
- data.tar.gz: 812f288ec96fb46afa30a61fc34caa85b4efbe8857b8fb6dbeaeab9b2c181124db8b8deea40ebbccedcfc8b78d4039dbcad609782d0955a36423e543ba293865
6
+ metadata.gz: fdbb4c0951fca595a37d1efc13491c6eaba328d77cae2184624260b9bb643c6483a0d167296a36ab168d0dd2afafbc8a3be9df1dfeb6ba9fc7cd83556c02b1c3
7
+ data.tar.gz: 9d8385b53f5e46ed414f59c6a9acbcb62734b94df6b86224e0fa401da349cd44c1af57ff54d0ec01c100d2ccd8e003ea1c062eb1a7d772b404d82c0c2eda579b
data/CHANGELOG.md CHANGED
@@ -8,6 +8,79 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [3.0.9] - 2021-06-16
12
+
13
+ ### Fixed
14
+
15
+ - \[Sequel\] Fixes loading the Sequel adapter, issue reported as [#112](https://github.com/omniauth/omniauth-identity/issues/112)
16
+
17
+ ### Added
18
+
19
+ - 📝 Document the Database adapters and drivers the gem currently works with
20
+
21
+ ## [3.0.8] - 2021-03-24
22
+
23
+ ### Fixed
24
+
25
+ - \[Model\] Fixes 2 issues raised in a comment on PR [#108](https://github.com/omniauth/omniauth-identity/pull/108#issuecomment-804456604)
26
+ - When `options[:on_validation]` is set `new`/`save`/`persisted?` logic is used.
27
+ - When `options[:on_validation]` is not set `create`/`persisted?` logic is used.
28
+
29
+ ## [3.0.7] - 2021-03-23
30
+
31
+ ### Fixed
32
+
33
+ - \[ActiveRecord\] Fixed [#110](https://github.com/omniauth/omniauth-identity/issues/110) which prevented `OmniAuth::Identity::Models::ActiveRecord`-based records from saving.
34
+ - \[CouchPotato\] Fixed `OmniAuth::Identity::Models::CouchPotato`'s `#save`.
35
+ - \[Sequel\] Fixed `OmniAuth::Identity::Models::Sequel`'s `#save`.
36
+ - \[Model\] Only define `::create`, `#save`, and `#persisted?` when not already defined.
37
+ - \[Model\] Restore original `info` functionality which set `name` based on `first_name`, `last_name`, or `nickname`
38
+
39
+ ### Changed
40
+
41
+ - 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)
42
+ - Aeons ago the original was ripped from Rails 3.1, and frozen in time.
43
+ While writing specs, it was discovered to be incompatible with this gem's Sequel adapter.
44
+ - Specs validate that the new version does work.
45
+ In any case, the ripped version is only used when the `has_secure_password` macro is not yet defined in the class.
46
+
47
+ ### Added
48
+
49
+ - New specs to cover real use cases and implementations of each ORM model adapter that ships with the gem:
50
+ - ActiveRecord (Polyglot - Many Relational Databases)
51
+ - Sequel (Polyglot - Many Relational Databases)
52
+ - CouchPotato (CouchDB)
53
+ - Mongoid (MongoDB)
54
+ - NoBrainer (RethinkDB)
55
+
56
+ ## [3.0.6] - 2021-03-20
57
+
58
+ ### Fixed
59
+
60
+ - Fix breaking changes introduced by [#108](https://github.com/omniauth/omniauth-identity/pull/108) which prevented `:on_validation` from firing
61
+
62
+ ### Added
63
+
64
+ - New (or finally documented) options:
65
+ - `:create_identity_link_text` defaults to `'Create an Identity'`
66
+ - `:registration_failure_message` defaults to `'One or more fields were invalid'`
67
+ - `:validation_failure_message` defaults to `'Validation failed'`
68
+ - `:title` defaults to `'Identity Verification'`
69
+ - `:registration_form_title` defaults to `'Register Identity'`
70
+
71
+ ## [3.0.5] - 2021-03-19
72
+
73
+ ### Fixed
74
+
75
+ - Fix breaking changes introduced by [#86's](https://github.com/omniauth/omniauth-identity/pull/86) introduction of `:on_validation`
76
+
77
+ ### Added
78
+
79
+ - Define `#save`, `#persisted?` and `::create` on `Omniauth::Identity::Model`
80
+ - Add `@since` YARD tags to interface methods
81
+ - Refactor `Omniauth::Strategies::Identity.registration_phase` to support `Omniauth::Identity::Model`-inheriting classes that do not define `#save`.
82
+ - This support will be dropped in v4.0.
83
+
11
84
  ## [3.0.4] - 2021-02-14
12
85
 
13
86
  ### Added
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  [![Downloads Rank](https://img.shields.io/gem/rd/omniauth-identity.svg)](https://rubygems.org/gems/omniauth-identity)
11
11
 
12
12
  The OmniAuth Identity gem provides a way for applications to utilize a
13
- traditional login/password based authentication system without the need
13
+ traditional username/password based authentication system without the need
14
14
  to give up the simple authentication flow provided by OmniAuth. Identity
15
15
  is designed on purpose to be as featureless as possible: it provides the
16
16
  basic construct for user management and then gets out of the way.
@@ -21,6 +21,15 @@ This gem is compatible with, as of Feb 2021, version 3:
21
21
 
22
22
  * Latest released version of omniauth, v2.0.2
23
23
  * Ruby 2.4, 2.5, 2.6, 2.7, 3.0, ruby-head
24
+ * At least 5 different database ORM adapters, which connect to 15 different database clients!
25
+
26
+ | Databases | Adapter Libraries |
27
+ |--------- | -------- |
28
+ | MySQL, PostgreSQL, SQLite3 | [ActiveRecord](https://guides.rubyonrails.org/active_record_basics.html) |
29
+ | CouchDB | [CouchPotato](https://github.com/langalex/couch_potato) |
30
+ | MongoDB | [Mongoid](https://github.com/mongodb/mongoid) |
31
+ | RethinkDB | [NoBrainer](http://nobrainer.io/) |
32
+ | ADO, Amalgalite, IBM_DB, JDBC, MySQL, Mysql2, ODBC, Oracle, PostgreSQL, SQLAnywhere, SQLite3, and TinyTDS | [Sequel](http://sequel.jeremyevans.net) |
24
33
 
25
34
  ## Installation
26
35
 
@@ -93,8 +102,8 @@ Just include `OmniAuth::Identity::Models::Sequel` mixin, and specify
93
102
  whatever else you will need.
94
103
 
95
104
  ```ruby
96
- class SequelTestIdentity < Sequel::Model
97
- include OmniAuth::Identity::Models::Sequel
105
+ class SequelTestIdentity < Sequel::Model(:identities)
106
+ include ::OmniAuth::Identity::Models::Sequel
98
107
  auth_key :email
99
108
  # whatever else you want!
100
109
  end
@@ -108,8 +117,8 @@ fields that you will need.
108
117
 
109
118
  ```ruby
110
119
  class Identity
111
- include Mongoid::Document
112
- include OmniAuth::Identity::Models::Mongoid
120
+ include ::Mongoid::Document
121
+ include ::OmniAuth::Identity::Models::Mongoid
113
122
 
114
123
  field :email, type: String
115
124
  field :name, type: String
@@ -124,8 +133,9 @@ fields that you will need.
124
133
 
125
134
  ```ruby
126
135
  class Identity
127
- include CouchPotato::Persistence
128
- include OmniAuth::Identity::Models::CouchPotatoModule
136
+ # NOTE: CouchPotato::Persistence must be included before OmniAuth::Identity::Models::CouchPotatoModule
137
+ include ::CouchPotato::Persistence
138
+ include ::OmniAuth::Identity::Models::CouchPotatoModule
129
139
 
130
140
  property :email
131
141
  property :password_digest
@@ -147,8 +157,8 @@ fields that you will need.
147
157
 
148
158
  ```ruby
149
159
  class Identity
150
- include NoBrainer::Document
151
- include OmniAuth::Identity::Models::NoBrainer
160
+ include ::NoBrainer::Document
161
+ include ::OmniAuth::Identity::Models::NoBrainer
152
162
 
153
163
  auth_key :email
154
164
  end
@@ -170,7 +180,7 @@ end
170
180
  ```
171
181
 
172
182
  NOTE: In the above example, `MyCustomClass` must have a class method called `auth_key` that returns
173
- the default (`email`) or custom `auth_key` to use.
183
+ the default (`email`) or custom `auth_key` to use.
174
184
 
175
185
  ## Customizing Registration Failure
176
186
 
@@ -245,12 +255,76 @@ Note: Be careful when customizing `locate_conditions`. The best way to modify t
245
255
  to copy the default value, and then add to the hash. Removing the default condition will almost
246
256
  always break things!
247
257
 
258
+ ## Customizing Other Things
259
+
260
+ 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!?
261
+ ```
262
+ option :fields, %i[name email]
263
+
264
+ # Primary Feature Switches:
265
+ option :enable_registration, true # See #other_phase and #request_phase
266
+ option :enable_login, true # See #other_phase
267
+
268
+ # Customization Options:
269
+ option :on_login, nil # See #request_phase
270
+ option :on_validation, nil # See #registration_phase
271
+ option :on_registration, nil # See #registration_phase
272
+ option :on_failed_registration, nil # See #registration_phase
273
+ option :locate_conditions, ->(req) { { model.auth_key => req['auth_key'] } }
274
+ ```
275
+
276
+ 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. 😭
277
+
278
+ ## Contributing
279
+
280
+ 1. Fork it
281
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
282
+ 3. Commit your changes (`git commit -am ‘Added some feature’`)
283
+ 4. Push to the branch (`git push origin my-new-feature`)
284
+ 5. Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
285
+ - NOTE: In order to run *all* the tests you will need to have the following databases installed, configured, and running.
286
+ 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.
287
+ ```bash
288
+ brew install rethinkdb
289
+ rethinkdb
290
+ ```
291
+ 2. [MongoDB](https://docs.mongodb.com/manual/administration/install-community/)
292
+ ```bash
293
+ brew tap mongodb/brew
294
+ brew install mongodb-community@4.4
295
+ mongod --config /usr/local/etc/mongod.conf
296
+ ```
297
+ 3. [CouchDB](https://couchdb.apache.org) (download the .app)
298
+
299
+ To run all tests on all databases:
300
+ ```bash
301
+ bundle exec rake
302
+ ```
303
+ To run a specific DB:
304
+ ```bash
305
+ # CouchDB / CouchPotato
306
+ bundle exec rspec spec spec_orms --tag 'couchdb'
307
+
308
+ # ActiveRecord and Sequel, as they both use the in-memory SQLite driver.
309
+ bundle exec rspec spec spec_orms --tag 'sqlite3'
310
+
311
+ # NOTE - mongoid and nobrainer specs can't be isolated with "tag" because it still loads everything,
312
+ # and the two libraries are fundamentally incompatible.
313
+
314
+ # MongoDB / Mongoid
315
+ bundle exec rspec spec_orms/mongoid_spec.rb
316
+
317
+ # RethinkDB / NoBrainer
318
+ bundle exec rspec spec_orms/nobrainer_spec.rb
319
+ ```
320
+ 6. Create new Pull Request
321
+
248
322
  ## License
249
323
 
250
324
  MIT License. See LICENSE for details.
251
325
 
252
326
  ## Copyright
253
327
 
254
- Copyright (c) 2021 OmniAuth-Identity Maintainers
255
- Copyright (c) 2020 Peter Boling, Andrew Roberts, and Jellybooks Ltd.
256
- Copyright (c) 2010-2015 Michael Bleigh, and Intridea, Inc.
328
+ * Copyright (c) 2021 OmniAuth-Identity Maintainers
329
+ * Copyright (c) 2020 Peter Boling, Andrew Roberts, and Jellybooks Ltd.
330
+ * 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.4'
5
+ VERSION = '3.0.9'
6
6
  end
7
7
  end
@@ -14,7 +14,7 @@ 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/no_brainer'
17
+ autoload :NoBrainer, 'omniauth/identity/models/nobrainer'
18
18
  autoload :Sequel, 'omniauth/identity/models/sequel'
19
19
  end
20
20
  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.
@@ -43,6 +53,56 @@ module OmniAuth
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
@@ -5,9 +5,12 @@ require 'active_record'
5
5
  module OmniAuth
6
6
  module Identity
7
7
  module Models
8
+ # ActiveRecord is an ORM for MySQL, PostgreSQL, and SQLite3:
9
+ # https://guides.rubyonrails.org/active_record_basics.html
10
+ # NOTE: ActiveRecord is based on ActiveModel.
8
11
  class ActiveRecord < ::ActiveRecord::Base
9
- include OmniAuth::Identity::Model
10
- include OmniAuth::Identity::SecurePassword
12
+ include ::OmniAuth::Identity::Model
13
+ include ::OmniAuth::Identity::SecurePassword
11
14
 
12
15
  self.abstract_class = true
13
16
  has_secure_password
@@ -5,7 +5,11 @@ require 'couch_potato'
5
5
  module OmniAuth
6
6
  module Identity
7
7
  module Models
8
- # can not be named CouchPotato since there is a class with that name
8
+ # CouchPotato is an ORM adapter for CouchDB:
9
+ # https://github.com/langalex/couch_potato
10
+ # NOTE: CouchPotato is based on ActiveModel.
11
+ # NOTE: CouchPotato::Persistence must be included before OmniAuth::Identity::Models::CouchPotatoModule
12
+ # NOTE: Includes "Module" in the name for invalid legacy reasons. Rename only with a major version bump.
9
13
  module CouchPotatoModule
10
14
  def self.included(base)
11
15
  base.class_eval do
@@ -22,6 +26,10 @@ module OmniAuth
22
26
  def self.locate(search_hash)
23
27
  where(search_hash).first
24
28
  end
29
+
30
+ def save
31
+ CouchPotato.database.save(self)
32
+ end
25
33
  end
26
34
  end
27
35
  end