authentication-zero 2.8.1 → 2.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (22) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +1 -1
  4. data/lib/authentication_zero/version.rb +1 -1
  5. data/lib/generators/authentication/authentication_generator.rb +11 -12
  6. data/lib/generators/authentication/templates/controllers/html/identity/emails_controller.rb.tt +1 -1
  7. data/lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt +1 -1
  8. data/lib/generators/authentication/templates/controllers/html/passwords_controller.rb.tt +1 -1
  9. data/lib/generators/authentication/templates/controllers/html/registrations_controller.rb.tt +1 -1
  10. data/lib/generators/authentication/templates/controllers/html/sessions/sudos_controller.rb.tt +1 -1
  11. data/lib/generators/authentication/templates/erb/identity/emails/edit.html.erb.tt +1 -1
  12. data/lib/generators/authentication/templates/erb/identity/password_resets/edit.html.erb.tt +1 -1
  13. data/lib/generators/authentication/templates/erb/passwords/edit.html.erb.tt +1 -1
  14. data/lib/generators/authentication/templates/erb/registrations/new.html.erb.tt +1 -1
  15. data/lib/generators/authentication/templates/erb/sessions/new.html.erb.tt +1 -1
  16. data/lib/generators/authentication/templates/migrations/create_table_migration.rb.tt +7 -0
  17. data/lib/generators/authentication/templates/test_unit/controllers/html/identity/emails_controller_test.rb.tt +2 -2
  18. data/lib/generators/authentication/templates/test_unit/controllers/html/identity/password_resets_controller_test.rb.tt +1 -1
  19. data/lib/generators/authentication/templates/test_unit/controllers/html/passwords_controller_test.rb.tt +2 -2
  20. data/lib/generators/authentication/templates/test_unit/controllers/html/registrations_controller_test.rb.tt +1 -1
  21. metadata +2 -3
  22. data/lib/generators/authentication/templates/migrations/add_omniauth_migration.rb.tt +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09e4e9fd6a0cb245624984f07b574c17264d6df4cdedd508372153d1d40a860e'
4
- data.tar.gz: 1f86f6ffc7590ec45d3b3e9d64cb4fe8042e763b73024adb396c492a92ba7578
3
+ metadata.gz: bfa3da3a6167d405cd7869b9cb90f7c61eee5ef1d03475d079d72362a3bedf04
4
+ data.tar.gz: 3775ac3bd3fb334134618c9cbc8b32c25a5a3940246a554592e74415383de72b
5
5
  SHA512:
6
- metadata.gz: 30975f47ce22d6d2ff68cfa17f79831295adfb0938eea4af111fa7d3bef0e7a1c2e35ca3918b8feb5ce874267ac8aae9e231fbcb5ca520b8c51f57da72a8ee30
7
- data.tar.gz: 8aee14ca37ef8bdc460ddce3c15f4b785f587625655940752ec23844ee44492ca3026f0eb3769a1468d28af9af653eaf1d2754870a54d45a22d6310e9e89ea0e
6
+ metadata.gz: 4b596006ad41a57e3c3e54d21393ae2ceae9b21b36a11666f0988b2d59bda944c499d599074ced369cedbdb5cde98fc831f97691a3274d3467596904a7f2022c
7
+ data.tar.gz: 7096373b36cf3c9dead056e3d0584f4e44eb97b6efa353e0b3a7f9399620eb59aa3c298e5016aef38138508c9e01d4d1c1e99d4918730e6f9d3eda0b8e035a6a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authentication-zero (2.8.1)
4
+ authentication-zero (2.8.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 (--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
@@ -1,3 +1,3 @@
1
1
  module AuthenticationZero
2
- VERSION = "2.8.1"
2
+ VERSION = "2.8.4"
3
3
  end
@@ -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, 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 :omniauth, type: :boolean, desc: "Add social login support"
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 omniauth?
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 omniauth?
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,6 @@ 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 omniauth?
51
50
  end
52
51
 
53
52
  def create_models
@@ -106,7 +105,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
106
105
 
107
106
  def create_controllers
108
107
  directory "controllers/#{format_folder}", "app/controllers"
109
- template "controllers/omniauth_controller.rb", "app/controllers/sessions/omniauth_controller.rb" if omniauth?
108
+ template "controllers/omniauth_controller.rb", "app/controllers/sessions/omniauth_controller.rb" if omniauthable?
110
109
  end
111
110
 
112
111
  def create_views
@@ -123,7 +122,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
123
122
  end
124
123
 
125
124
  def add_routes
126
- if omniauth?
125
+ if omniauthable?
127
126
  route "post '/auth/:provider/callback', to: 'sessions/omniauth#create'"
128
127
  route "get '/auth/:provider/callback', to: 'sessions/omniauth#create'"
129
128
  route "get '/auth/failure', to: 'sessions/omniauth#failure'"
@@ -151,7 +150,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
151
150
  options.api? ? "api" : "html"
152
151
  end
153
152
 
154
- def omniauth?
155
- options.omniauth? && !options.api?
153
+ def omniauthable?
154
+ options.omniauthable? && !options.api?
156
155
  end
157
156
  end
@@ -19,6 +19,6 @@ class Identity::EmailsController < ApplicationController
19
19
  end
20
20
 
21
21
  def <%= "#{singular_table_name}_params" %>
22
- params.require(:<%= singular_table_name %>).permit(:email)
22
+ params.permit(:email)
23
23
  end
24
24
  end
@@ -37,7 +37,7 @@ class Identity::PasswordResetsController < ApplicationController
37
37
  end
38
38
 
39
39
  def <%= "#{singular_table_name}_params" %>
40
- params.require(:<%= singular_table_name %>).permit(:password, :password_confirmation)
40
+ params.permit(:password, :password_confirmation)
41
41
  end
42
42
  <% if options.lockable? %>
43
43
  def require_locking
@@ -20,6 +20,6 @@ class PasswordsController < ApplicationController
20
20
  end
21
21
 
22
22
  def <%= "#{singular_table_name}_params" %>
23
- params.require(:<%= singular_table_name %>).permit(:password, :password_confirmation)
23
+ params.permit(:password, :password_confirmation)
24
24
  end
25
25
  end
@@ -20,7 +20,7 @@ class RegistrationsController < ApplicationController
20
20
 
21
21
  private
22
22
  def <%= "#{singular_table_name}_params" %>
23
- params.require(:<%= singular_table_name %>).permit(:email, :password, :password_confirmation)
23
+ params.permit(:email, :password, :password_confirmation)
24
24
  end
25
25
 
26
26
  def session_params
@@ -5,7 +5,7 @@ class Sessions::SudosController < ApplicationController
5
5
  def create
6
6
  session = Current.session
7
7
 
8
- <% if options.omniauth? -%>
8
+ <% if omniauthable? -%>
9
9
  if session.<%= singular_table_name %>.authenticate(params[:password]) || session.<%= singular_table_name %>.provider
10
10
  <% else -%>
11
11
  if session.<%= singular_table_name %>.authenticate(params[:password])
@@ -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(model: @<%= model_resource_name %>, url: identity_email_path) do |form| %>
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(model: @<%= model_resource_name %>, url: identity_password_reset_path) do |form| %>
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(model: @<%= model_resource_name %>, url: password_path) do |form| %>
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(model: @<%= model_resource_name %>, url: sign_up_path) do |form| %>
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>
@@ -18,7 +18,7 @@
18
18
  <%%= form.submit "Sign in" %>
19
19
  </div>
20
20
  <%% end %>
21
- <% if options.omniauth? %>
21
+ <% if omniauthable? %>
22
22
  <div>
23
23
  <%%= button_to "Sign in with OmniAuth", "/auth/developer", "data-turbo" => false %>
24
24
  </div>
@@ -5,10 +5,17 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
5
5
  t.string :password_digest, null: false
6
6
 
7
7
  t.boolean :verified, null: false, default: false
8
+ <% if omniauthable? %>
9
+ t.string :provide
10
+ t.string :uid
11
+ <% end -%>
8
12
 
9
13
  t.timestamps
10
14
  end
11
15
 
12
16
  add_index :<%= table_name %>, :email, unique: true
17
+ <% if omniauthable? -%>
18
+ add_index :<%= table_name %>, [:provider, :uid], unique: true
19
+ <% end -%>
13
20
  end
14
21
  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: { <%= singular_table_name %>: { email: "new_email@hey.com" } }
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: { <%= singular_table_name %>: { email: "new_email@hey.com" } }
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, <%= singular_table_name %>: { password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" } }
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*", <%= singular_table_name %>: { password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" } }
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", <%= singular_table_name %>: { password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" } }
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,7 +8,7 @@ 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: { <%= singular_table_name %>: { email: "lazaronixon@hey.com", password: "Secret1*3*5*", password_confirmation: "Secret1*3*5*" } }, headers: { "User-Agent" => "Firefox" }
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
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.1
4
+ version: 2.8.4
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-03 00:00:00.000000000 Z
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -65,7 +65,6 @@ files:
65
65
  - lib/generators/authentication/templates/erb/sessions/sudos/new.html.erb.tt
66
66
  - lib/generators/authentication/templates/mailers/identity_mailer.rb.tt
67
67
  - lib/generators/authentication/templates/mailers/session_mailer.rb.tt
68
- - lib/generators/authentication/templates/migrations/add_omniauth_migration.rb.tt
69
68
  - lib/generators/authentication/templates/migrations/create_sessions_migration.rb.tt
70
69
  - lib/generators/authentication/templates/migrations/create_table_migration.rb.tt
71
70
  - lib/generators/authentication/templates/models/current.rb.tt
@@ -1,8 +0,0 @@
1
- class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
- def change
3
- add_column :<%= table_name %>, :provider, :string
4
- add_column :<%= table_name %>, :uid, :string
5
- end
6
-
7
- add_index :<%= table_name %>, [:provider, :uid], unique: true
8
- end