omniauth-identity 3.0.4 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +24 -4
- data/lib/omniauth-identity/version.rb +1 -1
- data/lib/omniauth/identity/model.rb +81 -27
- data/lib/omniauth/identity/models/couch_potato.rb +1 -0
- data/lib/omniauth/identity/models/mongoid.rb +1 -0
- data/lib/omniauth/identity/models/no_brainer.rb +1 -0
- data/lib/omniauth/identity/models/sequel.rb +11 -0
- data/lib/omniauth/strategies/identity.rb +52 -20
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e486fff1d58be9ad944402aa2952bfceca493c6e78f1ba8c1e29cf6142543b01
|
4
|
+
data.tar.gz: a4be9557b902ff9dfe779baea964477aaf127519f8e389b82aa3cd83af3041da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f4d5a82e3ee782716992b1183cac66e6a29cee8037a8491a56bb8dd832ee9f22946eee7900d9e1d8d20d9bc5dcce3336652f25f606f027e87d79be6a9a00c6d
|
7
|
+
data.tar.gz: f2de6f02475fe119947bd6ba2f66e9585664b522833180e5327fcda8aa3b92c8fcb95d3bfb6baf45724851c1dd6c2a8144fe473f70715c6399b8025d73b195b2
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
8
8
|
|
9
9
|
## [Unreleased]
|
10
10
|
|
11
|
+
## [3.0.5] - 2021-03-19
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
- Fix breaking changes introduced by [#86's](https://github.com/omniauth/omniauth-identity/pull/86) introduction of `:on_validation`
|
16
|
+
|
17
|
+
### Added
|
18
|
+
|
19
|
+
- Define `#save`, `#persisted?` and `::create` on `Omniauth::Identity::Model`
|
20
|
+
- Add `@since` YARD tags to interface methods
|
21
|
+
- Refactor `Omniauth::Strategies::Identity.registration_phase` to support `Omniauth::Identity::Model`-inheriting classes that do not define `#save`.
|
22
|
+
- This support will be dropped in v4.0.
|
23
|
+
|
11
24
|
## [3.0.4] - 2021-02-14
|
12
25
|
|
13
26
|
### 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
|
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.
|
@@ -245,12 +245,32 @@ Note: Be careful when customizing `locate_conditions`. The best way to modify t
|
|
245
245
|
to copy the default value, and then add to the hash. Removing the default condition will almost
|
246
246
|
always break things!
|
247
247
|
|
248
|
+
## Customizing Other Things
|
249
|
+
|
250
|
+
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!?
|
251
|
+
```
|
252
|
+
option :fields, %i[name email]
|
253
|
+
|
254
|
+
# Primary Feature Switches:
|
255
|
+
option :enable_registration, true # See #other_phase and #request_phase
|
256
|
+
option :enable_login, true # See #other_phase
|
257
|
+
|
258
|
+
# Customization Options:
|
259
|
+
option :on_login, nil # See #request_phase
|
260
|
+
option :on_validation, nil # See #registration_phase
|
261
|
+
option :on_registration, nil # See #registration_phase
|
262
|
+
option :on_failed_registration, nil # See #registration_phase
|
263
|
+
option :locate_conditions, ->(req) { { model.auth_key => req['auth_key'] } }
|
264
|
+
```
|
265
|
+
|
266
|
+
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. 😭
|
267
|
+
|
248
268
|
## License
|
249
269
|
|
250
270
|
MIT License. See LICENSE for details.
|
251
271
|
|
252
272
|
## Copyright
|
253
273
|
|
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.
|
274
|
+
* Copyright (c) 2021 OmniAuth-Identity Maintainers
|
275
|
+
* Copyright (c) 2020 Peter Boling, Andrew Roberts, and Jellybooks Ltd.
|
276
|
+
* Copyright (c) 2010-2015 Michael Bleigh, and Intridea, Inc.
|
@@ -4,23 +4,31 @@ 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.
|
8
|
-
#
|
9
|
-
#
|
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
|
13
28
|
end
|
14
29
|
|
15
30
|
module ClassMethods
|
16
|
-
|
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
|
31
|
+
extend Gem::Deprecate
|
24
32
|
|
25
33
|
# Authenticate a user with the given key and password.
|
26
34
|
#
|
@@ -43,6 +51,53 @@ module OmniAuth
|
|
43
51
|
|
44
52
|
@auth_key || 'email'
|
45
53
|
end
|
54
|
+
|
55
|
+
# Persists a new Identity object to the ORM.
|
56
|
+
# Defaults to calling super. Override as needed per ORM.
|
57
|
+
#
|
58
|
+
# @deprecated v4.0 will begin using {#new} with {#save} instead.
|
59
|
+
# @abstract
|
60
|
+
# @param [Hash] args Attributes of the new instance.
|
61
|
+
# @return [Model] An instance of the identity model class.
|
62
|
+
# @since 3.0.5
|
63
|
+
def create(*args)
|
64
|
+
raise NotImplementedError unless defined?(super)
|
65
|
+
|
66
|
+
super
|
67
|
+
end
|
68
|
+
|
69
|
+
# Locate an identity given its unique login key.
|
70
|
+
#
|
71
|
+
# @abstract
|
72
|
+
# @param [String] key The unique login key.
|
73
|
+
# @return [Model] An instance of the identity model class.
|
74
|
+
def locate(key)
|
75
|
+
raise NotImplementedError
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Persists a new Identity object to the ORM.
|
80
|
+
# Default raises an error. Override as needed per ORM.
|
81
|
+
#
|
82
|
+
# @abstract
|
83
|
+
# @return [Model] An instance of the identity model class.
|
84
|
+
# @since 3.0.5
|
85
|
+
def save
|
86
|
+
raise NotImplementedError unless defined?(super)
|
87
|
+
|
88
|
+
super
|
89
|
+
end
|
90
|
+
|
91
|
+
# Checks if the Identity object is persisted in the ORM.
|
92
|
+
# Defaults to calling super. Override as needed per ORM.
|
93
|
+
#
|
94
|
+
# @abstract
|
95
|
+
# @return [true or false] true if object exists, false if not.
|
96
|
+
# @since 3.0.5
|
97
|
+
def persisted?
|
98
|
+
raise NotImplementedError unless defined?(super)
|
99
|
+
|
100
|
+
super
|
46
101
|
end
|
47
102
|
|
48
103
|
# Returns self if the provided password is correct, false
|
@@ -55,22 +110,6 @@ module OmniAuth
|
|
55
110
|
raise NotImplementedError
|
56
111
|
end
|
57
112
|
|
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
113
|
# An identifying string that must be globally unique to the
|
75
114
|
# application. Defaults to stringifying the `id` method.
|
76
115
|
#
|
@@ -113,6 +152,21 @@ module OmniAuth
|
|
113
152
|
raise NotImplementedError
|
114
153
|
end
|
115
154
|
end
|
155
|
+
|
156
|
+
# A hash of as much of the standard OmniAuth schema as is stored
|
157
|
+
# in this particular model. By default, this will call instance
|
158
|
+
# methods for each of the attributes it needs in turn, ignoring
|
159
|
+
# any for which `#respond_to?` is `false`.
|
160
|
+
#
|
161
|
+
# If `first_name`, `nickname`, and/or `last_name` is provided but
|
162
|
+
# `name` is not, it will be automatically calculated.
|
163
|
+
#
|
164
|
+
# @return [Hash] A string-keyed hash of user information.
|
165
|
+
def info
|
166
|
+
SCHEMA_ATTRIBUTES.each_with_object({}) do |attribute, hash|
|
167
|
+
hash[attribute] = send(attribute) if respond_to?(attribute)
|
168
|
+
end
|
169
|
+
end
|
116
170
|
end
|
117
171
|
end
|
118
172
|
end
|
@@ -6,6 +6,9 @@ module OmniAuth
|
|
6
6
|
module Identity
|
7
7
|
module Models
|
8
8
|
# http://sequel.jeremyevans.net/ an SQL ORM
|
9
|
+
# NOTE: Sequel is *not* based on ActiveModel, but supports the API we need, except for `persisted`:
|
10
|
+
# * create
|
11
|
+
# * save, but save is deprecated in favor of `save_changes`
|
9
12
|
module Sequel
|
10
13
|
def self.included(base)
|
11
14
|
base.class_eval do
|
@@ -29,6 +32,14 @@ module OmniAuth
|
|
29
32
|
def self.locate(search_hash)
|
30
33
|
where(search_hash).first
|
31
34
|
end
|
35
|
+
|
36
|
+
def persisted?
|
37
|
+
exists?
|
38
|
+
end
|
39
|
+
|
40
|
+
def save
|
41
|
+
save_changes
|
42
|
+
end
|
32
43
|
end
|
33
44
|
end
|
34
45
|
end
|
@@ -6,8 +6,8 @@ module OmniAuth
|
|
6
6
|
# user authentication using the same process flow that you
|
7
7
|
# use for external OmniAuth providers.
|
8
8
|
class Identity
|
9
|
+
DEFAULT_REGISTRATION_FIELDS = %i[password password_confirmation].freeze
|
9
10
|
include OmniAuth::Strategy
|
10
|
-
|
11
11
|
option :fields, %i[name email]
|
12
12
|
|
13
13
|
# Primary Feature Switches:
|
@@ -65,29 +65,23 @@ module OmniAuth
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def registration_phase
|
68
|
-
attributes = (options[:fields] +
|
68
|
+
attributes = (options[:fields] + DEFAULT_REGISTRATION_FIELDS).each_with_object({}) do |k, h|
|
69
69
|
h[k] = request[k.to_s]
|
70
70
|
end
|
71
71
|
if model.respond_to?(:column_names) && model.column_names.include?('provider')
|
72
72
|
attributes.reverse_merge!(provider: 'identity')
|
73
73
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
env['omniauth.identity'] = @identity
|
81
|
-
options[:on_failed_registration].call(env)
|
74
|
+
if saving_instead_of_creating?
|
75
|
+
@identity = model.new(attributes)
|
76
|
+
env['omniauth.identity'] = @identity
|
77
|
+
if !validating? || valid?
|
78
|
+
@identity.save
|
79
|
+
registration_result
|
82
80
|
else
|
83
|
-
|
84
|
-
registration_form(validation_message)
|
81
|
+
registration_failure('Validation failed')
|
85
82
|
end
|
86
|
-
elsif @identity.save && @identity.persisted?
|
87
|
-
env['PATH_INFO'] = callback_path
|
88
|
-
callback_phase
|
89
83
|
else
|
90
|
-
|
84
|
+
deprecated_registration(attributes)
|
91
85
|
end
|
92
86
|
end
|
93
87
|
|
@@ -142,15 +136,53 @@ module OmniAuth
|
|
142
136
|
end
|
143
137
|
end
|
144
138
|
|
145
|
-
def
|
139
|
+
def saving_instead_of_creating?
|
140
|
+
model.respond_to?(:save) && model.respond_to?(:persisted?)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Validates the model before it is persisted
|
144
|
+
#
|
145
|
+
# @return [truthy or falsey] :on_validation option is truthy or falsey
|
146
|
+
def validating?
|
147
|
+
options[:on_validation]
|
148
|
+
end
|
149
|
+
|
150
|
+
# Validates the model before it is persisted
|
151
|
+
#
|
152
|
+
# @return [true or false] result of :on_validation call
|
153
|
+
def valid?
|
154
|
+
# on_validation may run a Captcha or other validation mechanism
|
155
|
+
# Must return true when validation passes, false otherwise
|
156
|
+
!!options[:on_validation].call(env: env)
|
157
|
+
end
|
158
|
+
|
159
|
+
def registration_failure(message)
|
146
160
|
if options[:on_failed_registration]
|
147
|
-
env['omniauth.identity'] = @identity
|
148
161
|
options[:on_failed_registration].call(env)
|
149
162
|
else
|
150
|
-
|
151
|
-
|
163
|
+
registration_form(message)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def registration_result
|
168
|
+
if @identity.persisted?
|
169
|
+
env['PATH_INFO'] = callback_path
|
170
|
+
callback_phase
|
171
|
+
else
|
172
|
+
registration_failure('One or more fields were invalid')
|
152
173
|
end
|
153
174
|
end
|
175
|
+
|
176
|
+
def deprecated_registration(attributes)
|
177
|
+
warn <<~CREATEDEP
|
178
|
+
[DEPRECATION] Please define '#{model.class}#save'.
|
179
|
+
Behavior based on '#{model.class}.create' will be removed in omniauth-identity v4.0.
|
180
|
+
See lib/omniauth/identity/model.rb
|
181
|
+
CREATEDEP
|
182
|
+
@identity = model.create(attributes)
|
183
|
+
env['omniauth.identity'] = @identity
|
184
|
+
registration_result
|
185
|
+
end
|
154
186
|
end
|
155
187
|
end
|
156
188
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-identity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-03-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bcrypt
|
@@ -158,7 +158,7 @@ dependencies:
|
|
158
158
|
- - "~>"
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '1.4'
|
161
|
-
description:
|
161
|
+
description: Traditional username/password based authentication system for OmniAuth
|
162
162
|
email:
|
163
163
|
executables: []
|
164
164
|
extensions: []
|
@@ -211,7 +211,7 @@ requirements: []
|
|
211
211
|
rubygems_version: 3.2.3
|
212
212
|
signing_key:
|
213
213
|
specification_version: 4
|
214
|
-
summary:
|
214
|
+
summary: Traditional username/password based authentication system for OmniAuth
|
215
215
|
test_files:
|
216
216
|
- spec/omniauth/identity/model_spec.rb
|
217
217
|
- spec/omniauth/identity/models/active_record_spec.rb
|