plutonium 0.23.4 → 0.23.5
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/app/assets/plutonium.css +2 -2
- data/config/initializers/sqlite_json_alias.rb +1 -1
- data/docs/.vitepress/config.ts +60 -19
- data/docs/guide/cursor-rules.md +75 -0
- data/docs/guide/deep-dive/authorization.md +189 -0
- data/docs/guide/{getting-started → deep-dive}/resources.md +137 -0
- data/docs/guide/getting-started/{installation.md → 01-installation.md} +0 -105
- data/docs/guide/index.md +28 -0
- data/docs/guide/introduction/02-core-concepts.md +440 -0
- data/docs/guide/tutorial/01-project-setup.md +75 -0
- data/docs/guide/tutorial/02-creating-a-feature-package.md +45 -0
- data/docs/guide/tutorial/03-defining-resources.md +90 -0
- data/docs/guide/tutorial/04-creating-a-portal.md +101 -0
- data/docs/guide/tutorial/05-customizing-the-ui.md +128 -0
- data/docs/guide/tutorial/06-adding-custom-actions.md +101 -0
- data/docs/guide/tutorial/07-implementing-authorization.md +90 -0
- data/docs/index.md +24 -31
- data/docs/modules/action.md +190 -0
- data/docs/modules/authentication.md +236 -0
- data/docs/modules/configuration.md +599 -0
- data/docs/modules/controller.md +398 -0
- data/docs/modules/core.md +316 -0
- data/docs/modules/definition.md +876 -0
- data/docs/modules/display.md +759 -0
- data/docs/modules/form.md +605 -0
- data/docs/modules/generator.md +288 -0
- data/docs/modules/index.md +167 -0
- data/docs/modules/interaction.md +470 -0
- data/docs/modules/package.md +151 -0
- data/docs/modules/policy.md +176 -0
- data/docs/modules/portal.md +710 -0
- data/docs/modules/query.md +287 -0
- data/docs/modules/resource_record.md +618 -0
- data/docs/modules/routing.md +641 -0
- data/docs/modules/table.md +293 -0
- data/docs/modules/ui.md +631 -0
- data/docs/public/plutonium.mdc +667 -0
- data/lib/generators/pu/core/assets/assets_generator.rb +0 -5
- data/lib/plutonium/ui/display/resource.rb +7 -2
- data/lib/plutonium/ui/table/resource.rb +8 -3
- data/lib/plutonium/version.rb +1 -1
- metadata +36 -9
- data/docs/guide/getting-started/authorization.md +0 -296
- data/docs/guide/getting-started/core-concepts.md +0 -432
- data/docs/guide/getting-started/index.md +0 -21
- data/docs/guide/tutorial.md +0 -401
- /data/docs/guide/{what-is-plutonium.md → introduction/01-what-is-plutonium.md} +0 -0
@@ -0,0 +1,236 @@
|
|
1
|
+
---
|
2
|
+
title: Authentication Module
|
3
|
+
---
|
4
|
+
|
5
|
+
# Authentication Module
|
6
|
+
|
7
|
+
The Authentication module provides comprehensive authentication capabilities for Plutonium applications. It integrates seamlessly with Rodauth for authentication while offering flexibility for different application security needs.
|
8
|
+
|
9
|
+
::: tip
|
10
|
+
The Authentication module is located in `lib/plutonium/auth/`.
|
11
|
+
:::
|
12
|
+
|
13
|
+
## Overview
|
14
|
+
|
15
|
+
- **Rodauth Integration**: Seamless integration with Rodauth authentication
|
16
|
+
- **Public Access Support**: Optional public access for applications without authentication
|
17
|
+
- **Multi-Account Support**: Support for multiple user types and authentication contexts
|
18
|
+
- **Portal-Aware Security**: Authentication scoped to specific portals/packages
|
19
|
+
- **Flexible Configuration**: Support for custom authentication systems
|
20
|
+
- **Security Features**: Built-in security best practices and configurations
|
21
|
+
|
22
|
+
## Core Components
|
23
|
+
|
24
|
+
::: code-group
|
25
|
+
```ruby [Rodauth Integration]
|
26
|
+
# lib/plutonium/auth/rodauth.rb
|
27
|
+
# Basic Rodauth integration
|
28
|
+
module MyApp
|
29
|
+
module Concerns
|
30
|
+
module Controller
|
31
|
+
extend ActiveSupport::Concern
|
32
|
+
include Plutonium::Auth::Rodauth(:main)
|
33
|
+
|
34
|
+
# Automatically provides:
|
35
|
+
# - current_user helper method
|
36
|
+
# - logout_url helper method
|
37
|
+
# - Proper URL options handling
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
```ruby [Public Access]
|
44
|
+
# For applications that don't require authentication
|
45
|
+
module MyApp
|
46
|
+
module Concerns
|
47
|
+
module Controller
|
48
|
+
extend ActiveSupport::Concern
|
49
|
+
include Plutonium::Auth::Public
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
```ruby [Custom Authentication]
|
56
|
+
# For applications using custom authentication systems
|
57
|
+
module MyApp
|
58
|
+
module Concerns
|
59
|
+
module Controller
|
60
|
+
extend ActiveSupport::Concern
|
61
|
+
|
62
|
+
included do
|
63
|
+
helper_method :current_user
|
64
|
+
end
|
65
|
+
|
66
|
+
def current_user
|
67
|
+
# Your custom authentication logic
|
68
|
+
@current_user ||= User.find(session[:user_id]) if session[:user_id]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
:::
|
75
|
+
|
76
|
+
### Automatic Helper Methods
|
77
|
+
|
78
|
+
When you include `Plutonium::Auth::Rodauth`, you automatically get:
|
79
|
+
|
80
|
+
- `current_user`: Returns the authenticated user/account (available in controllers and views).
|
81
|
+
- `logout_url`: Returns the logout URL for the current account type (available in controllers and views).
|
82
|
+
- `rodauth`: Access to the Rodauth instance (available in controllers only).
|
83
|
+
|
84
|
+
## Rodauth Configuration
|
85
|
+
|
86
|
+
### Account Generation
|
87
|
+
|
88
|
+
Plutonium provides generators for creating Rodauth accounts:
|
89
|
+
|
90
|
+
::: code-group
|
91
|
+
```bash [Basic User Account]
|
92
|
+
rails generate pu:rodauth:account user
|
93
|
+
```
|
94
|
+
|
95
|
+
```bash [Admin Account]
|
96
|
+
rails generate pu:rodauth:admin admin
|
97
|
+
```
|
98
|
+
|
99
|
+
```bash [Custom Features]
|
100
|
+
rails generate pu:rodauth:account customer \
|
101
|
+
--no-defaults \
|
102
|
+
--login --logout --create-account --verify-account \
|
103
|
+
--reset-password --change-password --remember
|
104
|
+
```
|
105
|
+
:::
|
106
|
+
|
107
|
+
### Configuration Examples
|
108
|
+
|
109
|
+
::: details Standard Rodauth Plugin Configuration
|
110
|
+
```ruby
|
111
|
+
# app/rodauth/user_rodauth_plugin.rb
|
112
|
+
class UserRodauthPlugin < RodauthPlugin
|
113
|
+
configure do
|
114
|
+
# Enable features
|
115
|
+
enable :login, :logout, :create_account, :verify_account,
|
116
|
+
:reset_password, :change_password, :remember
|
117
|
+
|
118
|
+
# Account model
|
119
|
+
rails_account_model { User }
|
120
|
+
|
121
|
+
# Controller for views and CSRF
|
122
|
+
rails_controller { Rodauth::UserController }
|
123
|
+
|
124
|
+
# Redirects
|
125
|
+
login_redirect "/"
|
126
|
+
logout_redirect "/"
|
127
|
+
create_account_redirect "/"
|
128
|
+
|
129
|
+
# Email configuration
|
130
|
+
create_reset_password_email do
|
131
|
+
UserMailer.reset_password(account_id, reset_password_key_value)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Remember feature
|
135
|
+
after_login { remember_login }
|
136
|
+
extend_remember_deadline? true
|
137
|
+
|
138
|
+
# Password requirements
|
139
|
+
password_minimum_length 8
|
140
|
+
|
141
|
+
# Custom validation
|
142
|
+
before_create_account do
|
143
|
+
throw_error_status(422, "name", "must be present") if param("name").empty?
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
```
|
148
|
+
:::
|
149
|
+
|
150
|
+
::: details Enhanced Admin Configuration with MFA
|
151
|
+
```ruby
|
152
|
+
# app/rodauth/admin_rodauth_plugin.rb
|
153
|
+
class AdminRodauthPlugin < RodauthPlugin
|
154
|
+
configure do
|
155
|
+
enable :login, :logout, :create_account, :verify_account,
|
156
|
+
:reset_password, :change_password, :remember,
|
157
|
+
:otp, :recovery_codes, :lockout, :active_sessions,
|
158
|
+
:audit_logging, :password_grace_period, :internal_request
|
159
|
+
|
160
|
+
# Account model
|
161
|
+
rails_account_model { Admin }
|
162
|
+
|
163
|
+
# Controller
|
164
|
+
rails_controller { Rodauth::AdminController }
|
165
|
+
|
166
|
+
# Prefix for admin routes
|
167
|
+
prefix "/admin"
|
168
|
+
|
169
|
+
# Require MFA setup
|
170
|
+
two_factor_not_setup_error_flash "You need to setup two factor authentication"
|
171
|
+
two_factor_auth_return_to_requested_location? true
|
172
|
+
|
173
|
+
# Multi-phase login for enhanced security
|
174
|
+
use_multi_phase_login? true
|
175
|
+
|
176
|
+
# Prevent web signup for admin accounts
|
177
|
+
before_create_account_route do
|
178
|
+
request.halt unless internal_request?
|
179
|
+
end
|
180
|
+
|
181
|
+
# Enhanced security settings
|
182
|
+
max_invalid_logins 3
|
183
|
+
lockout_deadline_interval Hash[minutes: 60]
|
184
|
+
|
185
|
+
# Session security
|
186
|
+
session_key "_admin_session"
|
187
|
+
remember_cookie_key "_admin_remember"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
```
|
191
|
+
:::
|
192
|
+
|
193
|
+
## Portal Integration
|
194
|
+
|
195
|
+
Each portal can have its own authentication requirements, allowing you to secure different parts of your application with different user types.
|
196
|
+
|
197
|
+
::: code-group
|
198
|
+
```ruby [Admin Portal]
|
199
|
+
# Admin portal with admin authentication
|
200
|
+
module AdminPortal
|
201
|
+
module Concerns
|
202
|
+
module Controller
|
203
|
+
extend ActiveSupport::Concern
|
204
|
+
include Plutonium::Portal::Controller
|
205
|
+
include Plutonium::Auth::Rodauth(:admin)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
```
|
210
|
+
|
211
|
+
```ruby [Customer Portal]
|
212
|
+
# Customer portal with customer authentication
|
213
|
+
module CustomerPortal
|
214
|
+
module Concerns
|
215
|
+
module Controller
|
216
|
+
extend ActiveSupport::Concern
|
217
|
+
include Plutonium::Portal::Controller
|
218
|
+
include Plutonium::Auth::Rodauth(:customer)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
```
|
223
|
+
|
224
|
+
```ruby [Public Portal]
|
225
|
+
# Public portal without authentication
|
226
|
+
module PublicPortal
|
227
|
+
module Concerns
|
228
|
+
module Controller
|
229
|
+
extend ActiveSupport::Concern
|
230
|
+
include Plutonium::Portal::Controller
|
231
|
+
include Plutonium::Auth::Public
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
```
|
236
|
+
:::
|