rails-auth-eassy 0.1.1 → 0.1.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 +83 -3
- data/app/controllers/concerns/rails/auth/authenticatable_controller.rb +6 -0
- data/app/controllers/rails/auth/confirmations_controller.rb +11 -2
- data/app/controllers/rails/auth/registrations_controller.rb +2 -1
- data/app/controllers/rails/auth/sessions_controller.rb +0 -8
- data/app/mailers/rails/auth/application_mailer.rb +1 -1
- data/app/models/concerns/rails/auth/authenticatable.rb +5 -1
- data/app/views/rails/auth/security/sessions.html.erb +8 -0
- data/config/routes.rb +1 -0
- data/lib/generators/rails_auth/install/templates/rails_auth.rb +9 -0
- data/lib/rails/auth/version.rb +1 -1
- data/lib/rails/auth.rb +9 -0
- data/lib/rails-auth-eassy.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6592b7a6b5fcdaf1119be69d88a0522933d84181fe9acb617946632260603e94
|
|
4
|
+
data.tar.gz: 856c026d8a9eb2765501ee7258fd04da26c360181110b591f5b803f564049cf0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 36cce21b0bdbf4b612c52750758cd2f8a0a46d583018aa3068e63f18cc753061569f722723729cdfe75b48e958de3892b25020f27c3fa8a017428e339ac8fb7b
|
|
7
|
+
data.tar.gz: 834e5b65d275f7edf0f8412c0117e8f81a380ec054008a1d32d4eedcbc596d85518c010b8667f5aab8265fb3a16fe5e226d2365de1a7c7599f16bfeb719b7564
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Rails::Auth** is a high-performance, security-first authentication engine for Ruby on Rails. Designed as a modern, transparent alternative to Devise, it empowers users with deep visibility and control over their account security through database-backed sessions and enterprise-grade protection.
|
|
4
4
|
|
|
5
|
-
[](https://badge.fury.io/rb/rails-auth)
|
|
5
|
+
[](https://badge.fury.io/rb/rails-auth-eassy)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
[](https://rubyonrails.org)
|
|
8
8
|
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
- [Controller Helpers](#controller-helpers)
|
|
17
17
|
- [Role-Based Access Control (RBAC)](#role-based-access-control-rbac)
|
|
18
18
|
- [Avatar Support](#avatar-support)
|
|
19
|
+
- [🔑 Core Authentication Flows](#-core-authentication-flows)
|
|
19
20
|
- [🛡️ Security Dashboard](#-security-dashboard)
|
|
21
|
+
- [📧 Mailer Setup](#-mailer-setup)
|
|
20
22
|
- [⚙️ Configuration](#-configuration)
|
|
21
23
|
- [🎨 Customization](#-customization)
|
|
22
24
|
- [👥 Authors & Maintainers](#-authors--maintainers)
|
|
@@ -54,7 +56,13 @@
|
|
|
54
56
|
Add this line to your application's Gemfile:
|
|
55
57
|
|
|
56
58
|
```ruby
|
|
57
|
-
gem "rails-auth"
|
|
59
|
+
gem "rails-auth-eassy"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Or install it directly via CLI:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
$ gem install rails-auth-eassy
|
|
58
66
|
```
|
|
59
67
|
|
|
60
68
|
Then execute:
|
|
@@ -147,9 +155,49 @@ rails_auth.stop_impersonations_path, method: :delete
|
|
|
147
155
|
|
|
148
156
|
---
|
|
149
157
|
|
|
158
|
+
## 🔑 Core Authentication Flows
|
|
159
|
+
|
|
160
|
+
Once installed, the engine provides the following core routes for user authentication. You can link to these anywhere in your application layout (e.g., your navigation bar).
|
|
161
|
+
|
|
162
|
+
### Sign Up (Registration)
|
|
163
|
+
To allow new users to create an account:
|
|
164
|
+
```erb
|
|
165
|
+
<%= link_to "Sign Up", rails_auth.new_registration_path %>
|
|
166
|
+
```
|
|
167
|
+
*Note: If email confirmation is enabled, they will be sent a confirmation link before they can sign in.*
|
|
168
|
+
|
|
169
|
+
### Sign In (Login)
|
|
170
|
+
To allow existing users to log into their account:
|
|
171
|
+
```erb
|
|
172
|
+
<%= link_to "Sign In", rails_auth.new_session_path %>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Sign Out (Logout)
|
|
176
|
+
To securely log the user out and destroy their current session:
|
|
177
|
+
```erb
|
|
178
|
+
<%= button_to "Sign Out", rails_auth.session_path, method: :delete %>
|
|
179
|
+
```
|
|
180
|
+
*(We use `button_to` with `method: :delete` for security best practices against CSRF).*
|
|
181
|
+
|
|
182
|
+
### Putting it together in a Navbar
|
|
183
|
+
```erb
|
|
184
|
+
<nav>
|
|
185
|
+
<% if user_signed_in? %>
|
|
186
|
+
<span>Welcome, <%= current_user.email %>!</span>
|
|
187
|
+
<%= link_to "Security Settings", rails_auth.security_sessions_path %>
|
|
188
|
+
<%= button_to "Sign Out", rails_auth.session_path, method: :delete %>
|
|
189
|
+
<% else %>
|
|
190
|
+
<%= link_to "Sign In", rails_auth.new_session_path %>
|
|
191
|
+
<%= link_to "Sign Up", rails_auth.new_registration_path %>
|
|
192
|
+
<% end %>
|
|
193
|
+
</nav>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
150
198
|
## 🛡️ Security Dashboard
|
|
151
199
|
|
|
152
|
-
Users can manage their security settings, view active
|
|
200
|
+
Users can manage their security settings, edit their profile/avatar, view active audit logs, and enable MFA at `/auth/security/sessions`.
|
|
153
201
|
|
|
154
202
|
### Linking to the Dashboard
|
|
155
203
|
```erb
|
|
@@ -158,6 +206,38 @@ Users can manage their security settings, view active sessions, and enable MFA a
|
|
|
158
206
|
|
|
159
207
|
---
|
|
160
208
|
|
|
209
|
+
## 📧 Mailer Setup
|
|
210
|
+
|
|
211
|
+
Rails::Auth sends emails for confirmation instructions, password resets, and account unlock instructions.
|
|
212
|
+
|
|
213
|
+
### 1. Set Default URL Options
|
|
214
|
+
In your environments (e.g., `config/environments/development.rb`), set the host for the mailer:
|
|
215
|
+
```ruby
|
|
216
|
+
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### 2. Configure the Sender & Tokens
|
|
220
|
+
In `config/initializers/rails_auth.rb`, you can customize the sender and confirmation tokens:
|
|
221
|
+
```ruby
|
|
222
|
+
Rails::Auth.setup do |config|
|
|
223
|
+
config.mailer_sender = "noreply@yourdomain.com"
|
|
224
|
+
|
|
225
|
+
# Optional: Customize confirmation tokens
|
|
226
|
+
# config.confirmation_token_format = :numeric # default is :hex
|
|
227
|
+
# config.confirmation_token_length = 6 # default is 20
|
|
228
|
+
end
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### 3. Development Tip
|
|
232
|
+
We recommend using [letter_opener](https://github.com/ryanb/letter_opener) to preview emails in your browser instead of sending them.
|
|
233
|
+
```ruby
|
|
234
|
+
# config/environments/development.rb
|
|
235
|
+
config.action_mailer.delivery_method = :letter_opener
|
|
236
|
+
config.action_mailer.perform_deliveries = true
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
161
241
|
## ⚙️ Configuration
|
|
162
242
|
|
|
163
243
|
Customize the gem behavior in `config/initializers/rails_auth.rb`:
|
|
@@ -39,6 +39,12 @@ module Rails
|
|
|
39
39
|
authorize_role!(:admin)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
def require_confirmed!
|
|
43
|
+
unless current_user&.confirmed?
|
|
44
|
+
redirect_to rails_auth.security_sessions_path, alert: "Please confirm your email address to access this page."
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
42
48
|
def authorize_role!(*roles)
|
|
43
49
|
unless user_signed_in? && roles.any? { |role| current_user.send("#{role}?") }
|
|
44
50
|
if request.format.json?
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
module Rails
|
|
2
2
|
module Auth
|
|
3
3
|
class ConfirmationsController < ApplicationController
|
|
4
|
-
skip_before_action :authenticate_user
|
|
4
|
+
skip_before_action :authenticate_user!, only: [ :show ]
|
|
5
5
|
|
|
6
6
|
def show
|
|
7
7
|
user = Rails::Auth.user_class.find_by(confirmation_token: params[:confirmation_token])
|
|
8
8
|
if user
|
|
9
9
|
user.confirm!
|
|
10
|
-
sign_in(user)
|
|
10
|
+
sign_in(user) unless user_signed_in?
|
|
11
11
|
redirect_to main_app.root_path, notice: "Your account has been confirmed."
|
|
12
12
|
else
|
|
13
13
|
redirect_to new_session_path, alert: "Invalid confirmation token."
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
|
+
|
|
17
|
+
def create
|
|
18
|
+
if current_user && !current_user.confirmed?
|
|
19
|
+
current_user.send_confirmation_instructions
|
|
20
|
+
redirect_to rails_auth.security_sessions_path, notice: "Confirmation instructions have been resent to your email address."
|
|
21
|
+
else
|
|
22
|
+
redirect_to main_app.root_path, alert: "Account already confirmed."
|
|
23
|
+
end
|
|
24
|
+
end
|
|
16
25
|
end
|
|
17
26
|
end
|
|
18
27
|
end
|
|
@@ -11,7 +11,8 @@ module Rails
|
|
|
11
11
|
@user = Rails::Auth.user_class.new(user_params)
|
|
12
12
|
if @user.save
|
|
13
13
|
@user.send_confirmation_instructions
|
|
14
|
-
|
|
14
|
+
sign_in(@user)
|
|
15
|
+
redirect_to rails_auth.security_sessions_path, notice: "Account created successfully. A confirmation link has been sent to your email address. You can now set up your profile and security settings."
|
|
15
16
|
else
|
|
16
17
|
render :new, status: :unprocessable_entity
|
|
17
18
|
end
|
|
@@ -18,14 +18,6 @@ module Rails
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
if user&.authenticate(params[:password])
|
|
21
|
-
unless user.confirmed?
|
|
22
|
-
respond_to do |format|
|
|
23
|
-
format.html { redirect_to new_session_path, alert: "Please confirm your email address before signing in." }
|
|
24
|
-
format.json { render json: { error: "Email not confirmed" }, status: :unauthorized }
|
|
25
|
-
end
|
|
26
|
-
return
|
|
27
|
-
end
|
|
28
|
-
|
|
29
21
|
user.update(failed_attempts: 0) # Reset on success
|
|
30
22
|
|
|
31
23
|
if user.otp_enabled?
|
|
@@ -27,7 +27,11 @@ def confirmed?
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def generate_confirmation_token
|
|
30
|
-
|
|
30
|
+
if Rails::Auth.confirmation_token_format == :numeric
|
|
31
|
+
self.confirmation_token = Array.new(Rails::Auth.confirmation_token_length) { rand(10) }.join
|
|
32
|
+
else
|
|
33
|
+
self.confirmation_token = SecureRandom.hex(Rails::Auth.confirmation_token_length / 2)
|
|
34
|
+
end
|
|
31
35
|
self.confirmation_sent_at = Time.current
|
|
32
36
|
end
|
|
33
37
|
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
<h2>Account Security</h2>
|
|
2
2
|
|
|
3
|
+
<% unless current_user.confirmed? %>
|
|
4
|
+
<div style="background: #fff3cd; padding: 15px; margin-bottom: 20px; border: 1px solid #ffeeba; border-radius: 4px; color: #856404;">
|
|
5
|
+
<strong>Please confirm your email address.</strong>
|
|
6
|
+
We sent a confirmation link to <%= current_user.email %>.
|
|
7
|
+
<%= button_to "Resend Link", rails_auth.resend_confirmation_path, method: :post, style: "display: inline-block; margin-left: 10px;" %>
|
|
8
|
+
</div>
|
|
9
|
+
<% end %>
|
|
10
|
+
|
|
3
11
|
<div style="margin-bottom: 20px;">
|
|
4
12
|
<% if current_user.avatar.attached? %>
|
|
5
13
|
<%= image_tag current_user.avatar.variant(resize_to_limit: [100, 100]), style: "border-radius: 50%;" %>
|
data/config/routes.rb
CHANGED
|
@@ -4,6 +4,7 @@ Rails::Auth::Engine.routes.draw do
|
|
|
4
4
|
resources :password_resets, only: [ :new, :create, :edit, :update ], constraints: { id: /.*/ }
|
|
5
5
|
|
|
6
6
|
get "confirmation", to: "confirmations#show"
|
|
7
|
+
post "confirmation/resend", to: "confirmations#create", as: :resend_confirmation
|
|
7
8
|
get "unlock", to: "unlocks#show"
|
|
8
9
|
|
|
9
10
|
resource :mfa, controller: "mfa", only: [ :show, :create, :destroy ]
|
|
@@ -4,4 +4,13 @@ Rails::Auth.setup do |config|
|
|
|
4
4
|
|
|
5
5
|
# The class name of the session model
|
|
6
6
|
# config.session_class_name = "Session"
|
|
7
|
+
|
|
8
|
+
# The email address that will be used as the "from" address for all emails
|
|
9
|
+
# config.mailer_sender = "from@example.com"
|
|
10
|
+
|
|
11
|
+
# The format of the confirmation token (:hex or :numeric)
|
|
12
|
+
# config.confirmation_token_format = :hex
|
|
13
|
+
|
|
14
|
+
# The length of the confirmation token
|
|
15
|
+
# config.confirmation_token_length = 20
|
|
7
16
|
end
|
data/lib/rails/auth/version.rb
CHANGED
data/lib/rails/auth.rb
CHANGED
|
@@ -16,6 +16,15 @@ module Rails
|
|
|
16
16
|
mattr_accessor :session_class_name
|
|
17
17
|
@@session_class_name = "Session"
|
|
18
18
|
|
|
19
|
+
mattr_accessor :mailer_sender
|
|
20
|
+
@@mailer_sender = "from@example.com"
|
|
21
|
+
|
|
22
|
+
mattr_accessor :confirmation_token_format
|
|
23
|
+
@@confirmation_token_format = :hex # :hex or :numeric
|
|
24
|
+
|
|
25
|
+
mattr_accessor :confirmation_token_length
|
|
26
|
+
@@confirmation_token_length = 20
|
|
27
|
+
|
|
19
28
|
mattr_writer :jwt_secret
|
|
20
29
|
|
|
21
30
|
def self.jwt_secret
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "rails/auth"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails-auth-eassy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shiboshree Roy
|
|
@@ -147,6 +147,7 @@ files:
|
|
|
147
147
|
- lib/generators/rails_auth/model/templates/session.rb
|
|
148
148
|
- lib/generators/rails_auth/model/templates/user.rb
|
|
149
149
|
- lib/generators/rails_auth/views/views_generator.rb
|
|
150
|
+
- lib/rails-auth-eassy.rb
|
|
150
151
|
- lib/rails/auth.rb
|
|
151
152
|
- lib/rails/auth/engine.rb
|
|
152
153
|
- lib/rails/auth/version.rb
|