challah 1.6.1 → 2.0.0.beta1
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 +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +5 -38
- data/VERSION +1 -1
- data/app/controllers/sessions_controller.rb +11 -10
- data/app/models/authorization.rb +2 -0
- data/lib/challah/audit.rb +38 -36
- data/lib/challah/authenticators/api_key.rb +4 -2
- data/lib/challah/authenticators/password.rb +3 -1
- data/lib/challah/authenticators.rb +5 -3
- data/lib/challah/concerns/authorizeable.rb +4 -0
- data/lib/challah/concerns/user/attributeable.rb +35 -33
- data/lib/challah/concerns/user/authenticateable.rb +2 -0
- data/lib/challah/concerns/user/authorizable.rb +16 -12
- data/lib/challah/concerns/user/findable.rb +13 -10
- data/lib/challah/concerns/user/passwordable.rb +5 -3
- data/lib/challah/concerns/user/provideable.rb +22 -20
- data/lib/challah/concerns/user/statusable.rb +3 -21
- data/lib/challah/concerns/user/validateable.rb +3 -1
- data/lib/challah/concerns/userable.rb +1 -3
- data/lib/challah/controller.rb +69 -65
- data/lib/challah/cookie_store.rb +7 -5
- data/lib/challah/encrypter.rb +4 -2
- data/lib/challah/engine.rb +5 -18
- data/lib/challah/providers/password_provider.rb +9 -7
- data/lib/challah/providers.rb +3 -1
- data/lib/challah/random.rb +6 -4
- data/lib/challah/routes.rb +6 -6
- data/lib/challah/session.rb +27 -25
- data/lib/challah/signup.rb +5 -3
- data/lib/challah/simple_cookie_store.rb +82 -80
- data/lib/challah/techniques/api_key_technique.rb +2 -2
- data/lib/challah/techniques/password_technique.rb +2 -1
- data/lib/challah/techniques/token_technique.rb +1 -1
- data/lib/challah/techniques.rb +2 -0
- data/lib/challah/test.rb +6 -0
- data/lib/challah/validators/email_validator.rb +2 -0
- data/lib/challah/validators/password_validator.rb +5 -3
- data/lib/challah/version.rb +3 -1
- data/lib/challah.rb +2 -5
- data/lib/generators/challah_generator.rb +2 -8
- data/lib/generators/templates/{migration.rb → migration.erb} +3 -6
- metadata +42 -19
- data/lib/challah/plugins.rb +0 -54
@@ -5,7 +5,7 @@ module Challah
|
|
5
5
|
attr_accessor :user_model
|
6
6
|
|
7
7
|
def initialize(session)
|
8
|
-
@key
|
8
|
+
@key = session.key? ? session.key : nil
|
9
9
|
end
|
10
10
|
|
11
11
|
def authenticate
|
@@ -16,7 +16,7 @@ module Challah
|
|
16
16
|
unless @key.to_s.blank?
|
17
17
|
user = user_model.find_by_api_key(@key)
|
18
18
|
|
19
|
-
if user
|
19
|
+
if user && user.valid_session?
|
20
20
|
return user
|
21
21
|
end
|
22
22
|
end
|
@@ -12,7 +12,7 @@ module Challah
|
|
12
12
|
|
13
13
|
# if we can successfully authenticate, return a User instance, otherwise nil
|
14
14
|
def authenticate
|
15
|
-
if username?
|
15
|
+
if username? && password?
|
16
16
|
user = user_model.find_for_session(username)
|
17
17
|
|
18
18
|
if user
|
@@ -49,5 +49,6 @@ module Challah
|
|
49
49
|
def username
|
50
50
|
@username
|
51
51
|
end
|
52
|
+
|
52
53
|
end
|
53
54
|
end
|
data/lib/challah/techniques.rb
CHANGED
@@ -54,6 +54,7 @@ module Challah
|
|
54
54
|
# +ApiKeyTechnique+.
|
55
55
|
#
|
56
56
|
module Techniques
|
57
|
+
|
57
58
|
# Register a new technique class. Pass in a name as an identifier, and the class to use
|
58
59
|
# when attempting to authenticate.
|
59
60
|
def register_technique(name, klass)
|
@@ -69,5 +70,6 @@ module Challah
|
|
69
70
|
def techniques
|
70
71
|
@techniques.dup
|
71
72
|
end
|
73
|
+
|
72
74
|
end
|
73
75
|
end
|
data/lib/challah/test.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Challah
|
2
|
+
|
2
3
|
# Used to persist session data in test mode instead of using cookies. Stores the session
|
3
4
|
# data lazily in a global var, accessible across the testing environment.
|
4
5
|
class TestSessionStore
|
6
|
+
|
5
7
|
def initialize(session = nil)
|
6
8
|
@session = session
|
7
9
|
end
|
@@ -22,6 +24,7 @@ module Challah
|
|
22
24
|
$challah_test_session = "#{ token }@#{ user_id }"
|
23
25
|
true
|
24
26
|
end
|
27
|
+
|
25
28
|
end
|
26
29
|
|
27
30
|
module Testing
|
@@ -39,17 +42,20 @@ module Challah
|
|
39
42
|
alias_method :logout, :signout
|
40
43
|
|
41
44
|
end
|
45
|
+
|
42
46
|
end
|
43
47
|
|
44
48
|
if defined?(ActionController::TestCase)
|
45
49
|
Challah.options[:storage_class] = Challah::TestSessionStore
|
46
50
|
|
47
51
|
class ActionController::TestCase
|
52
|
+
|
48
53
|
include Challah::Testing
|
49
54
|
|
50
55
|
setup do
|
51
56
|
$challah_test_session = nil
|
52
57
|
end
|
58
|
+
|
53
59
|
end
|
54
60
|
end
|
55
61
|
|
@@ -6,6 +6,7 @@ module Challah
|
|
6
6
|
# validates :email, :presence => true, :email => true
|
7
7
|
# end
|
8
8
|
class EmailValidator < ActiveModel::EachValidator
|
9
|
+
|
9
10
|
# Called automatically by ActiveModel validation..
|
10
11
|
def validate_each(record, attribute, value)
|
11
12
|
unless value =~ EmailValidator.pattern
|
@@ -17,5 +18,6 @@ module Challah
|
|
17
18
|
def self.pattern
|
18
19
|
/\b[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,}\z/
|
19
20
|
end
|
21
|
+
|
20
22
|
end
|
21
23
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Challah
|
2
2
|
class PasswordValidator < ActiveModel::Validator
|
3
|
+
|
3
4
|
# Check to make sure a valid password and confirmation were set
|
4
5
|
def validate(record)
|
5
|
-
if record.password_provider?
|
6
|
-
if record.new_record?
|
6
|
+
if record.password_provider? || options[:force]
|
7
|
+
if record.new_record? && record.password.to_s.blank? && !record.password_changed?
|
7
8
|
record.errors.add :password, :blank
|
8
9
|
elsif record.password_changed?
|
9
10
|
if record.password.to_s.size < 4
|
@@ -14,5 +15,6 @@ module Challah
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
18
|
+
|
17
19
|
end
|
18
|
-
end
|
20
|
+
end
|
data/lib/challah/version.rb
CHANGED
data/lib/challah.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "challah/version"
|
2
2
|
|
3
3
|
module Challah
|
4
|
+
|
4
5
|
autoload :Audit, "challah/audit"
|
5
6
|
|
6
7
|
autoload :CookieStore, "challah/cookie_store"
|
@@ -9,7 +10,6 @@ module Challah
|
|
9
10
|
autoload :Authenticators, "challah/authenticators"
|
10
11
|
autoload :Controller, "challah/controller"
|
11
12
|
autoload :Encrypter, "challah/encrypter"
|
12
|
-
autoload :Plugins, "challah/plugins"
|
13
13
|
autoload :Providers, "challah/providers"
|
14
14
|
autoload :Random, "challah/random"
|
15
15
|
autoload :Session, "challah/session"
|
@@ -74,10 +74,6 @@ module Challah
|
|
74
74
|
register_technique :password, PasswordTechnique
|
75
75
|
register_technique :token, TokenTechnique
|
76
76
|
|
77
|
-
# Set up plugin registering capability
|
78
|
-
extend Plugins
|
79
|
-
@plugins ||= {}
|
80
|
-
|
81
77
|
# Set up authenticators
|
82
78
|
extend Authenticators
|
83
79
|
@authenticators ||= {}
|
@@ -91,6 +87,7 @@ module Challah
|
|
91
87
|
@providers ||= {}
|
92
88
|
|
93
89
|
register_provider :password, PasswordProvider
|
90
|
+
|
94
91
|
end
|
95
92
|
|
96
93
|
require "challah/engine" if defined?(Rails)
|
@@ -7,17 +7,11 @@ class ChallahGenerator < Rails::Generators::Base
|
|
7
7
|
source_root File.expand_path("../templates", __FILE__)
|
8
8
|
|
9
9
|
def copy_migration
|
10
|
-
migration_template "migration.
|
11
|
-
end
|
12
|
-
|
13
|
-
def rails5?
|
14
|
-
Rails.version.start_with? "5"
|
10
|
+
migration_template "migration.erb", "db/migrate/challah_create_users.rb", migration_version: migration_version
|
15
11
|
end
|
16
12
|
|
17
13
|
def migration_version
|
18
|
-
|
19
|
-
"[#{ Rails::VERSION::MAJOR }.#{ Rails::VERSION::MINOR }]"
|
20
|
-
end
|
14
|
+
"[#{ Rails::VERSION::MAJOR }.#{ Rails::VERSION::MINOR }]"
|
21
15
|
end
|
22
16
|
|
23
17
|
end
|
@@ -10,10 +10,8 @@ class ChallahCreateUsers < ActiveRecord::Migration<%= migration_version %>
|
|
10
10
|
t.datetime :last_session_at
|
11
11
|
t.integer :session_count, default: 0
|
12
12
|
t.integer :failed_auth_count, default: 0
|
13
|
-
t.
|
14
|
-
t.
|
15
|
-
t.datetime :created_at
|
16
|
-
t.datetime :updated_at
|
13
|
+
t.bigint :created_by, default: 0
|
14
|
+
t.bigint :updated_by, default: 0
|
17
15
|
t.integer :status, default: 0 # defaults to :active
|
18
16
|
t.timestamps null: true
|
19
17
|
end
|
@@ -24,7 +22,7 @@ class ChallahCreateUsers < ActiveRecord::Migration<%= migration_version %>
|
|
24
22
|
add_index :users, :api_key
|
25
23
|
|
26
24
|
create_table :authorizations do |t|
|
27
|
-
t.
|
25
|
+
t.references :user
|
28
26
|
t.string :provider, limit: 50
|
29
27
|
t.string :uid
|
30
28
|
t.string :token, limit: 500
|
@@ -34,7 +32,6 @@ class ChallahCreateUsers < ActiveRecord::Migration<%= migration_version %>
|
|
34
32
|
t.timestamps null: true
|
35
33
|
end
|
36
34
|
|
37
|
-
add_index :authorizations, :user_id
|
38
35
|
add_index :authorizations, [ :user_id, :provider ]
|
39
36
|
add_index :authorizations, :uid
|
40
37
|
add_index :authorizations, :token
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: challah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Tornow
|
@@ -10,42 +10,48 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-02-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: highline
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "~>"
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '1.7'
|
22
19
|
- - ">="
|
23
20
|
- !ruby/object:Gem::Version
|
24
21
|
version: 1.7.1
|
22
|
+
- - "<"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '3'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
28
|
requirements:
|
29
|
-
- - "~>"
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version: '1.7'
|
32
29
|
- - ">="
|
33
30
|
- !ruby/object:Gem::Version
|
34
31
|
version: 1.7.1
|
32
|
+
- - "<"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3'
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: rails
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 5.2.0
|
42
|
+
- - "<"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '7'
|
42
45
|
type: :runtime
|
43
46
|
prerelease: false
|
44
47
|
version_requirements: !ruby/object:Gem::Requirement
|
45
48
|
requirements:
|
46
49
|
- - ">="
|
47
50
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
51
|
+
version: 5.2.0
|
52
|
+
- - "<"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '7'
|
49
55
|
- !ruby/object:Gem::Dependency
|
50
56
|
name: rake
|
51
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,14 +100,14 @@ dependencies:
|
|
94
100
|
requirements:
|
95
101
|
- - "~>"
|
96
102
|
- !ruby/object:Gem::Version
|
97
|
-
version: '
|
103
|
+
version: '5.1'
|
98
104
|
type: :development
|
99
105
|
prerelease: false
|
100
106
|
version_requirements: !ruby/object:Gem::Requirement
|
101
107
|
requirements:
|
102
108
|
- - "~>"
|
103
109
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
110
|
+
version: '5.1'
|
105
111
|
- !ruby/object:Gem::Dependency
|
106
112
|
name: sqlite3
|
107
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,7 +136,21 @@ dependencies:
|
|
130
136
|
- - "~>"
|
131
137
|
- !ruby/object:Gem::Version
|
132
138
|
version: '0.2'
|
133
|
-
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: appraisal
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Authorization and session management for Rails apps
|
134
154
|
email:
|
135
155
|
- john@johntornow.com
|
136
156
|
- p@rdln.net
|
@@ -167,7 +187,6 @@ files:
|
|
167
187
|
- lib/challah/cookie_store.rb
|
168
188
|
- lib/challah/encrypter.rb
|
169
189
|
- lib/challah/engine.rb
|
170
|
-
- lib/challah/plugins.rb
|
171
190
|
- lib/challah/providers.rb
|
172
191
|
- lib/challah/providers/password_provider.rb
|
173
192
|
- lib/challah/random.rb
|
@@ -184,14 +203,19 @@ files:
|
|
184
203
|
- lib/challah/validators/password_validator.rb
|
185
204
|
- lib/challah/version.rb
|
186
205
|
- lib/generators/challah_generator.rb
|
187
|
-
- lib/generators/templates/migration.
|
206
|
+
- lib/generators/templates/migration.erb
|
188
207
|
- lib/tasks/crud.rake
|
189
208
|
- lib/tasks/setup.rake
|
190
209
|
- lib/tasks/unpack.rake
|
191
210
|
homepage: https://github.com/jdtornow/challah
|
192
211
|
licenses:
|
193
212
|
- MIT
|
194
|
-
metadata:
|
213
|
+
metadata:
|
214
|
+
bug_tracker_uri: https://github.com/jdtornow/challah/issues
|
215
|
+
changelog_uri: https://github.com/jdtornow/challah/releases
|
216
|
+
homepage_uri: https://github.com/jdtornow/challah
|
217
|
+
source_code_uri: https://github.com/jdtornow/challah
|
218
|
+
wiki_uri: https://github.com/jdtornow/challah/wiki
|
195
219
|
post_install_message:
|
196
220
|
rdoc_options: []
|
197
221
|
require_paths:
|
@@ -200,15 +224,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
224
|
requirements:
|
201
225
|
- - ">="
|
202
226
|
- !ruby/object:Gem::Version
|
203
|
-
version: 2.
|
227
|
+
version: 2.5.0
|
204
228
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
229
|
requirements:
|
206
230
|
- - ">="
|
207
231
|
- !ruby/object:Gem::Version
|
208
232
|
version: 1.8.11
|
209
233
|
requirements: []
|
210
|
-
|
211
|
-
rubygems_version: 2.7.6
|
234
|
+
rubygems_version: 3.1.2
|
212
235
|
signing_key:
|
213
236
|
specification_version: 4
|
214
237
|
summary: Rails authentication and sessions
|
data/lib/challah/plugins.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module Challah
|
2
|
-
# Plugins are used to extend the functionality of Challah.
|
3
|
-
module Plugins
|
4
|
-
# A simple DSL for registering a plugin
|
5
|
-
class Plugin
|
6
|
-
attr_reader :active_record, :action_controller, :user_extensions, :user_init_methods
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@active_record ||= []
|
10
|
-
@action_controller ||= []
|
11
|
-
@user_extensions ||= []
|
12
|
-
@user_init_methods ||= []
|
13
|
-
end
|
14
|
-
|
15
|
-
# When active_record or action_controller is loaded, run the given block
|
16
|
-
def on_load(framework, &block)
|
17
|
-
return unless [ :active_record, :action_controller ].include?(framework)
|
18
|
-
instance_variable_get("@#{framework}") << block
|
19
|
-
end
|
20
|
-
|
21
|
-
# Pass a module name to include it in the base User model after challah_user
|
22
|
-
# is run
|
23
|
-
def extend_user(module_name, init_method = nil)
|
24
|
-
@user_extensions << module_name
|
25
|
-
@user_init_methods << init_method unless init_method.nil?
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Register a new plugin.
|
30
|
-
def register_plugin(name, &block)
|
31
|
-
plugin = Plugin.new
|
32
|
-
plugin.instance_eval(&block)
|
33
|
-
@plugins[name] = plugin
|
34
|
-
end
|
35
|
-
|
36
|
-
# Get the list of all plugins
|
37
|
-
def plugins
|
38
|
-
@plugins
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Loop through all registered plugins and extend User functionality.
|
43
|
-
def self.include_user_plugins!
|
44
|
-
Challah.plugins.values.each do |plugin|
|
45
|
-
plugin.user_extensions.each do |mod|
|
46
|
-
Challah.user.send(:extend, mod)
|
47
|
-
end
|
48
|
-
|
49
|
-
plugin.user_init_methods.each do |method_name|
|
50
|
-
Challah.user.send(method_name)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|