authentication-zero 2.9.0 → 2.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -0
- data/authentication-zero-api.md +210 -0
- data/lib/authentication_zero/version.rb +1 -1
- data/lib/generators/authentication/authentication_generator.rb +17 -67
- data/lib/generators/authentication/templates/controllers/api/application_controller.rb.tt +26 -0
- data/lib/generators/authentication/templates/controllers/html/application_controller.rb.tt +24 -0
- data/lib/generators/authentication/templates/erb/identity/password_resets/edit.html.erb.tt +2 -2
- data/lib/generators/authentication/templates/erb/passwords/edit.html.erb.tt +3 -3
- data/lib/generators/authentication/templates/erb/registrations/new.html.erb.tt +2 -2
- data/lib/generators/authentication/templates/erb/sessions/sudos/new.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/models/model.rb.tt +2 -2
- data/lib/generators/authentication/templates/test_unit/application_system_test_case.rb.tt +15 -0
- data/lib/generators/authentication/templates/test_unit/controllers/api/identity/email_verifications_controller_test.rb.tt +0 -4
- data/lib/generators/authentication/templates/test_unit/controllers/api/identity/emails_controller_test.rb.tt +0 -4
- data/lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt +0 -4
- data/lib/generators/authentication/templates/test_unit/controllers/api/sessions/sudos_controller_test.rb.tt +0 -4
- data/lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt +0 -4
- data/lib/generators/authentication/templates/test_unit/controllers/html/identity/email_verifications_controller_test.rb.tt +0 -4
- data/lib/generators/authentication/templates/test_unit/controllers/html/identity/emails_controller_test.rb.tt +0 -4
- data/lib/generators/authentication/templates/test_unit/controllers/html/passwords_controller_test.rb.tt +0 -4
- data/lib/generators/authentication/templates/test_unit/controllers/html/sessions/sudos_controller_test.rb.tt +0 -4
- data/lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt +0 -4
- data/lib/generators/authentication/templates/test_unit/system/identity/emails_test.rb.tt +0 -10
- data/lib/generators/authentication/templates/test_unit/system/passwords_test.rb.tt +0 -10
- data/lib/generators/authentication/templates/test_unit/system/sessions/sudos_test.rb.tt +0 -10
- data/lib/generators/authentication/templates/test_unit/system/sessions_test.rb.tt +4 -7
- data/lib/generators/authentication/templates/test_unit/test_helper.rb.tt +22 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8173a1510dfbe78180ce29cbb83b5f79b84b0ed4ecacf0569344905c28f2a01
|
4
|
+
data.tar.gz: 9d89bc1c96a4b59b7c7bf2437bd038036e747f4e78c0a7d5a81f1c0ae4c86f28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34a5ed73cbd7f5e35cd9a1e16ae0e4880a677ffa94f3892c0c6292abb436b3fded01c4664dd5e77d5b8025718b60ea8507bdbd968243d94ef191980615b02ea4
|
7
|
+
data.tar.gz: 2afb2c4fbc2bef0c7e06fab12cf783f04c6bc811d7150ed58f4a73f430c23925f4e790c6e3477729e04f2ade59b80dd30220667952d7b41cc98a4106fc4e064e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,6 +22,7 @@ The purpose of authentication zero is to generate a pre-built authentication sys
|
|
22
22
|
- Manage multiple sessions & devices
|
23
23
|
- Activity log (--trackable)
|
24
24
|
- Log out
|
25
|
+
- [API documentation](https://github.com/lazaronixon/authentication-zero/blob/master/authentication-zero-api.md)
|
25
26
|
|
26
27
|
## Security and best practices
|
27
28
|
|
@@ -74,6 +75,10 @@ Add these lines to your `app/views/home/index.html.erb`:
|
|
74
75
|
<%= link_to "Devices & Sessions", sessions_path %>
|
75
76
|
</div>
|
76
77
|
|
78
|
+
<div>
|
79
|
+
<%# link_to "Activity Log", authentications_events_path %>
|
80
|
+
</div>
|
81
|
+
|
77
82
|
<br>
|
78
83
|
|
79
84
|
<%= button_to "Log out", Current.session, method: :delete %>
|
@@ -0,0 +1,210 @@
|
|
1
|
+
# Authentication Zero API
|
2
|
+
|
3
|
+
This document describe the api endpoints available in authentication-zero.
|
4
|
+
|
5
|
+
## Making a request
|
6
|
+
|
7
|
+
To make a sign in request for example, append sign_in to the base URL to form something like http://localhost:3000/sign_in, also notice you have to include the Content-Type header and the JSON data: In cURL, it looks like this:
|
8
|
+
|
9
|
+
``` shell
|
10
|
+
curl -H "Authorization: Bearer $ACCESS_TOKEN" \
|
11
|
+
-H 'Content-Type: application/json' \
|
12
|
+
-H 'User-Agent: MyApp (yourname@example.com)' \
|
13
|
+
-d '{ "email": "lazaronixon@hotmail.com", "password": "secret", "password_confirmation": "secret" }' \
|
14
|
+
http://localhost:3000/sign_in
|
15
|
+
```
|
16
|
+
|
17
|
+
## API endpoints
|
18
|
+
|
19
|
+
- [Sign up](#sign-up)
|
20
|
+
- [Sign in](#sign-in)
|
21
|
+
- [Get your sessions](#get-your-sessions)
|
22
|
+
- [Get a session](#get-a-session)
|
23
|
+
- [Destroy a session](#destroy-a-session)
|
24
|
+
- [Execute sudo](#execute-sudo)
|
25
|
+
- [Update your password](#update-your-password)
|
26
|
+
- [Update your email](#update-your-email)
|
27
|
+
- [Send verification email](#send-verification-email)
|
28
|
+
- [Verify email](#verify-email)
|
29
|
+
- [Send password reset email](#send-password-reset-email)
|
30
|
+
- [Reset password](#reset-password)
|
31
|
+
|
32
|
+
## Registrations
|
33
|
+
|
34
|
+
### Sign up
|
35
|
+
|
36
|
+
* `POST /sign_up` creates a user on database.
|
37
|
+
|
38
|
+
###### Example JSON Request
|
39
|
+
|
40
|
+
``` json
|
41
|
+
{
|
42
|
+
"email": "lazaronixon@hotmail.com",
|
43
|
+
"password": "Secret1*2*3*4*5*6",
|
44
|
+
"password_confirmation": "Secret1*2*3*4*5*6"
|
45
|
+
}
|
46
|
+
```
|
47
|
+
|
48
|
+
This endpoint will return `201 Created` with the current JSON representation of the user if the creation was a success.
|
49
|
+
|
50
|
+
## Sessions
|
51
|
+
|
52
|
+
### Sign in
|
53
|
+
|
54
|
+
* `POST /sign_in` creates a session on database.
|
55
|
+
|
56
|
+
###### Example JSON Request
|
57
|
+
|
58
|
+
``` json
|
59
|
+
{
|
60
|
+
"email": "lazaronixon@hotmail.com",
|
61
|
+
"password": "Secret1*2*3*4*5*6"
|
62
|
+
}
|
63
|
+
```
|
64
|
+
|
65
|
+
This endpoint will return `201 Created` with the current JSON representation of the session if the creation was a success, also you will receive a `X-Session-Token` that you will use as your authorization token.
|
66
|
+
|
67
|
+
|
68
|
+
### Get your sessions
|
69
|
+
|
70
|
+
* `GET /sessions` will return a list of sessions.
|
71
|
+
|
72
|
+
###### Example JSON Response
|
73
|
+
|
74
|
+
``` json
|
75
|
+
[
|
76
|
+
{
|
77
|
+
"id": 2,
|
78
|
+
"user_id": 1,
|
79
|
+
"user_agent": "insomnia/2022.1.0",
|
80
|
+
"ip_address": "127.0.0.1",
|
81
|
+
"sudo_at": "2022-03-04T17:20:33.632Z",
|
82
|
+
"created_at": "2022-03-04T17:20:33.632Z",
|
83
|
+
"updated_at": "2022-03-04T17:20:33.632Z"
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"id": 1,
|
87
|
+
"user_id": 1,
|
88
|
+
"user_agent": "insomnia/2022.1.0",
|
89
|
+
"ip_address": "127.0.0.1",
|
90
|
+
"sudo_at": "2022-03-04T17:14:03.386Z",
|
91
|
+
"created_at": "2022-03-04T17:14:03.386Z",
|
92
|
+
"updated_at": "2022-03-04T17:14:03.386Z"
|
93
|
+
}
|
94
|
+
]
|
95
|
+
```
|
96
|
+
|
97
|
+
### Get a session
|
98
|
+
|
99
|
+
* `GET /sessions/1` will return the session with an ID of 1.
|
100
|
+
|
101
|
+
###### Example JSON Response
|
102
|
+
|
103
|
+
``` json
|
104
|
+
{
|
105
|
+
"id": 1,
|
106
|
+
"user_id": 1,
|
107
|
+
"user_agent": "insomnia/2022.1.0",
|
108
|
+
"ip_address": "127.0.0.1",
|
109
|
+
"sudo_at": "2022-03-04T17:14:03.386Z",
|
110
|
+
"created_at": "2022-03-04T17:14:03.386Z",
|
111
|
+
"updated_at": "2022-03-04T17:14:03.386Z"
|
112
|
+
}
|
113
|
+
```
|
114
|
+
|
115
|
+
### Destroy a session
|
116
|
+
|
117
|
+
* `DELETE /sessions/1` will destroy the session with an ID of 1.
|
118
|
+
|
119
|
+
Returns `204 No Content` if successful.
|
120
|
+
|
121
|
+
|
122
|
+
### Execute sudo
|
123
|
+
|
124
|
+
* `POST /sessions/sudo` will grant temporary access to sensitive information.
|
125
|
+
|
126
|
+
###### Example JSON Request
|
127
|
+
|
128
|
+
``` json
|
129
|
+
{
|
130
|
+
"password": "Secret1*2*3*4*5*6",
|
131
|
+
}
|
132
|
+
```
|
133
|
+
|
134
|
+
Returns `204 No Content` if successful.
|
135
|
+
|
136
|
+
## Password
|
137
|
+
|
138
|
+
### Update your password
|
139
|
+
|
140
|
+
* `PUT /password` allows changing your password.
|
141
|
+
|
142
|
+
###### Example JSON Request
|
143
|
+
|
144
|
+
``` json
|
145
|
+
{
|
146
|
+
"current_password": "Secret1*2*3*4*5*6",
|
147
|
+
"password": "NewPassword12$34$56$7",
|
148
|
+
"password_confirmation": "NewPassword12$34$56$7"
|
149
|
+
}
|
150
|
+
```
|
151
|
+
|
152
|
+
This endpoint will return 200 OK with the current JSON representation of the user if the update was a success.
|
153
|
+
|
154
|
+
## Email
|
155
|
+
|
156
|
+
### Update your email
|
157
|
+
|
158
|
+
* `PUT /identity/email` allows changing your email. **(requires sudo)**.
|
159
|
+
|
160
|
+
###### Example JSON Request
|
161
|
+
|
162
|
+
``` json
|
163
|
+
{
|
164
|
+
"email": "new_email@hey.com"
|
165
|
+
}
|
166
|
+
```
|
167
|
+
|
168
|
+
This endpoint will return 200 OK with the current JSON representation of the user if the update was a success.
|
169
|
+
|
170
|
+
## Email verification
|
171
|
+
|
172
|
+
### Send verification email
|
173
|
+
|
174
|
+
* `POST /identity/email_verification` sends an email verification with the instructions and link to proceed with the verification.
|
175
|
+
|
176
|
+
Returns `204 No Content` if successful.
|
177
|
+
|
178
|
+
### Verify email
|
179
|
+
|
180
|
+
* `GET /identity/email_verification` verify your email using a temporary token.
|
181
|
+
|
182
|
+
**Required parameters:** `email` and `token`.
|
183
|
+
|
184
|
+
Example: `/identity/email_verification?email=lazaronixon@hotmail.com&token=eyJfcmFpbHMiOnsibWVzc2FnZSI6Ik1nPT0iLCJleHAiOm51bGwsInB1ciI6InNlc3Npb24ifX0=--1a277b4a5576c6e371144a22476979a18d3e45fb8515a79e815cd4b95eb5fb6b`
|
185
|
+
|
186
|
+
Returns `204 No Content` if successful.
|
187
|
+
|
188
|
+
## Password reset
|
189
|
+
|
190
|
+
### Send password reset email
|
191
|
+
|
192
|
+
* `POST /identity/password_reset` sends a password reset email with the instructions and link to proceed reset.
|
193
|
+
|
194
|
+
Returns `204 No Content` if successful.
|
195
|
+
|
196
|
+
### Reset password
|
197
|
+
|
198
|
+
* `PUT /identity/password_reset` allows changing your password through a email token.
|
199
|
+
|
200
|
+
##### Example JSON Request
|
201
|
+
|
202
|
+
``` json
|
203
|
+
{
|
204
|
+
"password": "NewPassword12$34$56$7",
|
205
|
+
"password_confirmation": "NewPassword12$34$56$7",
|
206
|
+
"token": "eyJfcmFpbHMiOnsibWVzc2FnZSI6Ik1nPT0iLCJleHAiOm51bGwsInB1ciI6InNlc3Npb24ifX0=--1a277b4a5576c6e371144a22476979a18d3e45fb8515a79e815cd4b95eb5fb6b",
|
207
|
+
}
|
208
|
+
```
|
209
|
+
|
210
|
+
This endpoint will return 200 OK with the current JSON representation of the user if the update was a success.
|
@@ -32,12 +32,12 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def create_configuration_files
|
35
|
-
|
36
|
-
|
35
|
+
copy_file "config/redis/shared.yml", "config/redis/shared.yml" if options.lockable?
|
36
|
+
copy_file "config/initializers/omniauth.rb", "config/initializers/omniauth.rb" if omniauthable?
|
37
37
|
end
|
38
38
|
|
39
39
|
def add_environment_configurations
|
40
|
-
|
40
|
+
ratelimit_code = <<~CODE
|
41
41
|
# Rate limit general requests by IP address in a rate of 1000 requests per hour
|
42
42
|
config.middleware.use(Rack::Ratelimit, name: "General", rate: [1000, 1.hour], redis: Redis.new, logger: Rails.logger) { |env| ActionDispatch::Request.new(env).ip }
|
43
43
|
CODE
|
@@ -63,64 +63,9 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
63
63
|
template "test_unit/fixtures.yml", "test/fixtures/#{fixture_file_name}.yml"
|
64
64
|
end
|
65
65
|
|
66
|
-
def add_application_controller_methods
|
67
|
-
api_code = <<~CODE
|
68
|
-
include ActionController::HttpAuthentication::Token::ControllerMethods
|
69
|
-
|
70
|
-
before_action :set_current_request_details
|
71
|
-
before_action :authenticate
|
72
|
-
|
73
|
-
def require_sudo
|
74
|
-
if Current.session.sudo_at < 30.minutes.ago
|
75
|
-
render json: { error: "Enter your password to continue" }, status: :forbidden
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
def authenticate
|
81
|
-
if session = authenticate_with_http_token { |token, _| Session.find_signed(token) }
|
82
|
-
Current.session = session
|
83
|
-
else
|
84
|
-
request_http_token_authentication
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def set_current_request_details
|
89
|
-
Current.user_agent = request.user_agent
|
90
|
-
Current.ip_address = request.ip
|
91
|
-
end
|
92
|
-
CODE
|
93
|
-
|
94
|
-
html_code = <<~CODE
|
95
|
-
before_action :set_current_request_details
|
96
|
-
before_action :authenticate
|
97
|
-
|
98
|
-
def require_sudo
|
99
|
-
if Current.session.sudo_at < 30.minutes.ago
|
100
|
-
redirect_to new_sessions_sudo_path(proceed_to_url: request.url)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
def authenticate
|
106
|
-
if session = Session.find_by_id(cookies.signed[:session_token])
|
107
|
-
Current.session = session
|
108
|
-
else
|
109
|
-
redirect_to sign_in_path
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def set_current_request_details
|
114
|
-
Current.user_agent = request.user_agent
|
115
|
-
Current.ip_address = request.ip
|
116
|
-
end
|
117
|
-
CODE
|
118
|
-
|
119
|
-
inject_code = options.api? ? api_code : html_code
|
120
|
-
inject_into_class "app/controllers/application_controller.rb", "ApplicationController", optimize_indentation(inject_code, 2), verbose: false
|
121
|
-
end
|
122
|
-
|
123
66
|
def create_controllers
|
67
|
+
template "controllers/#{format_folder}/application_controller.rb", "app/controllers/application_controller.rb", force: true
|
68
|
+
|
124
69
|
directory "controllers/#{format_folder}/identity", "app/controllers/identity"
|
125
70
|
template "controllers/#{format_folder}/passwords_controller.rb", "app/controllers/passwords_controller.rb"
|
126
71
|
template "controllers/#{format_folder}/registrations_controller.rb", "app/controllers/registrations_controller.rb"
|
@@ -135,6 +80,9 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
135
80
|
directory "erb/identity_mailer", "app/views/identity_mailer"
|
136
81
|
directory "erb/session_mailer", "app/views/session_mailer"
|
137
82
|
else
|
83
|
+
directory "erb/identity_mailer", "app/views/identity_mailer"
|
84
|
+
directory "erb/session_mailer", "app/views/session_mailer"
|
85
|
+
|
138
86
|
directory "erb/identity", "app/views/identity"
|
139
87
|
directory "erb/passwords", "app/views/passwords"
|
140
88
|
directory "erb/registrations", "app/views/registrations"
|
@@ -150,29 +98,31 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
150
98
|
def add_routes
|
151
99
|
if omniauthable?
|
152
100
|
route "post '/auth/:provider/callback', to: 'sessions/omniauth#create'"
|
153
|
-
route "get
|
154
|
-
route "get
|
101
|
+
route "get '/auth/:provider/callback', to: 'sessions/omniauth#create'"
|
102
|
+
route "get '/auth/failure', to: 'sessions/omniauth#failure'"
|
155
103
|
end
|
156
104
|
|
157
105
|
if options.trackable?
|
158
106
|
route "resources :events, only: :index", namespace: :authentications
|
159
107
|
end
|
160
108
|
|
161
|
-
route "resource :password_reset,
|
109
|
+
route "resource :password_reset, only: [:new, :edit, :create, :update]", namespace: :identity
|
162
110
|
route "resource :email_verification, only: [:edit, :create]", namespace: :identity
|
163
|
-
route "resource :email,
|
111
|
+
route "resource :email, only: [:edit, :update]", namespace: :identity
|
164
112
|
route "resource :sudo, only: [:new, :create]", namespace: :sessions
|
113
|
+
route "resource :password, only: [:edit, :update]"
|
165
114
|
route "resources :sessions, only: [:index, :show, :destroy]"
|
166
|
-
route "resource :password, only: [:edit, :update]"
|
167
115
|
route "post 'sign_up', to: 'registrations#create'"
|
168
|
-
route "get
|
116
|
+
route "get 'sign_up', to: 'registrations#new'" unless options.api?
|
169
117
|
route "post 'sign_in', to: 'sessions#create'"
|
170
|
-
route "get
|
118
|
+
route "get 'sign_in', to: 'sessions#new'" unless options.api?
|
171
119
|
end
|
172
120
|
|
173
121
|
def create_test_files
|
174
122
|
directory "test_unit/controllers/#{format_folder}", "test/controllers"
|
175
123
|
directory "test_unit/system", "test/system" unless options.api?
|
124
|
+
template "test_unit/test_helper.rb", "test/test_helper.rb", force: true
|
125
|
+
template "test_unit/application_system_test_case.rb", "test/application_system_test_case.rb", force: true unless options.api?
|
176
126
|
end
|
177
127
|
|
178
128
|
private
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class ApplicationController < ActionController::API
|
2
|
+
include ActionController::HttpAuthentication::Token::ControllerMethods
|
3
|
+
|
4
|
+
before_action :set_current_request_details
|
5
|
+
before_action :authenticate
|
6
|
+
|
7
|
+
def require_sudo
|
8
|
+
if Current.session.sudo_at < 30.minutes.ago
|
9
|
+
render json: { error: "Enter your password to continue" }, status: :forbidden
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def authenticate
|
15
|
+
if session = authenticate_with_http_token { |token, _| Session.find_signed(token) }
|
16
|
+
Current.session = session
|
17
|
+
else
|
18
|
+
request_http_token_authentication
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_current_request_details
|
23
|
+
Current.user_agent = request.user_agent
|
24
|
+
Current.ip_address = request.ip
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
before_action :set_current_request_details
|
3
|
+
before_action :authenticate
|
4
|
+
|
5
|
+
def require_sudo
|
6
|
+
if Current.session.sudo_at < 30.minutes.ago
|
7
|
+
redirect_to new_sessions_sudo_path(proceed_to_url: request.url)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def authenticate
|
13
|
+
if session = Session.find_by_id(cookies.signed[:session_token])
|
14
|
+
Current.session = session
|
15
|
+
else
|
16
|
+
redirect_to sign_in_path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_current_request_details
|
21
|
+
Current.user_agent = request.user_agent
|
22
|
+
Current.ip_address = request.ip
|
23
|
+
end
|
24
|
+
end
|
@@ -17,13 +17,13 @@
|
|
17
17
|
|
18
18
|
<div>
|
19
19
|
<%%= form.label :password, "New password", style: "display: block" %>
|
20
|
-
<%%= form.password_field :password, autofocus: true, autocomplete: "new-password" %>
|
20
|
+
<%%= form.password_field :password, required: true, autofocus: true, autocomplete: "new-password" %>
|
21
21
|
<div>12 characters minimum.</div>
|
22
22
|
</div>
|
23
23
|
|
24
24
|
<div>
|
25
25
|
<%%= form.label :password_confirmation, "Confirm new password", style: "display: block" %>
|
26
|
-
<%%= form.password_field :password_confirmation, autocomplete: "new-password" %>
|
26
|
+
<%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password" %>
|
27
27
|
</div>
|
28
28
|
|
29
29
|
<div>
|
@@ -17,18 +17,18 @@
|
|
17
17
|
|
18
18
|
<div>
|
19
19
|
<%%= label_tag :current_password, nil, style: "display: block" %>
|
20
|
-
<%%= password_field_tag :current_password, nil, autofocus: true, autocomplete: "current-password" %>
|
20
|
+
<%%= password_field_tag :current_password, nil, required: true, autofocus: true, autocomplete: "current-password" %>
|
21
21
|
</div>
|
22
22
|
|
23
23
|
<div>
|
24
24
|
<%%= form.label :password, "New password", style: "display: block" %>
|
25
|
-
<%%= form.password_field :password, autocomplete: "new-password" %>
|
25
|
+
<%%= form.password_field :password, required: true, autocomplete: "new-password" %>
|
26
26
|
<div>12 characters minimum.</div>
|
27
27
|
</div>
|
28
28
|
|
29
29
|
<div>
|
30
30
|
<%%= form.label :password_confirmation, "Confirm new password", style: "display: block" %>
|
31
|
-
<%%= form.password_field :password_confirmation, autocomplete: "new-password" %>
|
31
|
+
<%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password" %>
|
32
32
|
</div>
|
33
33
|
|
34
34
|
<div>
|
@@ -20,13 +20,13 @@
|
|
20
20
|
|
21
21
|
<div>
|
22
22
|
<%%= form.label :password, style: "display: block" %>
|
23
|
-
<%%= form.password_field :password, autocomplete: "new-password" %>
|
23
|
+
<%%= form.password_field :password, required: true, autocomplete: "new-password" %>
|
24
24
|
<div>12 characters minimum.</div>
|
25
25
|
</div>
|
26
26
|
|
27
27
|
<div>
|
28
28
|
<%%= form.label :password_confirmation, style: "display: block" %>
|
29
|
-
<%%= form.password_field :password_confirmation, autocomplete: "new-password" %>
|
29
|
+
<%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password" %>
|
30
30
|
</div>
|
31
31
|
|
32
32
|
<div>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<%%= hidden_field_tag :proceed_to_url, params[:proceed_to_url] %>
|
8
8
|
|
9
9
|
<div>
|
10
|
-
<%%= password_field_tag :password, nil, autofocus: true, autocomplete: "current-password" %>
|
10
|
+
<%%= password_field_tag :password, nil, required: true, autofocus: true, autocomplete: "current-password" %>
|
11
11
|
</div>
|
12
12
|
|
13
13
|
<div>
|
@@ -9,8 +9,8 @@ class <%= class_name %> < ApplicationRecord
|
|
9
9
|
validates :email, presence: true, uniqueness: true
|
10
10
|
validates_format_of :email, with: /\A[^@\s]+@[^@\s]+\z/
|
11
11
|
|
12
|
-
validates_length_of :password, minimum: 12,
|
13
|
-
validates_format_of :password, with: /(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])/,
|
12
|
+
validates_length_of :password, minimum: 12, allow_nil: true
|
13
|
+
validates_format_of :password, with: /(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])/, allow_nil: true, message: "might easily be guessed"
|
14
14
|
<% if options.pwned? -%>
|
15
15
|
validates :password, not_pwned: { message: "might easily be guessed" }
|
16
16
|
<% end -%>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
4
|
+
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
|
5
|
+
|
6
|
+
def sign_in_as(<%= singular_table_name %>)
|
7
|
+
visit sign_in_url
|
8
|
+
fill_in :email, with: <%= singular_table_name %>.email
|
9
|
+
fill_in :password, with: "Secret1*3*5*"
|
10
|
+
click_on "Sign in"
|
11
|
+
|
12
|
+
assert_current_path root_url
|
13
|
+
return <%= singular_table_name %>
|
14
|
+
end
|
15
|
+
end
|
@@ -37,8 +37,4 @@ class Identity::EmailVerificationsControllerTest < ActionDispatch::IntegrationTe
|
|
37
37
|
assert_response :bad_request
|
38
38
|
assert_equal "That email verification link is invalid", response.parsed_body["error"]
|
39
39
|
end
|
40
|
-
|
41
|
-
def sign_in_as(<%= singular_table_name %>)
|
42
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
43
|
-
end
|
44
40
|
end
|
@@ -18,8 +18,4 @@ class Identity::EmailsControllerTest < ActionDispatch::IntegrationTest
|
|
18
18
|
assert_response :forbidden
|
19
19
|
assert_equal "Enter your password to continue", response.parsed_body["error"]
|
20
20
|
end
|
21
|
-
|
22
|
-
def sign_in_as(<%= singular_table_name %>)
|
23
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
24
|
-
end
|
25
21
|
end
|
@@ -16,8 +16,4 @@ class PasswordsControllerTest < ActionDispatch::IntegrationTest
|
|
16
16
|
assert_response :bad_request
|
17
17
|
assert_equal "The current password you entered is incorrect", response.parsed_body["error"]
|
18
18
|
end
|
19
|
-
|
20
|
-
def sign_in_as(<%= singular_table_name %>)
|
21
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
22
|
-
end
|
23
19
|
end
|
@@ -17,8 +17,4 @@ class Sessions::SudosControllerTest < ActionDispatch::IntegrationTest
|
|
17
17
|
assert_response :bad_request
|
18
18
|
assert_equal "The password you entered is incorrect", response.parsed_body["error"]
|
19
19
|
end
|
20
|
-
|
21
|
-
def sign_in_as(<%= singular_table_name %>)
|
22
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
23
|
-
end
|
24
20
|
end
|
@@ -31,8 +31,4 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest
|
|
31
31
|
delete session_url(@<%= singular_table_name %>.sessions.last), headers: { "Authorization" => "Bearer #{@token}" }
|
32
32
|
assert_response :no_content
|
33
33
|
end
|
34
|
-
|
35
|
-
def sign_in_as(<%= singular_table_name %>)
|
36
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
37
|
-
end
|
38
34
|
end
|
@@ -37,8 +37,4 @@ class Identity::EmailVerificationsControllerTest < ActionDispatch::IntegrationTe
|
|
37
37
|
assert_redirected_to edit_identity_email_url
|
38
38
|
assert_equal "That email verification link is invalid", flash[:alert]
|
39
39
|
end
|
40
|
-
|
41
|
-
def sign_in_as(<%= singular_table_name %>)
|
42
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); <%= singular_table_name %>
|
43
|
-
end
|
44
40
|
end
|
@@ -28,8 +28,4 @@ class Identity::EmailsControllerTest < ActionDispatch::IntegrationTest
|
|
28
28
|
patch identity_email_url, params: { email: "new_email@hey.com" }
|
29
29
|
assert_redirected_to new_sessions_sudo_url(proceed_to_url: identity_email_url)
|
30
30
|
end
|
31
|
-
|
32
|
-
def sign_in_as(<%= singular_table_name %>)
|
33
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); <%= singular_table_name %>
|
34
|
-
end
|
35
31
|
end
|
@@ -21,8 +21,4 @@ class PasswordsControllerTest < ActionDispatch::IntegrationTest
|
|
21
21
|
assert_redirected_to edit_password_url
|
22
22
|
assert_equal "The current password you entered is incorrect", flash[:alert]
|
23
23
|
end
|
24
|
-
|
25
|
-
def sign_in_as(<%= singular_table_name %>)
|
26
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); <%= singular_table_name %>
|
27
|
-
end
|
28
24
|
end
|
@@ -19,8 +19,4 @@ class Sessions::SudosControllerTest < ActionDispatch::IntegrationTest
|
|
19
19
|
post sessions_sudo_url, params: { password: "SecretWrong1*3", proceed_to_url: edit_password_url }
|
20
20
|
assert_redirected_to new_sessions_sudo_url(proceed_to_url: edit_password_url)
|
21
21
|
end
|
22
|
-
|
23
|
-
def sign_in_as(<%= singular_table_name %>)
|
24
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
25
|
-
end
|
26
22
|
end
|
@@ -45,8 +45,4 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest
|
|
45
45
|
follow_redirect!
|
46
46
|
assert_redirected_to sign_in_url
|
47
47
|
end
|
48
|
-
|
49
|
-
def sign_in_as(<%= singular_table_name %>)
|
50
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); <%= singular_table_name %>
|
51
|
-
end
|
52
48
|
end
|
@@ -22,14 +22,4 @@ class Identity::EmailsTest < ApplicationSystemTestCase
|
|
22
22
|
|
23
23
|
assert_text "We sent a verification email to your email address"
|
24
24
|
end
|
25
|
-
|
26
|
-
def sign_in_as(<%= singular_table_name %>)
|
27
|
-
visit sign_in_url
|
28
|
-
fill_in :email, with: <%= singular_table_name %>.email
|
29
|
-
fill_in :password, with: "Secret1*3*5*"
|
30
|
-
click_on "Sign in"
|
31
|
-
|
32
|
-
assert_current_path root_url
|
33
|
-
return <%= singular_table_name %>
|
34
|
-
end
|
35
25
|
end
|
@@ -15,14 +15,4 @@ class PasswordsTest < ApplicationSystemTestCase
|
|
15
15
|
|
16
16
|
assert_text "Your password has been changed"
|
17
17
|
end
|
18
|
-
|
19
|
-
def sign_in_as(<%= singular_table_name %>)
|
20
|
-
visit sign_in_url
|
21
|
-
fill_in :email, with: <%= singular_table_name %>.email
|
22
|
-
fill_in :password, with: "Secret1*3*5*"
|
23
|
-
click_on "Sign in"
|
24
|
-
|
25
|
-
assert_current_path root_url
|
26
|
-
return <%= singular_table_name %>
|
27
|
-
end
|
28
18
|
end
|
@@ -12,14 +12,4 @@ class Sessions::SudosTest < ApplicationSystemTestCase
|
|
12
12
|
|
13
13
|
assert_selector "h1", text: "Change your password"
|
14
14
|
end
|
15
|
-
|
16
|
-
def sign_in_as(<%= singular_table_name %>)
|
17
|
-
visit sign_in_url
|
18
|
-
fill_in :email, with: <%= singular_table_name %>.email
|
19
|
-
fill_in :password, with: "Secret1*3*5*"
|
20
|
-
click_on "Sign in"
|
21
|
-
|
22
|
-
assert_current_path root_url
|
23
|
-
return <%= singular_table_name %>
|
24
|
-
end
|
25
15
|
end
|
@@ -21,13 +21,10 @@ class SessionsTest < ApplicationSystemTestCase
|
|
21
21
|
assert_text "Signed in successfully"
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
fill_in :email, with: <%= singular_table_name %>.email
|
27
|
-
fill_in :password, with: "Secret1*3*5*"
|
28
|
-
click_on "Sign in"
|
24
|
+
test "signing out" do
|
25
|
+
sign_in_as @<%= singular_table_name %>
|
29
26
|
|
30
|
-
|
31
|
-
|
27
|
+
click_on "Log out"
|
28
|
+
assert_text "That session has been logged out"
|
32
29
|
end
|
33
30
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= "test"
|
2
|
+
require_relative "../config/environment"
|
3
|
+
require "rails/test_help"
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Run tests in parallel with specified workers
|
7
|
+
parallelize(workers: :number_of_processors)
|
8
|
+
|
9
|
+
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
10
|
+
fixtures :all
|
11
|
+
|
12
|
+
# Add more helper methods to be used by all tests here...
|
13
|
+
<% if options.api? -%>
|
14
|
+
def sign_in_as(<%= singular_table_name %>)
|
15
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
16
|
+
end
|
17
|
+
<% else -%>
|
18
|
+
def sign_in_as(<%= singular_table_name %>)
|
19
|
+
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }); <%= singular_table_name %>
|
20
|
+
end
|
21
|
+
<% end -%>
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authentication-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.9.
|
4
|
+
version: 2.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nixon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- LICENSE.txt
|
27
27
|
- README.md
|
28
28
|
- Rakefile
|
29
|
+
- authentication-zero-api.md
|
29
30
|
- authentication-zero.gemspec
|
30
31
|
- lib/authentication-zero.rb
|
31
32
|
- lib/authentication_zero.rb
|
@@ -34,6 +35,7 @@ files:
|
|
34
35
|
- lib/generators/authentication/authentication_generator.rb
|
35
36
|
- lib/generators/authentication/templates/config/initializers/omniauth.rb
|
36
37
|
- lib/generators/authentication/templates/config/redis/shared.yml
|
38
|
+
- lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
|
37
39
|
- lib/generators/authentication/templates/controllers/api/authentications/events_controller.rb.tt
|
38
40
|
- lib/generators/authentication/templates/controllers/api/identity/email_verifications_controller.rb.tt
|
39
41
|
- lib/generators/authentication/templates/controllers/api/identity/emails_controller.rb.tt
|
@@ -42,6 +44,7 @@ files:
|
|
42
44
|
- lib/generators/authentication/templates/controllers/api/registrations_controller.rb.tt
|
43
45
|
- lib/generators/authentication/templates/controllers/api/sessions/sudos_controller.rb.tt
|
44
46
|
- lib/generators/authentication/templates/controllers/api/sessions_controller.rb.tt
|
47
|
+
- lib/generators/authentication/templates/controllers/html/application_controller.rb.tt
|
45
48
|
- lib/generators/authentication/templates/controllers/html/authentications/events_controller.rb.tt
|
46
49
|
- lib/generators/authentication/templates/controllers/html/identity/email_verifications_controller.rb.tt
|
47
50
|
- lib/generators/authentication/templates/controllers/html/identity/emails_controller.rb.tt
|
@@ -76,6 +79,7 @@ files:
|
|
76
79
|
- lib/generators/authentication/templates/models/locking.rb.tt
|
77
80
|
- lib/generators/authentication/templates/models/model.rb.tt
|
78
81
|
- lib/generators/authentication/templates/models/session.rb.tt
|
82
|
+
- lib/generators/authentication/templates/test_unit/application_system_test_case.rb.tt
|
79
83
|
- lib/generators/authentication/templates/test_unit/controllers/api/identity/email_verifications_controller_test.rb.tt
|
80
84
|
- lib/generators/authentication/templates/test_unit/controllers/api/identity/emails_controller_test.rb.tt
|
81
85
|
- lib/generators/authentication/templates/test_unit/controllers/api/identity/password_resets_controller_test.rb.tt
|
@@ -97,6 +101,7 @@ files:
|
|
97
101
|
- lib/generators/authentication/templates/test_unit/system/registrations_test.rb.tt
|
98
102
|
- lib/generators/authentication/templates/test_unit/system/sessions/sudos_test.rb.tt
|
99
103
|
- lib/generators/authentication/templates/test_unit/system/sessions_test.rb.tt
|
104
|
+
- lib/generators/authentication/templates/test_unit/test_helper.rb.tt
|
100
105
|
homepage: https://github.com/lazaronixon/authentication-zero
|
101
106
|
licenses:
|
102
107
|
- MIT
|