rails-auth-eassy 0.1.1
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +206 -0
- data/Rakefile +6 -0
- data/app/assets/stylesheets/rails/auth/application.css +15 -0
- data/app/controllers/concerns/rails/auth/authenticatable_controller.rb +114 -0
- data/app/controllers/rails/auth/application_controller.rb +9 -0
- data/app/controllers/rails/auth/confirmations_controller.rb +18 -0
- data/app/controllers/rails/auth/impersonations_controller.rb +46 -0
- data/app/controllers/rails/auth/mfa_controller.rb +26 -0
- data/app/controllers/rails/auth/otp_verifications_controller.rb +25 -0
- data/app/controllers/rails/auth/password_resets_controller.rb +51 -0
- data/app/controllers/rails/auth/profiles_controller.rb +24 -0
- data/app/controllers/rails/auth/registrations_controller.rb +27 -0
- data/app/controllers/rails/auth/security_controller.rb +27 -0
- data/app/controllers/rails/auth/sessions_controller.rb +69 -0
- data/app/controllers/rails/auth/unlocks_controller.rb +17 -0
- data/app/helpers/rails/auth/application_helper.rb +6 -0
- data/app/jobs/rails/auth/application_job.rb +6 -0
- data/app/mailers/rails/auth/application_mailer.rb +8 -0
- data/app/mailers/rails/auth/user_mailer.rb +20 -0
- data/app/models/concerns/rails/auth/authenticatable.rb +107 -0
- data/app/models/concerns/rails/auth/sessionable.rb +30 -0
- data/app/models/rails/auth/application_record.rb +7 -0
- data/app/models/rails/auth/current.rb +7 -0
- data/app/models/rails/auth/security_event.rb +25 -0
- data/app/views/layouts/rails/auth/application.html.erb +29 -0
- data/app/views/rails/auth/mfa/show.html.erb +24 -0
- data/app/views/rails/auth/otp_verifications/new.html.erb +13 -0
- data/app/views/rails/auth/password_resets/edit.html.erb +28 -0
- data/app/views/rails/auth/password_resets/new.html.erb +14 -0
- data/app/views/rails/auth/profiles/edit.html.erb +44 -0
- data/app/views/rails/auth/registrations/new.html.erb +40 -0
- data/app/views/rails/auth/security/sessions.html.erb +92 -0
- data/app/views/rails/auth/sessions/new.html.erb +20 -0
- data/app/views/rails/auth/user_mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/rails/auth/user_mailer/password_reset.html.erb +8 -0
- data/app/views/rails/auth/user_mailer/password_reset.text.erb +8 -0
- data/app/views/rails/auth/user_mailer/unlock_instructions.html.erb +7 -0
- data/config/routes.rb +20 -0
- data/lib/generators/rails_auth/install/install_generator.rb +21 -0
- data/lib/generators/rails_auth/install/templates/rails_auth.rb +7 -0
- data/lib/generators/rails_auth/model/model_generator.rb +27 -0
- data/lib/generators/rails_auth/model/templates/create_rails_auth_tables.rb +60 -0
- data/lib/generators/rails_auth/model/templates/session.rb +3 -0
- data/lib/generators/rails_auth/model/templates/user.rb +3 -0
- data/lib/generators/rails_auth/views/views_generator.rb +13 -0
- data/lib/rails/auth/engine.rb +7 -0
- data/lib/rails/auth/version.rb +5 -0
- data/lib/rails/auth.rb +49 -0
- data/lib/tasks/rails/auth_tasks.rake +4 -0
- metadata +177 -0
data/config/routes.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Rails::Auth::Engine.routes.draw do
|
|
2
|
+
resource :session, only: [ :new, :create, :destroy ]
|
|
3
|
+
resource :registration, only: [ :new, :create ]
|
|
4
|
+
resources :password_resets, only: [ :new, :create, :edit, :update ], constraints: { id: /.*/ }
|
|
5
|
+
|
|
6
|
+
get "confirmation", to: "confirmations#show"
|
|
7
|
+
get "unlock", to: "unlocks#show"
|
|
8
|
+
|
|
9
|
+
resource :mfa, controller: "mfa", only: [ :show, :create, :destroy ]
|
|
10
|
+
resource :otp_verification, only: [ :new, :create ]
|
|
11
|
+
resource :profile, only: [ :edit, :update ]
|
|
12
|
+
|
|
13
|
+
resources :impersonations, only: [ :create ] do
|
|
14
|
+
delete :stop, on: :collection, action: :destroy
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
get "security/sessions", to: "security#sessions"
|
|
18
|
+
delete "security/sessions/:id", to: "security#revoke_session", as: :revoke_session
|
|
19
|
+
delete "security/revoke_all", to: "security#revoke_all_sessions", as: :revoke_all_sessions
|
|
20
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "rails/generators/base"
|
|
2
|
+
|
|
3
|
+
module RailsAuth
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
|
7
|
+
|
|
8
|
+
def copy_initializer
|
|
9
|
+
template "rails_auth.rb", "config/initializers/rails_auth.rb"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add_routes
|
|
13
|
+
route 'mount Rails::Auth::Engine => "/auth"'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def display_readme
|
|
17
|
+
readme "README" if File.exist?("README")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require "rails/generators/active_record"
|
|
2
|
+
|
|
3
|
+
module RailsAuth
|
|
4
|
+
module Generators
|
|
5
|
+
class ModelGenerator < ActiveRecord::Generators::Base
|
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
|
7
|
+
|
|
8
|
+
def create_user_model
|
|
9
|
+
template "user.rb", "app/models/#{name.underscore}.rb"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create_session_model
|
|
13
|
+
template "session.rb", "app/models/session.rb"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create_migrations
|
|
17
|
+
migration_template "create_rails_auth_tables.rb", "db/migrate/create_rails_auth_tables.rb"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def migration_class_name
|
|
23
|
+
"CreateRailsAuthTables"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
class CreateRailsAuthTables < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
|
2
|
+
def change
|
|
3
|
+
create_table :<%= table_name %> do |t|
|
|
4
|
+
t.string :email, null: false
|
|
5
|
+
t.string :password_digest, null: false
|
|
6
|
+
t.string :reset_token
|
|
7
|
+
t.datetime :reset_sent_at
|
|
8
|
+
|
|
9
|
+
# Confirmable
|
|
10
|
+
t.string :confirmation_token
|
|
11
|
+
t.datetime :confirmed_at
|
|
12
|
+
t.datetime :confirmation_sent_at
|
|
13
|
+
t.string :unconfirmed_email # Only if using reconfirmable
|
|
14
|
+
|
|
15
|
+
# Lockable
|
|
16
|
+
t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
|
17
|
+
t.string :unlock_token # Only if unlock strategy is :email or :both
|
|
18
|
+
t.datetime :locked_at
|
|
19
|
+
|
|
20
|
+
# MFA
|
|
21
|
+
t.string :otp_secret
|
|
22
|
+
t.boolean :otp_enabled, default: false, null: false
|
|
23
|
+
|
|
24
|
+
# RBAC
|
|
25
|
+
t.integer :role, default: 0, null: false
|
|
26
|
+
|
|
27
|
+
t.timestamps
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
add_index :<%= table_name %>, :email, unique: true
|
|
31
|
+
add_index :<%= table_name %>, :reset_token, unique: true
|
|
32
|
+
add_index :<%= table_name %>, :confirmation_token, unique: true
|
|
33
|
+
add_index :<%= table_name %>, :unlock_token, unique: true
|
|
34
|
+
|
|
35
|
+
create_table :sessions do |t|
|
|
36
|
+
t.references :user, null: false, foreign_key: { to_table: :<%= table_name %> }
|
|
37
|
+
t.string :token, null: false
|
|
38
|
+
t.string :ip_address
|
|
39
|
+
t.string :user_agent
|
|
40
|
+
t.string :browser
|
|
41
|
+
t.string :os
|
|
42
|
+
t.integer :impersonated_by_id # For Admin Impersonation
|
|
43
|
+
t.datetime :last_active_at
|
|
44
|
+
|
|
45
|
+
t.timestamps
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
add_index :sessions, :token, unique: true
|
|
49
|
+
|
|
50
|
+
create_table :security_events do |t|
|
|
51
|
+
t.references :user, null: false, foreign_key: { to_table: :<%= table_name %> }
|
|
52
|
+
t.string :event_type, null: false
|
|
53
|
+
t.string :ip_address
|
|
54
|
+
t.string :user_agent
|
|
55
|
+
t.json :details
|
|
56
|
+
|
|
57
|
+
t.timestamps
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require "rails/generators/base"
|
|
2
|
+
|
|
3
|
+
module RailsAuth
|
|
4
|
+
module Generators
|
|
5
|
+
class ViewsGenerator < Rails::Generators::Base
|
|
6
|
+
source_root File.expand_path("../../../../app/views/rails/auth", __dir__)
|
|
7
|
+
|
|
8
|
+
def copy_views
|
|
9
|
+
directory ".", "app/views/rails/auth"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/rails/auth.rb
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require "rails/auth/version"
|
|
2
|
+
require "rails/auth/engine"
|
|
3
|
+
require "rotp"
|
|
4
|
+
require "rqrcode"
|
|
5
|
+
require "jwt"
|
|
6
|
+
|
|
7
|
+
module Rails
|
|
8
|
+
module Auth
|
|
9
|
+
def self.table_name_prefix
|
|
10
|
+
""
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
mattr_accessor :user_class_name
|
|
14
|
+
@@user_class_name = "User"
|
|
15
|
+
|
|
16
|
+
mattr_accessor :session_class_name
|
|
17
|
+
@@session_class_name = "Session"
|
|
18
|
+
|
|
19
|
+
mattr_writer :jwt_secret
|
|
20
|
+
|
|
21
|
+
def self.jwt_secret
|
|
22
|
+
@@jwt_secret || ENV["RAILS_AUTH_JWT_SECRET"] || (Rails.application&.respond_to?(:secret_key_base) ? Rails.application.secret_key_base : "default_secret_for_testing_only")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.setup
|
|
26
|
+
yield self
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.user_class
|
|
30
|
+
@@user_class_name.constantize
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.session_class
|
|
34
|
+
@@session_class_name.constantize
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.encode_jwt(payload, exp = 24.hours.from_now)
|
|
38
|
+
payload[:exp] = exp.to_i
|
|
39
|
+
::JWT.encode(payload, self.jwt_secret.to_s)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.decode_jwt(token)
|
|
43
|
+
body = ::JWT.decode(token, self.jwt_secret.to_s)[0]
|
|
44
|
+
HashWithIndifferentAccess.new body
|
|
45
|
+
rescue ::JWT::DecodeError
|
|
46
|
+
nil
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rails-auth-eassy
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Shiboshree Roy
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '7.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '7.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: bcrypt
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 3.1.7
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 3.1.7
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: useragent
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rotp
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '6.2'
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '6.2'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rqrcode
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '2.2'
|
|
75
|
+
type: :runtime
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '2.2'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: jwt
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '2.7'
|
|
89
|
+
type: :runtime
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '2.7'
|
|
96
|
+
description: A modern, advanced authentication engine for Rails with built-in session
|
|
97
|
+
management, multi-factor authentication support, and more.
|
|
98
|
+
email:
|
|
99
|
+
- shiboshreeroy169@gmail.com
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- MIT-LICENSE
|
|
105
|
+
- README.md
|
|
106
|
+
- Rakefile
|
|
107
|
+
- app/assets/stylesheets/rails/auth/application.css
|
|
108
|
+
- app/controllers/concerns/rails/auth/authenticatable_controller.rb
|
|
109
|
+
- app/controllers/rails/auth/application_controller.rb
|
|
110
|
+
- app/controllers/rails/auth/confirmations_controller.rb
|
|
111
|
+
- app/controllers/rails/auth/impersonations_controller.rb
|
|
112
|
+
- app/controllers/rails/auth/mfa_controller.rb
|
|
113
|
+
- app/controllers/rails/auth/otp_verifications_controller.rb
|
|
114
|
+
- app/controllers/rails/auth/password_resets_controller.rb
|
|
115
|
+
- app/controllers/rails/auth/profiles_controller.rb
|
|
116
|
+
- app/controllers/rails/auth/registrations_controller.rb
|
|
117
|
+
- app/controllers/rails/auth/security_controller.rb
|
|
118
|
+
- app/controllers/rails/auth/sessions_controller.rb
|
|
119
|
+
- app/controllers/rails/auth/unlocks_controller.rb
|
|
120
|
+
- app/helpers/rails/auth/application_helper.rb
|
|
121
|
+
- app/jobs/rails/auth/application_job.rb
|
|
122
|
+
- app/mailers/rails/auth/application_mailer.rb
|
|
123
|
+
- app/mailers/rails/auth/user_mailer.rb
|
|
124
|
+
- app/models/concerns/rails/auth/authenticatable.rb
|
|
125
|
+
- app/models/concerns/rails/auth/sessionable.rb
|
|
126
|
+
- app/models/rails/auth/application_record.rb
|
|
127
|
+
- app/models/rails/auth/current.rb
|
|
128
|
+
- app/models/rails/auth/security_event.rb
|
|
129
|
+
- app/views/layouts/rails/auth/application.html.erb
|
|
130
|
+
- app/views/rails/auth/mfa/show.html.erb
|
|
131
|
+
- app/views/rails/auth/otp_verifications/new.html.erb
|
|
132
|
+
- app/views/rails/auth/password_resets/edit.html.erb
|
|
133
|
+
- app/views/rails/auth/password_resets/new.html.erb
|
|
134
|
+
- app/views/rails/auth/profiles/edit.html.erb
|
|
135
|
+
- app/views/rails/auth/registrations/new.html.erb
|
|
136
|
+
- app/views/rails/auth/security/sessions.html.erb
|
|
137
|
+
- app/views/rails/auth/sessions/new.html.erb
|
|
138
|
+
- app/views/rails/auth/user_mailer/confirmation_instructions.html.erb
|
|
139
|
+
- app/views/rails/auth/user_mailer/password_reset.html.erb
|
|
140
|
+
- app/views/rails/auth/user_mailer/password_reset.text.erb
|
|
141
|
+
- app/views/rails/auth/user_mailer/unlock_instructions.html.erb
|
|
142
|
+
- config/routes.rb
|
|
143
|
+
- lib/generators/rails_auth/install/install_generator.rb
|
|
144
|
+
- lib/generators/rails_auth/install/templates/rails_auth.rb
|
|
145
|
+
- lib/generators/rails_auth/model/model_generator.rb
|
|
146
|
+
- lib/generators/rails_auth/model/templates/create_rails_auth_tables.rb
|
|
147
|
+
- lib/generators/rails_auth/model/templates/session.rb
|
|
148
|
+
- lib/generators/rails_auth/model/templates/user.rb
|
|
149
|
+
- lib/generators/rails_auth/views/views_generator.rb
|
|
150
|
+
- lib/rails/auth.rb
|
|
151
|
+
- lib/rails/auth/engine.rb
|
|
152
|
+
- lib/rails/auth/version.rb
|
|
153
|
+
- lib/tasks/rails/auth_tasks.rake
|
|
154
|
+
homepage: https://github.com/shiboshreeroy/rails-auth
|
|
155
|
+
licenses:
|
|
156
|
+
- MIT
|
|
157
|
+
metadata:
|
|
158
|
+
homepage_uri: https://github.com/shiboshreeroy/rails-auth
|
|
159
|
+
source_code_uri: https://github.com/shiboshreeroy/rails-auth/tree/main
|
|
160
|
+
rdoc_options: []
|
|
161
|
+
require_paths:
|
|
162
|
+
- lib
|
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
164
|
+
requirements:
|
|
165
|
+
- - ">="
|
|
166
|
+
- !ruby/object:Gem::Version
|
|
167
|
+
version: 3.0.0
|
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
|
+
requirements:
|
|
170
|
+
- - ">="
|
|
171
|
+
- !ruby/object:Gem::Version
|
|
172
|
+
version: '0'
|
|
173
|
+
requirements: []
|
|
174
|
+
rubygems_version: 4.0.11
|
|
175
|
+
specification_version: 4
|
|
176
|
+
summary: Advanced authentication engine for Rails.
|
|
177
|
+
test_files: []
|