authentication-zero 2.8.0 → 2.8.3
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/Gemfile.lock +1 -1
- data/README.md +3 -8
- data/lib/authentication_zero/version.rb +1 -1
- data/lib/generators/authentication/authentication_generator.rb +12 -13
- data/lib/generators/authentication/templates/controllers/api/registrations_controller.rb.tt +1 -5
- data/lib/generators/authentication/templates/controllers/html/identity/emails_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/controllers/html/passwords_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/controllers/html/registrations_controller.rb.tt +2 -6
- data/lib/generators/authentication/templates/erb/identity/emails/edit.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/erb/identity/password_resets/edit.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/erb/passwords/edit.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/erb/registrations/new.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/test_unit/controllers/api/registrations_controller_test.rb.tt +0 -14
- data/lib/generators/authentication/templates/test_unit/controllers/html/identity/emails_controller_test.rb.tt +2 -2
- data/lib/generators/authentication/templates/test_unit/controllers/html/identity/password_resets_controller_test.rb.tt +1 -1
- data/lib/generators/authentication/templates/test_unit/controllers/html/passwords_controller_test.rb.tt +2 -2
- data/lib/generators/authentication/templates/test_unit/controllers/html/registrations_controller_test.rb.tt +1 -15
- data/lib/generators/authentication/templates/test_unit/system/registrations_test.rb.tt +0 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c761cc8c78b6706041724ca6313bb115f8263036a5d4ea94e50ea30c8928ebc
|
4
|
+
data.tar.gz: d9488244decbc2fbd95e4d46b6847d34b701b3f023c6bb37c26da19a67a7ab19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a09fd156b599aba36c0e27d6c96e07779fde672da91b2db7541d12ea2395f581114569f8036cd18cdf6a062d68b9cabacb543b76a5885aa4121a79768495831
|
7
|
+
data.tar.gz: bbdcd461f3effa96d83ffb631defa701eb4b174bc3ada9ce6782e906b136ed2c7d45f8f5c2b56b80d8caa95326f5fbcfa637759c44b3a731c356b3adef56b819
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ The purpose of authentication zero is to generate a pre-built authentication sys
|
|
11
11
|
- Checks if a password has been found in any data breach (--pwned)
|
12
12
|
- Authentication by cookie
|
13
13
|
- Authentication by token (--api)
|
14
|
-
- Social Login with OmniAuth (--
|
14
|
+
- Social Login with OmniAuth (--omniauthable)
|
15
15
|
- Ask password before sensitive data changes, aka: sudo
|
16
16
|
- Reset the user password and send reset instructions
|
17
17
|
- Reset the user password only from verified emails
|
@@ -20,7 +20,6 @@ The purpose of authentication zero is to generate a pre-built authentication sys
|
|
20
20
|
- Send e-mail confirmation when your email has been changed
|
21
21
|
- Send e-mail notification when someone has logged into your account
|
22
22
|
- Manage multiple sessions & devices
|
23
|
-
- Cancel my account
|
24
23
|
- Log out
|
25
24
|
|
26
25
|
## Security and best practices
|
@@ -62,20 +61,16 @@ Add these lines to your `app/views/home/index.html.erb`:
|
|
62
61
|
|
63
62
|
<p>Signed as <%= Current.user.email %></p>
|
64
63
|
|
65
|
-
<div>
|
66
|
-
<%= link_to "Change password", edit_password_path %>
|
67
|
-
</div>
|
68
|
-
|
69
64
|
<div>
|
70
65
|
<%= link_to "Change email address", edit_identity_email_path %>
|
71
66
|
</div>
|
72
67
|
|
73
68
|
<div>
|
74
|
-
<%= link_to "
|
69
|
+
<%= link_to "Change password", edit_password_path %>
|
75
70
|
</div>
|
76
71
|
|
77
72
|
<div>
|
78
|
-
<%=
|
73
|
+
<%= link_to "Devices & Sessions", sessions_path %>
|
79
74
|
</div>
|
80
75
|
|
81
76
|
<br>
|
@@ -3,11 +3,11 @@ require "rails/generators/active_record"
|
|
3
3
|
class AuthenticationGenerator < Rails::Generators::NamedBase
|
4
4
|
include ActiveRecord::Generators::Migration
|
5
5
|
|
6
|
-
class_option :api,
|
7
|
-
class_option :pwned,
|
8
|
-
class_option :lockable,
|
9
|
-
class_option :ratelimit,
|
10
|
-
class_option :
|
6
|
+
class_option :api, type: :boolean, desc: "Generates API authentication"
|
7
|
+
class_option :pwned, type: :boolean, desc: "Add pwned password validation"
|
8
|
+
class_option :lockable, type: :boolean, desc: "Add password reset locking"
|
9
|
+
class_option :ratelimit, type: :boolean, desc: "Add request rate limiting"
|
10
|
+
class_option :omniauthable, type: :boolean, desc: "Add social login support"
|
11
11
|
|
12
12
|
source_root File.expand_path("templates", __dir__)
|
13
13
|
|
@@ -24,7 +24,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
24
24
|
gem "rack-ratelimit", group: :production, comment: "Use Rack::Ratelimit to rate limit requests [https://github.com/jeremy/rack-ratelimit]"
|
25
25
|
end
|
26
26
|
|
27
|
-
if
|
27
|
+
if omniauthable?
|
28
28
|
gem "omniauth", comment: "Use OmniAuth to support multi-provider authentication [https://github.com/omniauth/omniauth]"
|
29
29
|
gem "omniauth-rails_csrf_protection", comment: "Provides a mitigation against CVE-2015-9284 [https://github.com/cookpad/omniauth-rails_csrf_protection]"
|
30
30
|
end
|
@@ -32,7 +32,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
32
32
|
|
33
33
|
def create_configuration_files
|
34
34
|
copy_file "config/redis/shared.yml", "config/redis/shared.yml" if options.lockable?
|
35
|
-
copy_file "config/initializers/omniauth.rb", "config/initializers/omniauth.rb" if
|
35
|
+
copy_file "config/initializers/omniauth.rb", "config/initializers/omniauth.rb" if omniauthable?
|
36
36
|
end
|
37
37
|
|
38
38
|
def add_environment_configurations
|
@@ -47,7 +47,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
47
47
|
def create_migrations
|
48
48
|
migration_template "migrations/create_table_migration.rb", "#{db_migrate_path}/create_#{table_name}.rb"
|
49
49
|
migration_template "migrations/create_sessions_migration.rb", "#{db_migrate_path}/create_sessions.rb"
|
50
|
-
migration_template "migrations/add_omniauth_migration.rb", "#{db_migrate_path}/add_omniauth_to_#{table_name}.rb" if
|
50
|
+
migration_template "migrations/add_omniauth_migration.rb", "#{db_migrate_path}/add_omniauth_to_#{table_name}.rb" if omniauthable?
|
51
51
|
end
|
52
52
|
|
53
53
|
def create_models
|
@@ -106,7 +106,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
106
106
|
|
107
107
|
def create_controllers
|
108
108
|
directory "controllers/#{format_folder}", "app/controllers"
|
109
|
-
template "controllers/omniauth_controller.rb", "app/controllers/sessions/omniauth_controller.rb" if
|
109
|
+
template "controllers/omniauth_controller.rb", "app/controllers/sessions/omniauth_controller.rb" if omniauthable?
|
110
110
|
end
|
111
111
|
|
112
112
|
def create_views
|
@@ -123,7 +123,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def add_routes
|
126
|
-
if
|
126
|
+
if omniauthable?
|
127
127
|
route "post '/auth/:provider/callback', to: 'sessions/omniauth#create'"
|
128
128
|
route "get '/auth/:provider/callback', to: 'sessions/omniauth#create'"
|
129
129
|
route "get '/auth/failure', to: 'sessions/omniauth#failure'"
|
@@ -135,7 +135,6 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
135
135
|
route "resource :sudo, only: [:new, :create]", namespace: :sessions
|
136
136
|
route "resources :sessions, only: [:index, :show, :destroy]"
|
137
137
|
route "resource :password, only: [:edit, :update]"
|
138
|
-
route "resource :registration, only: :destroy"
|
139
138
|
route "post 'sign_up', to: 'registrations#create'"
|
140
139
|
route "get 'sign_up', to: 'registrations#new'" unless options.api?
|
141
140
|
route "post 'sign_in', to: 'sessions#create'"
|
@@ -152,7 +151,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
|
|
152
151
|
options.api? ? "api" : "html"
|
153
152
|
end
|
154
153
|
|
155
|
-
def
|
156
|
-
options.
|
154
|
+
def omniauthable?
|
155
|
+
options.omniauthable? && !options.api?
|
157
156
|
end
|
158
157
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class RegistrationsController < ApplicationController
|
2
|
-
skip_before_action :authenticate
|
2
|
+
skip_before_action :authenticate
|
3
3
|
|
4
4
|
def create
|
5
5
|
@<%= singular_table_name %> = <%= class_name %>.new(<%= "#{singular_table_name}_params" %>)
|
@@ -11,10 +11,6 @@ class RegistrationsController < ApplicationController
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def destroy
|
15
|
-
Current.<%= singular_table_name %>.destroy
|
16
|
-
end
|
17
|
-
|
18
14
|
private
|
19
15
|
def <%= "#{singular_table_name}_params" %>
|
20
16
|
params.permit(:email, :password, :password_confirmation)
|
@@ -37,7 +37,7 @@ class Identity::PasswordResetsController < ApplicationController
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def <%= "#{singular_table_name}_params" %>
|
40
|
-
params.
|
40
|
+
params.permit(:password, :password_confirmation)
|
41
41
|
end
|
42
42
|
<% if options.lockable? %>
|
43
43
|
def require_locking
|
data/lib/generators/authentication/templates/controllers/html/registrations_controller.rb.tt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class RegistrationsController < ApplicationController
|
2
|
-
skip_before_action :authenticate
|
2
|
+
skip_before_action :authenticate
|
3
3
|
|
4
4
|
def new
|
5
5
|
@<%= singular_table_name %> = <%= class_name %>.new
|
@@ -18,13 +18,9 @@ class RegistrationsController < ApplicationController
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def destroy
|
22
|
-
Current.<%= singular_table_name %>.destroy; redirect_to(sign_in_path, notice: "Your account is closed")
|
23
|
-
end
|
24
|
-
|
25
21
|
private
|
26
22
|
def <%= "#{singular_table_name}_params" %>
|
27
|
-
params.
|
23
|
+
params.permit(:email, :password, :password_confirmation)
|
28
24
|
end
|
29
25
|
|
30
26
|
def session_params
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<p><%%= button_to "Re-send verification email", identity_email_verification_path %></p>
|
9
9
|
<%% end %>
|
10
10
|
|
11
|
-
<%%= form_with(
|
11
|
+
<%%= form_with(url: identity_email_path, method: :patch) do |form| %>
|
12
12
|
<%% if @<%= singular_table_name %>.errors.any? %>
|
13
13
|
<div style="color: red">
|
14
14
|
<h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<h1>Reset your password</h1>
|
2
2
|
|
3
|
-
<%%= form_with(
|
3
|
+
<%%= form_with(url: identity_password_reset_path, method: :patch) do |form| %>
|
4
4
|
<%% if @<%= singular_table_name %>.errors.any? %>
|
5
5
|
<div style="color: red">
|
6
6
|
<h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
<h1>Change your password</h1>
|
4
4
|
|
5
|
-
<%%= form_with(
|
5
|
+
<%%= form_with(url: password_path, method: :patch) do |form| %>
|
6
6
|
<%% if @<%= singular_table_name %>.errors.any? %>
|
7
7
|
<div style="color: red">
|
8
8
|
<h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<h1>Sign up</h1>
|
2
2
|
|
3
|
-
<%%= form_with(
|
3
|
+
<%%= form_with(url: sign_up_path) do |form| %>
|
4
4
|
<%% if @<%= singular_table_name %>.errors.any? %>
|
5
5
|
<div style="color: red">
|
6
6
|
<h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
|
@@ -8,18 +8,4 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
|
8
8
|
|
9
9
|
assert_response :created
|
10
10
|
end
|
11
|
-
|
12
|
-
test "should destroy account" do
|
13
|
-
@<%= singular_table_name %>, @token = sign_in_as(<%= table_name %>(:lazaro_nixon))
|
14
|
-
|
15
|
-
assert_difference("<%= class_name %>.count", -1) do
|
16
|
-
delete registration_url, headers: { "Authorization" => "Bearer #{@token}" }
|
17
|
-
end
|
18
|
-
|
19
|
-
assert_response :no_content
|
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*" }, headers: { "User-Agent" => "App iOS" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
|
24
|
-
end
|
25
11
|
end
|
@@ -18,14 +18,14 @@ class Identity::EmailsControllerTest < ActionDispatch::IntegrationTest
|
|
18
18
|
end
|
19
19
|
|
20
20
|
test "should update email" do
|
21
|
-
patch identity_email_url, params: {
|
21
|
+
patch identity_email_url, params: { email: "new_email@hey.com" }
|
22
22
|
assert_redirected_to root_url
|
23
23
|
end
|
24
24
|
|
25
25
|
test "should not update email without sudo" do
|
26
26
|
@<%= singular_table_name %>.sessions.last.update! sudo_at: 1.day.ago
|
27
27
|
|
28
|
-
patch identity_email_url, params: {
|
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
31
|
|
@@ -49,7 +49,7 @@ class Identity::PasswordResetsControllerTest < ActionDispatch::IntegrationTest
|
|
49
49
|
end
|
50
50
|
|
51
51
|
test "should update password" do
|
52
|
-
patch identity_password_reset_url, params: { token: @sid,
|
52
|
+
patch identity_password_reset_url, params: { token: @sid, password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" }
|
53
53
|
assert_redirected_to sign_in_url
|
54
54
|
end
|
55
55
|
|
@@ -11,12 +11,12 @@ class PasswordsControllerTest < ActionDispatch::IntegrationTest
|
|
11
11
|
end
|
12
12
|
|
13
13
|
test "should update password" do
|
14
|
-
patch password_url, params: { current_password: "Secret1*3*5*",
|
14
|
+
patch password_url, params: { current_password: "Secret1*3*5*", password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" }
|
15
15
|
assert_redirected_to root_url
|
16
16
|
end
|
17
17
|
|
18
18
|
test "should not update password with wrong current password" do
|
19
|
-
patch password_url, params: { current_password: "SecretWrong1*3",
|
19
|
+
patch password_url, params: { current_password: "SecretWrong1*3", password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" }
|
20
20
|
|
21
21
|
assert_redirected_to edit_password_url
|
22
22
|
assert_equal "The current password you entered is incorrect", flash[:alert]
|
@@ -8,23 +8,9 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
|
8
8
|
|
9
9
|
test "should sign up" do
|
10
10
|
assert_difference("<%= class_name %>.count") do
|
11
|
-
post sign_up_url, params: {
|
11
|
+
post sign_up_url, params: { email: "lazaronixon@hey.com", password: "Secret1*3*5*", password_confirmation: "Secret1*3*5*" }, headers: { "User-Agent" => "Firefox" }
|
12
12
|
end
|
13
13
|
|
14
14
|
assert_redirected_to root_url
|
15
15
|
end
|
16
|
-
|
17
|
-
test "should destroy account" do
|
18
|
-
sign_in_as <%= table_name %>(:lazaro_nixon)
|
19
|
-
|
20
|
-
assert_difference("<%= class_name %>.count", -1) do
|
21
|
-
delete registration_url
|
22
|
-
end
|
23
|
-
|
24
|
-
assert_redirected_to sign_in_url
|
25
|
-
end
|
26
|
-
|
27
|
-
def sign_in_as(<%= singular_table_name %>)
|
28
|
-
post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret1*3*5*" }, headers: { "User-Agent" => "Firefox" }); <%= singular_table_name %>
|
29
|
-
end
|
30
16
|
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
require "application_system_test_case"
|
2
2
|
|
3
3
|
class RegistrationsTest < ApplicationSystemTestCase
|
4
|
-
setup do
|
5
|
-
@<%= singular_table_name %> = <%= table_name %>(:lazaro_nixon)
|
6
|
-
end
|
7
|
-
|
8
4
|
test "signing up" do
|
9
5
|
visit sign_up_url
|
10
6
|
|
@@ -15,21 +11,4 @@ class RegistrationsTest < ApplicationSystemTestCase
|
|
15
11
|
|
16
12
|
assert_text "Welcome! You have signed up successfully"
|
17
13
|
end
|
18
|
-
|
19
|
-
test "cancelling my account" do
|
20
|
-
sign_in_as @<%= singular_table_name %>
|
21
|
-
|
22
|
-
click_on "Cancel my account & delete my data"
|
23
|
-
assert_text "Your account is closed"
|
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
14
|
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.8.
|
4
|
+
version: 2.8.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-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|