authenticatable 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 907a194f62507d83bdc23c1cee102bf5486544907b880637ca570fbfc55d7f78
4
- data.tar.gz: 88a89169c344fa7e23333e41cee068195ffcd0d295ec6709fdcf20a5255a9368
3
+ metadata.gz: 1414dc1c8d7fe94e26249b1cec20c7d86996ea16829009f46cb87997170a6a7e
4
+ data.tar.gz: a67cef5b6641aa31aa924a7d660a934cba001aad953367c9db4fa92c75097ccf
5
5
  SHA512:
6
- metadata.gz: 721cd0363327e1d76350df5bc14d9e2f668638b512b5fded8b999146d4a5ded469f3be10e591086b0224c12ce82afd37ea5943ae8095e5a330156a50f2848199
7
- data.tar.gz: f072a1baefee474141d1b002a59e872a4eef10b3d8e8058a035af5514bcd5e560d690bdff055b076f402eba5186b2c61247790ef8e04bf85e834d82a4532beae
6
+ metadata.gz: d543450bac7a6b03b392906d36f984c6541e6aeab78db0c511553ef963396fc72096bbf1c941d39ddd4b5c5b20eeaedca98c880f66db7194d2e7f6274f03fa5d
7
+ data.tar.gz: 9eefefb04397c1514872be68dd67ceb710dc6696f1550213481d2a8161f2bc3e862ff0636edf912b56598eb5b0f14be38fb31d004a6b3504e7401601e73b6d5c
data/README.md CHANGED
@@ -13,8 +13,8 @@ Authenticatable also ships with some **extra security features** that very often
13
13
  - Protection against [timing/enumeration attacks](https://www.kaspersky.com/blog/username-enumeration-attack/34618/) by hashing the password even if a user record isn't found.
14
14
 
15
15
  #### What's included?
16
- - Controllers and views for authentication & registration with support for both [turbo](https://github.com/hotwired/turbo-rails) and [turbolinks](https://github.com/turbolinks/turbolinks).
17
- - Support for multiple authenticatable models (like users/accounts/admins or whatever you want).
16
+ - Controllers and views for authentication, registration & reset password with support for both [turbo](https://github.com/hotwired/turbo-rails) and [turbolinks](https://github.com/turbolinks/turbolinks).
17
+ - Support for multiple user models (like users/accounts/admins or whatever you want).
18
18
  - Custom identifier column (sign in with for example username or phonenumber instead of email).
19
19
  - Customizable: Easily override default behaviors with your own.
20
20
 
@@ -27,17 +27,11 @@ Installation
27
27
  Add the following line to Gemfile:
28
28
 
29
29
  ```ruby
30
- gem "authenticatable", github: "kiqr/authenticatable" # Temporary use master as source before stable release.
30
+ gem "authenticatable", "~> 1.0"
31
31
  ```
32
32
 
33
33
  and run `bundle install` from your terminal to install it.
34
34
 
35
- After you've installed the gem, you can run the generator to create an initializer file that allows further configuration:
36
-
37
- ```console
38
- $ rails g authenticatable:install
39
- ```
40
-
41
35
  Getting started
42
36
  ---------------
43
37
 
@@ -74,7 +68,7 @@ To restrict your whole application to signed-in users, you can add the before_ac
74
68
 
75
69
  #### Handling Authenticatable::UnauthenticatedError
76
70
 
77
- The `Authenticatable::UnauthenticatedError` exception is raised when calling `:authenticate_user!` in the controller and no valid user is signed in. You can catch the exception and modify its behavior in the ApplicationController. The behavior may vary depending on the request format and user scope. For example here we set a flash error message and redirect to the sign in page for HTML requests and return 403 Forbidden for JSON requests.
71
+ The `Authenticatable::UnauthenticatedError` exception is raised when calling `:authenticate_user!` in the controller and no valid user is signed in. You can catch the exception and modify its behaviour in the ApplicationController. The behavior may vary depending on the request format and user scope. For example here we set a flash error message and redirect to the sign in page for HTML requests and return 403 Forbidden for JSON requests.
78
72
 
79
73
  ```ruby
80
74
  class ApplicationController < ActionController::Base
@@ -107,7 +101,7 @@ class User < ApplicationRecord
107
101
 
108
102
  # Identifying column to use when looking up an authenticatable record in the database.
109
103
  # Can be for example email or a username. Default is email.
110
- identifiy_by :username
104
+ identify_by :username
111
105
 
112
106
  # You need to create your own validator for your identifier column.
113
107
  validates_presence_of :username
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/concern"
4
- require "valid_email2"
5
4
 
6
5
  module Authenticatable
7
6
  module Models
@@ -27,9 +27,6 @@ module Authenticatable
27
27
  opts[:skip] = [opts[:skip]].flatten
28
28
  opts[:skip].each { |s| @authenticatable_extensions.delete(s) } if opts[:skip].present?
29
29
 
30
- # Load extensions into model
31
- load_core_mixins
32
-
33
30
  # Load extensions into model
34
31
  load_model_extensions
35
32
  end
@@ -54,14 +51,6 @@ module Authenticatable
54
51
  @authenticatable_loaded_extensions << module_name
55
52
  end
56
53
  end
57
-
58
- # Concerns that should be included to the authenticatable model if
59
- # initialized with the 'authenticatable'-method above.
60
- def load_core_mixins
61
- include Authenticatable::Models::EmailValidator
62
- include Authenticatable::Models::Identifier
63
- include Authenticatable::Models::Password
64
- end
65
54
  end
66
55
  end
67
56
  end
@@ -2,7 +2,9 @@
2
2
 
3
3
  require "rspec/rails"
4
4
  require "authenticatable/testing/controller_helpers"
5
+ require "authenticatable/testing/request_helpers"
5
6
 
6
7
  RSpec.configure do |config|
7
8
  config.include Authenticatable::Testing::ControllerHelpers, type: :controller
9
+ config.include Authenticatable::Testing::RequestHelpers, type: :request
8
10
  end
@@ -16,6 +16,8 @@ module Authenticatable
16
16
  # Usage:
17
17
  # serializer.store(@resource)
18
18
  def store(id)
19
+ delete_csrf_token
20
+ renew_session_id
19
21
  request.session[session_key] = id
20
22
  end
21
23
 
@@ -28,6 +30,19 @@ module Authenticatable
28
30
 
29
31
  private
30
32
 
33
+ # Protection against sessions fixation attacks by clearing the session_id on authentication.
34
+ def renew_session_id
35
+ return if request.env["rack.session.options"].blank?
36
+
37
+ request.env["rack.session.options"][:renew] = true
38
+ end
39
+
40
+ # Protect against cross-site request forgery (CSRF) by cleaning up the CSRF Token on authentication.
41
+ def delete_csrf_token
42
+ request.session.delete("_csrf_token")
43
+ end
44
+
45
+ # Returns the session key for a scoped authenticatable session.
31
46
  def session_key
32
47
  :"authenticatable_#{@scope}_id"
33
48
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Authenticatable
4
+ module Testing
5
+ module RequestHelpers
6
+ def sign_in(resource, resource_name = "user", path = "/users/sign_in")
7
+ post path, params: { "#{resource_name}": {
8
+ email: resource.email,
9
+ password: resource.password
10
+ } }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Authenticatable
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -35,7 +35,7 @@ module Authenticatable
35
35
  # includes a Warden Strategy for authentication with password. It does also
36
36
  # add password validations to your authenticatable model.
37
37
  #
38
- setting :default_extensions, %i[password]
38
+ setting :default_extensions, %i[identifier password email_validator]
39
39
 
40
40
  # Default column to use when looking up an authenticatable record in the database.
41
41
  # Can be for example email or a username. Default is :email. This can also be changed
@@ -46,6 +46,9 @@ module Authenticatable
46
46
  #
47
47
  setting :default_identifier, :email
48
48
 
49
+ # Set the default user scope
50
+ setting :default_scope, :user
51
+
49
52
  # The controller class that all Authenticatable controllers will inherit from.
50
53
  # Defaults to `ApplicationController`.
51
54
  setting :parent_controller, "ApplicationController"
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authenticatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rasmus Kjellberg
8
8
  - KIQR
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-10-02 00:00:00.000000000 Z
12
+ date: 2021-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bcrypt
@@ -39,21 +39,7 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.11.0
42
- - !ruby/object:Gem::Dependency
43
- name: valid_email2
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: 4.0.0
49
- type: :runtime
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: 4.0.0
56
- description:
42
+ description:
57
43
  email: hello@kiqr.dev
58
44
  executables: []
59
45
  extensions: []
@@ -99,6 +85,7 @@ files:
99
85
  - lib/authenticatable/serializers/base.rb
100
86
  - lib/authenticatable/serializers/session.rb
101
87
  - lib/authenticatable/testing/controller_helpers.rb
88
+ - lib/authenticatable/testing/request_helpers.rb
102
89
  - lib/authenticatable/token.rb
103
90
  - lib/authenticatable/version.rb
104
91
  - lib/generators/active_record/authenticatable_generator.rb
@@ -114,7 +101,7 @@ metadata:
114
101
  bug_tracker_uri: https://github.com/kiqr/authenticatable/issues
115
102
  documentation_uri: https://github.com/kiqr/authenticatable/issues
116
103
  source_code_uri: https://github.com/kiqr/authenticatable
117
- post_install_message:
104
+ post_install_message:
118
105
  rdoc_options: []
119
106
  require_paths:
120
107
  - lib
@@ -129,8 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
116
  - !ruby/object:Gem::Version
130
117
  version: '0'
131
118
  requirements: []
132
- rubygems_version: 3.2.26
133
- signing_key:
119
+ rubygems_version: 3.2.3
120
+ signing_key:
134
121
  specification_version: 4
135
122
  summary: Authentication solution for Ruby on Rails
136
123
  test_files: []