rails_simple_auth 1.0.0 → 1.0.2
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/README.md +144 -2
- data/app/assets/stylesheets/rails_simple_auth/application.css +234 -0
- data/app/controllers/rails_simple_auth/confirmations_controller.rb +19 -17
- data/app/controllers/rails_simple_auth/omniauth_callbacks_controller.rb +6 -4
- data/app/controllers/rails_simple_auth/passwords_controller.rb +13 -12
- data/app/controllers/rails_simple_auth/registrations_controller.rb +6 -4
- data/app/controllers/rails_simple_auth/sessions_controller.rb +21 -16
- data/app/mailers/rails_simple_auth/auth_mailer.rb +10 -7
- data/app/views/layouts/rails_simple_auth.html.erb +37 -0
- data/app/views/rails_simple_auth/confirmations/new.html.erb +2 -2
- data/app/views/rails_simple_auth/passwords/new.html.erb +2 -2
- data/app/views/rails_simple_auth/registrations/new.html.erb +5 -5
- data/app/views/rails_simple_auth/sessions/magic_link_form.html.erb +2 -2
- data/app/views/rails_simple_auth/sessions/new.html.erb +2 -2
- data/lib/generators/rails_simple_auth/css/css_generator.rb +20 -20
- data/lib/generators/rails_simple_auth/install/install_generator.rb +32 -32
- data/lib/generators/rails_simple_auth/install/templates/initializer.rb +3 -3
- data/lib/generators/rails_simple_auth/install/templates/migration.rb +2 -2
- data/lib/generators/rails_simple_auth/temporary_users/USAGE +21 -0
- data/lib/generators/rails_simple_auth/temporary_users/templates/add_temporary_to_users.rb.erb +8 -0
- data/lib/generators/rails_simple_auth/temporary_users/temporary_users_generator.rb +40 -0
- data/lib/generators/rails_simple_auth/views/views_generator.rb +8 -8
- data/lib/rails_simple_auth/configuration.rb +23 -8
- data/lib/rails_simple_auth/controllers/concerns/authentication.rb +17 -18
- data/lib/rails_simple_auth/controllers/concerns/session_management.rb +24 -0
- data/lib/rails_simple_auth/engine.rb +1 -1
- data/lib/rails_simple_auth/models/concerns/authenticatable.rb +13 -5
- data/lib/rails_simple_auth/models/concerns/confirmable.rb +38 -3
- data/lib/rails_simple_auth/models/concerns/oauth_connectable.rb +5 -5
- data/lib/rails_simple_auth/models/concerns/temporary_user.rb +105 -0
- data/lib/rails_simple_auth/models/session.rb +2 -4
- data/lib/rails_simple_auth/routes.rb +15 -15
- data/lib/rails_simple_auth/version.rb +1 -1
- data/lib/rails_simple_auth.rb +14 -12
- metadata +19 -16
|
@@ -17,9 +17,9 @@ module RailsSimpleAuth
|
|
|
17
17
|
return unless (session_token = cookies.signed.permanent[:session_token])
|
|
18
18
|
|
|
19
19
|
session_record = RailsSimpleAuth.configuration.session_class
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
.includes(:user)
|
|
21
|
+
.active
|
|
22
|
+
.find_by(id: session_token)
|
|
23
23
|
|
|
24
24
|
if session_record
|
|
25
25
|
RailsSimpleAuth::Current.user = session_record.user
|
|
@@ -51,8 +51,8 @@ module RailsSimpleAuth
|
|
|
51
51
|
|
|
52
52
|
# SECURITY: Validate path to prevent open redirect attacks
|
|
53
53
|
# Only store relative paths that start with / but not //
|
|
54
|
-
return unless path.start_with?(
|
|
55
|
-
return if path.start_with?(
|
|
54
|
+
return unless path.start_with?('/')
|
|
55
|
+
return if path.start_with?('//')
|
|
56
56
|
|
|
57
57
|
session[:return_to] = path
|
|
58
58
|
end
|
|
@@ -63,34 +63,33 @@ module RailsSimpleAuth
|
|
|
63
63
|
|
|
64
64
|
def redirect_to_sign_in
|
|
65
65
|
respond_to do |format|
|
|
66
|
-
format.html { redirect_to new_session_path, alert:
|
|
67
|
-
format.json { render json: { error:
|
|
68
|
-
format.turbo_stream { redirect_to new_session_path, alert:
|
|
66
|
+
format.html { redirect_to new_session_path, alert: 'Please sign in to continue.' }
|
|
67
|
+
format.json { render json: { error: 'Authentication required' }, status: :unauthorized }
|
|
68
|
+
format.turbo_stream { redirect_to new_session_path, alert: 'Please sign in to continue.' }
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def client_ip
|
|
73
|
-
request.headers[
|
|
74
|
-
request.headers[
|
|
73
|
+
request.headers['CF-Connecting-IP'] ||
|
|
74
|
+
request.headers['X-Forwarded-For']&.split(',')&.first&.strip ||
|
|
75
75
|
request.remote_ip
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
def resolve_path(config_key)
|
|
79
79
|
path_config = RailsSimpleAuth.configuration.public_send(config_key)
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
case path_config
|
|
82
82
|
when Symbol then send(path_config)
|
|
83
83
|
when Proc then path_config.call(self)
|
|
84
84
|
when String then path_config
|
|
85
85
|
else
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
Rails.logger.warn(
|
|
87
|
+
"[RailsSimpleAuth] Invalid path configuration for #{config_key}: " \
|
|
88
|
+
"expected Symbol, Proc, or String, got #{path_config.class.name}. " \
|
|
89
|
+
'Falling back to root_path.'
|
|
90
|
+
)
|
|
91
|
+
root_path
|
|
92
92
|
end
|
|
93
|
-
result
|
|
94
93
|
rescue NoMethodError => e
|
|
95
94
|
Rails.logger.error(
|
|
96
95
|
"[RailsSimpleAuth] Path helper '#{path_config}' not found for #{config_key}. " \
|
|
@@ -39,6 +39,30 @@ module RailsSimpleAuth
|
|
|
39
39
|
RailsSimpleAuth::Current.session = nil
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
# Destroy temporary user session when signing in with a different account
|
|
43
|
+
# This cleans up guest/demo users when they sign in or register
|
|
44
|
+
# @param signing_in_user [User, nil] The user being signed in (to avoid self-destruction)
|
|
45
|
+
def destroy_temporary_user_session(signing_in_user = nil)
|
|
46
|
+
return unless RailsSimpleAuth.configuration.temporary_users_enabled
|
|
47
|
+
return unless RailsSimpleAuth::Current.user&.temporary?
|
|
48
|
+
|
|
49
|
+
temp_user = RailsSimpleAuth::Current.user
|
|
50
|
+
|
|
51
|
+
# Don't destroy if the user is re-authenticating as themselves
|
|
52
|
+
return if signing_in_user && temp_user.id == signing_in_user.id
|
|
53
|
+
|
|
54
|
+
temp_user_id = temp_user.id
|
|
55
|
+
|
|
56
|
+
temp_user.transaction do
|
|
57
|
+
destroy_current_session
|
|
58
|
+
temp_user.destroy!
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
Rails.logger.info("[RailsSimpleAuth] Destroyed temporary user #{temp_user_id} on sign in")
|
|
62
|
+
rescue ActiveRecord::RecordNotDestroyed => e
|
|
63
|
+
Rails.logger.error("[RailsSimpleAuth] Failed to destroy temporary user #{temp_user_id}: #{e.message}")
|
|
64
|
+
end
|
|
65
|
+
|
|
42
66
|
# Run after sign in callback if configured
|
|
43
67
|
def run_after_sign_in_callback(user)
|
|
44
68
|
run_callback(:after_sign_in_callback, user)
|
|
@@ -8,7 +8,7 @@ module RailsSimpleAuth
|
|
|
8
8
|
g.test_framework :minitest
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
initializer
|
|
11
|
+
initializer 'rails_simple_auth.helpers' do
|
|
12
12
|
ActiveSupport.on_load(:action_controller_base) do
|
|
13
13
|
include RailsSimpleAuth::Controllers::Concerns::Authentication
|
|
14
14
|
include RailsSimpleAuth::Controllers::Concerns::SessionManagement
|
|
@@ -10,25 +10,26 @@ module RailsSimpleAuth
|
|
|
10
10
|
has_secure_password
|
|
11
11
|
|
|
12
12
|
has_many :sessions,
|
|
13
|
-
class_name:
|
|
13
|
+
class_name: RailsSimpleAuth.configuration.session_class_name,
|
|
14
14
|
dependent: :destroy,
|
|
15
15
|
inverse_of: :user
|
|
16
16
|
|
|
17
|
-
validates :
|
|
17
|
+
validates :email,
|
|
18
18
|
presence: true,
|
|
19
19
|
uniqueness: { case_sensitive: false },
|
|
20
|
-
format: { with: URI::MailTo::EMAIL_REGEXP }
|
|
20
|
+
format: { with: URI::MailTo::EMAIL_REGEXP },
|
|
21
|
+
unless: :temporary?
|
|
21
22
|
|
|
22
23
|
validate :password_meets_minimum_length, if: :password_required?
|
|
23
24
|
|
|
24
|
-
normalizes :
|
|
25
|
+
normalizes :email, with: ->(email) { email.strip.downcase }
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
class_methods do
|
|
28
29
|
def find_by_email(email)
|
|
29
30
|
return nil if email.blank?
|
|
30
31
|
|
|
31
|
-
find_by(
|
|
32
|
+
find_by(email: email.to_s.strip.downcase)
|
|
32
33
|
end
|
|
33
34
|
end
|
|
34
35
|
|
|
@@ -47,9 +48,16 @@ module RailsSimpleAuth
|
|
|
47
48
|
count
|
|
48
49
|
end
|
|
49
50
|
|
|
51
|
+
# Returns false by default. Override in TemporaryUser concern.
|
|
52
|
+
def temporary?
|
|
53
|
+
false
|
|
54
|
+
end
|
|
55
|
+
|
|
50
56
|
private
|
|
51
57
|
|
|
52
58
|
def password_required?
|
|
59
|
+
return false if temporary?
|
|
60
|
+
|
|
53
61
|
password_digest.blank? || password.present?
|
|
54
62
|
end
|
|
55
63
|
|
|
@@ -8,6 +8,7 @@ module RailsSimpleAuth
|
|
|
8
8
|
|
|
9
9
|
included do
|
|
10
10
|
# Requires `confirmed_at` datetime column
|
|
11
|
+
# Optional `unconfirmed_email` string column for reconfirmation
|
|
11
12
|
scope :confirmed, -> { where.not(confirmed_at: nil) }
|
|
12
13
|
scope :unconfirmed, -> { where(confirmed_at: nil) }
|
|
13
14
|
end
|
|
@@ -22,17 +23,51 @@ module RailsSimpleAuth
|
|
|
22
23
|
!confirmed?
|
|
23
24
|
end
|
|
24
25
|
|
|
26
|
+
# Check if user is changing their email (reconfirmation)
|
|
27
|
+
def reconfirming?
|
|
28
|
+
respond_to?(:unconfirmed_email) && unconfirmed_email.present?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Check if user needs confirmation (either unconfirmed or reconfirming)
|
|
32
|
+
def unconfirmed_or_reconfirming?
|
|
33
|
+
unconfirmed? || reconfirming?
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Get the email that needs confirmation
|
|
37
|
+
def confirmable_email
|
|
38
|
+
reconfirming? ? unconfirmed_email : email
|
|
39
|
+
end
|
|
40
|
+
|
|
25
41
|
# Confirm the user's email
|
|
42
|
+
# Handles both initial confirmation and reconfirmation (email change)
|
|
43
|
+
# Also sets temporary: false if TemporaryUser concern is included
|
|
44
|
+
# Returns true on success, false on failure (with errors populated)
|
|
26
45
|
def confirm!
|
|
27
|
-
|
|
46
|
+
attrs = { confirmed_at: Time.current }
|
|
47
|
+
attrs[:temporary] = false if respond_to?(:temporary?)
|
|
28
48
|
|
|
29
|
-
|
|
49
|
+
if reconfirming?
|
|
50
|
+
# Email change confirmation - check email uniqueness first
|
|
51
|
+
if self.class.where.not(id: id).exists?(email: unconfirmed_email)
|
|
52
|
+
errors.add(:email, 'is already taken by another user')
|
|
53
|
+
return false
|
|
54
|
+
end
|
|
55
|
+
attrs[:email] = unconfirmed_email
|
|
56
|
+
attrs[:unconfirmed_email] = nil
|
|
57
|
+
update(attrs)
|
|
58
|
+
elsif unconfirmed?
|
|
59
|
+
# Initial confirmation
|
|
60
|
+
update(attrs)
|
|
61
|
+
else
|
|
62
|
+
# Already confirmed and not reconfirming
|
|
63
|
+
true
|
|
64
|
+
end
|
|
30
65
|
end
|
|
31
66
|
|
|
32
67
|
# Generate email confirmation token using Rails signed_id
|
|
33
68
|
def generate_confirmation_token
|
|
34
69
|
signed_id(
|
|
35
|
-
purpose: :
|
|
70
|
+
purpose: :confirm_email,
|
|
36
71
|
expires_in: RailsSimpleAuth.configuration.confirmation_expiry
|
|
37
72
|
)
|
|
38
73
|
end
|
|
@@ -18,13 +18,13 @@ module RailsSimpleAuth
|
|
|
18
18
|
# - true (default): Links OAuth to existing email accounts (safe for providers that verify emails)
|
|
19
19
|
# - false: Only allows OAuth for accounts created via OAuth with same provider+uid
|
|
20
20
|
def from_oauth(auth_hash)
|
|
21
|
-
email = auth_hash.dig(
|
|
22
|
-
provider = auth_hash[
|
|
23
|
-
uid = auth_hash[
|
|
21
|
+
email = auth_hash.dig('info', 'email')
|
|
22
|
+
provider = auth_hash['provider']
|
|
23
|
+
uid = auth_hash['uid']
|
|
24
24
|
|
|
25
25
|
if email.blank?
|
|
26
26
|
Rails.logger.warn(
|
|
27
|
-
|
|
27
|
+
'[RailsSimpleAuth] OAuth auth_hash missing email. ' \
|
|
28
28
|
"Provider: #{provider}, UID: #{uid}. Ensure email scope is requested."
|
|
29
29
|
)
|
|
30
30
|
return nil
|
|
@@ -62,7 +62,7 @@ module RailsSimpleAuth
|
|
|
62
62
|
|
|
63
63
|
# Create new user for new OAuth signups
|
|
64
64
|
user = new(
|
|
65
|
-
|
|
65
|
+
email: email,
|
|
66
66
|
password: SecureRandom.hex(32) # Random password for OAuth users
|
|
67
67
|
)
|
|
68
68
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsSimpleAuth
|
|
4
|
+
module Models
|
|
5
|
+
module Concerns
|
|
6
|
+
module TemporaryUser
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
scope :temporary, -> { where(temporary: true) }
|
|
11
|
+
scope :permanent, -> { where(temporary: false) }
|
|
12
|
+
scope :temporary_expired, lambda { |days = nil|
|
|
13
|
+
cleanup_days = days || RailsSimpleAuth.configuration.temporary_user_cleanup_days
|
|
14
|
+
raise ConfigurationError, 'temporary_user_cleanup_days must be configured' unless cleanup_days&.positive?
|
|
15
|
+
|
|
16
|
+
temporary.where(created_at: ...cleanup_days.days.ago)
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def temporary?
|
|
21
|
+
temporary == true
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def permanent?
|
|
25
|
+
!temporary?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Convert a temporary user to a permanent user with email and password
|
|
29
|
+
# Returns self on success, false on failure (with errors populated)
|
|
30
|
+
def convert_to_permanent!(email:, password:)
|
|
31
|
+
# Validate email uniqueness upfront (better UX than failing inside transaction)
|
|
32
|
+
if self.class.where.not(id: id).exists?(email: email)
|
|
33
|
+
errors.add(:email, 'has already been taken')
|
|
34
|
+
return false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
transaction do
|
|
38
|
+
# Reload to discard any unpersisted changes from callbacks before locking
|
|
39
|
+
reload
|
|
40
|
+
lock!
|
|
41
|
+
|
|
42
|
+
unless temporary?
|
|
43
|
+
errors.add(:base, 'User is already permanent')
|
|
44
|
+
raise ActiveRecord::Rollback
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
attrs = {
|
|
48
|
+
email: email,
|
|
49
|
+
password: password,
|
|
50
|
+
temporary: false
|
|
51
|
+
}
|
|
52
|
+
# Reset confirmation so new email requires verification
|
|
53
|
+
attrs[:confirmed_at] = nil if respond_to?(:confirmed_at)
|
|
54
|
+
|
|
55
|
+
raise ActiveRecord::Rollback unless update(attrs)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Check if transaction was rolled back
|
|
59
|
+
return false if errors.any? || temporary?
|
|
60
|
+
|
|
61
|
+
invalidate_all_sessions!
|
|
62
|
+
send_conversion_confirmation_email
|
|
63
|
+
Rails.logger.info("[RailsSimpleAuth] Converted temporary user #{id} to permanent")
|
|
64
|
+
self
|
|
65
|
+
rescue ActiveRecord::RecordNotUnique
|
|
66
|
+
errors.add(:email, 'has already been taken')
|
|
67
|
+
false
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class_methods do
|
|
71
|
+
# Cleanup expired temporary users in batches
|
|
72
|
+
# @param days [Integer, nil] Override for cleanup_days config
|
|
73
|
+
# @param batch_size [Integer] Number of users to process per batch
|
|
74
|
+
# @return [Integer] Number of users destroyed
|
|
75
|
+
def cleanup_expired_temporary!(days: nil, batch_size: 100)
|
|
76
|
+
count = 0
|
|
77
|
+
temporary_expired(days).find_each(batch_size: batch_size) do |user|
|
|
78
|
+
user.destroy
|
|
79
|
+
count += 1
|
|
80
|
+
end
|
|
81
|
+
Rails.logger.info("[RailsSimpleAuth] Cleaned up #{count} expired temporary users")
|
|
82
|
+
count
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
def send_conversion_confirmation_email
|
|
89
|
+
return unless RailsSimpleAuth.configuration.email_confirmation_enabled
|
|
90
|
+
return unless respond_to?(:generate_confirmation_token)
|
|
91
|
+
|
|
92
|
+
token = generate_confirmation_token
|
|
93
|
+
RailsSimpleAuth.configuration.mailer.confirmation(self, token).deliver_later
|
|
94
|
+
|
|
95
|
+
Rails.logger.info("[RailsSimpleAuth] Queued confirmation email for converted user #{id}")
|
|
96
|
+
rescue ArgumentError, NoMethodError, RailsSimpleAuth::ConfigurationError => e
|
|
97
|
+
# Configuration or method errors - log but don't fail conversion
|
|
98
|
+
Rails.logger.error(
|
|
99
|
+
"[RailsSimpleAuth] Failed to send confirmation email for user #{id}: #{e.class}: #{e.message}"
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module RailsSimpleAuth
|
|
4
|
-
class Session <
|
|
5
|
-
self.table_name =
|
|
4
|
+
class Session < ::ApplicationRecord
|
|
5
|
+
self.table_name = 'sessions'
|
|
6
6
|
|
|
7
7
|
# Use lambda to defer class resolution until runtime
|
|
8
8
|
belongs_to :user, class_name: -> { RailsSimpleAuth.configuration.user_class_name }
|
|
9
9
|
|
|
10
|
-
validates :user_id, presence: true
|
|
11
|
-
|
|
12
10
|
scope :recent, -> { order(created_at: :desc) }
|
|
13
11
|
scope :active, -> { where(created_at: RailsSimpleAuth.configuration.session_expiry.ago..) }
|
|
14
12
|
scope :expired, -> { where(created_at: ...RailsSimpleAuth.configuration.session_expiry.ago) }
|
|
@@ -4,11 +4,11 @@ module RailsSimpleAuth
|
|
|
4
4
|
module Routes
|
|
5
5
|
def rails_simple_auth_routes(options = {})
|
|
6
6
|
controllers = {
|
|
7
|
-
sessions: options.fetch(:sessions_controller,
|
|
8
|
-
registrations: options.fetch(:registrations_controller,
|
|
9
|
-
passwords: options.fetch(:passwords_controller,
|
|
10
|
-
confirmations: options.fetch(:confirmations_controller,
|
|
11
|
-
omniauth: options.fetch(:omniauth_controller,
|
|
7
|
+
sessions: options.fetch(:sessions_controller, 'rails_simple_auth/sessions'),
|
|
8
|
+
registrations: options.fetch(:registrations_controller, 'rails_simple_auth/registrations'),
|
|
9
|
+
passwords: options.fetch(:passwords_controller, 'rails_simple_auth/passwords'),
|
|
10
|
+
confirmations: options.fetch(:confirmations_controller, 'rails_simple_auth/confirmations'),
|
|
11
|
+
omniauth: options.fetch(:omniauth_controller, 'rails_simple_auth/omniauth_callbacks')
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
config = RailsSimpleAuth.configuration
|
|
@@ -16,29 +16,29 @@ module RailsSimpleAuth
|
|
|
16
16
|
# Core authentication routes (always registered)
|
|
17
17
|
resource :session, only: %i[new create destroy], controller: controllers[:sessions]
|
|
18
18
|
|
|
19
|
-
get
|
|
20
|
-
post
|
|
19
|
+
get 'sign_up', to: "#{controllers[:registrations]}#new", as: :sign_up
|
|
20
|
+
post 'sign_up', to: "#{controllers[:registrations]}#create"
|
|
21
21
|
|
|
22
22
|
resources :passwords, param: :token, only: %i[new create edit update], controller: controllers[:passwords]
|
|
23
23
|
|
|
24
24
|
# Email confirmation routes (only when enabled)
|
|
25
25
|
if config.email_confirmation_enabled
|
|
26
26
|
resources :confirmations, only: %i[new create], controller: controllers[:confirmations]
|
|
27
|
-
get
|
|
27
|
+
get 'confirmations/:token', to: "#{controllers[:confirmations]}#show", as: :confirmation
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
# Magic link routes (only when enabled)
|
|
31
31
|
if config.magic_link_enabled
|
|
32
|
-
get
|
|
33
|
-
post
|
|
34
|
-
get
|
|
32
|
+
get 'magic_link_form', to: "#{controllers[:sessions]}#magic_link_form", as: :magic_link_form
|
|
33
|
+
post 'request_magic_link', to: "#{controllers[:sessions]}#request_magic_link", as: :request_magic_link
|
|
34
|
+
get 'magic_link', to: "#{controllers[:sessions]}#magic_link_login", as: :magic_link
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
# OAuth routes (only when enabled)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
return unless config.oauth_enabled
|
|
39
|
+
|
|
40
|
+
get '/auth/:provider/callback', to: "#{controllers[:omniauth]}#create", as: :omniauth_callback
|
|
41
|
+
get '/auth/failure', to: "#{controllers[:omniauth]}#failure", as: :omniauth_failure
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
end
|
data/lib/rails_simple_auth.rb
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require 'rails_simple_auth/version'
|
|
4
|
+
require 'rails_simple_auth/configuration'
|
|
5
|
+
require 'rails_simple_auth/engine'
|
|
6
6
|
|
|
7
7
|
# Model concerns
|
|
8
|
-
require
|
|
9
|
-
require
|
|
10
|
-
require
|
|
11
|
-
require
|
|
12
|
-
require
|
|
13
|
-
require
|
|
8
|
+
require 'rails_simple_auth/models/concerns/authenticatable'
|
|
9
|
+
require 'rails_simple_auth/models/concerns/confirmable'
|
|
10
|
+
require 'rails_simple_auth/models/concerns/magic_linkable'
|
|
11
|
+
require 'rails_simple_auth/models/concerns/oauth_connectable'
|
|
12
|
+
require 'rails_simple_auth/models/concerns/temporary_user'
|
|
13
|
+
require 'rails_simple_auth/models/current'
|
|
14
|
+
# Session is NOT required here - it depends on ApplicationRecord which isn't available at gem load time
|
|
15
|
+
# It will be autoloaded by the engine when Rails is ready
|
|
14
16
|
|
|
15
17
|
# Controller concerns
|
|
16
|
-
require
|
|
17
|
-
require
|
|
18
|
+
require 'rails_simple_auth/controllers/concerns/authentication'
|
|
19
|
+
require 'rails_simple_auth/controllers/concerns/session_management'
|
|
18
20
|
|
|
19
21
|
# Routes
|
|
20
|
-
require
|
|
22
|
+
require 'rails_simple_auth/routes'
|
|
21
23
|
|
|
22
24
|
module RailsSimpleAuth
|
|
23
25
|
class Error < StandardError; end
|
metadata
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_simple_auth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ivan Kuznetsov
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
13
|
+
name: bcrypt
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
16
|
+
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
18
|
+
version: '3.1'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
|
-
- - "
|
|
23
|
+
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
25
|
+
version: '3.1'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
27
|
+
name: rails
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
|
-
- - "
|
|
30
|
+
- - ">="
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
32
|
+
version: '8.0'
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
|
-
- - "
|
|
37
|
+
- - ">="
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
39
|
+
version: '8.0'
|
|
41
40
|
description: 'A lightweight authentication gem built on Rails primitives: has_secure_password,
|
|
42
41
|
signed cookies, rate limiting. Supports email/password, magic links, email confirmation,
|
|
43
42
|
and OAuth.'
|
|
@@ -50,6 +49,7 @@ files:
|
|
|
50
49
|
- CHANGELOG.md
|
|
51
50
|
- MIT-LICENSE
|
|
52
51
|
- README.md
|
|
52
|
+
- app/assets/stylesheets/rails_simple_auth/application.css
|
|
53
53
|
- app/controllers/rails_simple_auth/base_controller.rb
|
|
54
54
|
- app/controllers/rails_simple_auth/confirmations_controller.rb
|
|
55
55
|
- app/controllers/rails_simple_auth/omniauth_callbacks_controller.rb
|
|
@@ -57,6 +57,7 @@ files:
|
|
|
57
57
|
- app/controllers/rails_simple_auth/registrations_controller.rb
|
|
58
58
|
- app/controllers/rails_simple_auth/sessions_controller.rb
|
|
59
59
|
- app/mailers/rails_simple_auth/auth_mailer.rb
|
|
60
|
+
- app/views/layouts/rails_simple_auth.html.erb
|
|
60
61
|
- app/views/rails_simple_auth/confirmations/new.html.erb
|
|
61
62
|
- app/views/rails_simple_auth/mailers/confirmation.html.erb
|
|
62
63
|
- app/views/rails_simple_auth/mailers/magic_link.html.erb
|
|
@@ -71,6 +72,9 @@ files:
|
|
|
71
72
|
- lib/generators/rails_simple_auth/install/install_generator.rb
|
|
72
73
|
- lib/generators/rails_simple_auth/install/templates/initializer.rb
|
|
73
74
|
- lib/generators/rails_simple_auth/install/templates/migration.rb
|
|
75
|
+
- lib/generators/rails_simple_auth/temporary_users/USAGE
|
|
76
|
+
- lib/generators/rails_simple_auth/temporary_users/templates/add_temporary_to_users.rb.erb
|
|
77
|
+
- lib/generators/rails_simple_auth/temporary_users/temporary_users_generator.rb
|
|
74
78
|
- lib/generators/rails_simple_auth/views/views_generator.rb
|
|
75
79
|
- lib/rails_simple_auth.rb
|
|
76
80
|
- lib/rails_simple_auth/configuration.rb
|
|
@@ -81,6 +85,7 @@ files:
|
|
|
81
85
|
- lib/rails_simple_auth/models/concerns/confirmable.rb
|
|
82
86
|
- lib/rails_simple_auth/models/concerns/magic_linkable.rb
|
|
83
87
|
- lib/rails_simple_auth/models/concerns/oauth_connectable.rb
|
|
88
|
+
- lib/rails_simple_auth/models/concerns/temporary_user.rb
|
|
84
89
|
- lib/rails_simple_auth/models/current.rb
|
|
85
90
|
- lib/rails_simple_auth/models/session.rb
|
|
86
91
|
- lib/rails_simple_auth/routes.rb
|
|
@@ -95,7 +100,6 @@ metadata:
|
|
|
95
100
|
bug_tracker_uri: https://github.com/ivankuznetsov/rails_simple_auth/issues
|
|
96
101
|
documentation_uri: https://github.com/ivankuznetsov/rails_simple_auth#readme
|
|
97
102
|
rubygems_mfa_required: 'true'
|
|
98
|
-
post_install_message:
|
|
99
103
|
rdoc_options: []
|
|
100
104
|
require_paths:
|
|
101
105
|
- lib
|
|
@@ -110,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
110
114
|
- !ruby/object:Gem::Version
|
|
111
115
|
version: '0'
|
|
112
116
|
requirements: []
|
|
113
|
-
rubygems_version: 3.
|
|
114
|
-
signing_key:
|
|
117
|
+
rubygems_version: 3.6.9
|
|
115
118
|
specification_version: 4
|
|
116
119
|
summary: Simple, secure authentication for Rails 8+ applications
|
|
117
120
|
test_files: []
|