authentication-zero 0.0.18 → 0.0.19

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: 5f48325c2122dac114a46a7949ba07ab7693872f198076dc7bcfae87b31441c1
4
- data.tar.gz: 4117615d796766e17a773707f2dba9616eaf1ca7a59c007c831431d9b09e18eb
3
+ metadata.gz: 4b1eabca1df60e043a1cc139cee3426a19c4a2bb494fcd2ceeb68875baecc126
4
+ data.tar.gz: ca697e2d442e566a3f3b5fe051ca03840756185edd963679636ad76eaac4f972
5
5
  SHA512:
6
- metadata.gz: a6c76a600c3a82bb51bdb638bc1d114aef80ed13b2a252af3fac6bd4e1cd05992004a9bb6ec33457cb56e0fa93a3f48209acfb5d9c41c1ca7f9542104166e01b
7
- data.tar.gz: 277192f60768925670f1580c13a0f593e27f92656987171818e09edff379b7571b88abcf0460ae9961477557bfe186e7b1a4e05e46c1ff24f760e2d0ff959301
6
+ metadata.gz: 9cc259932fe245e5031f48aafa8407ed190f04e56a884eef339cfe04b1f21394dcede01d945f601193783caca66d83404f58817ca50d375d52816061cc05b4f5
7
+ data.tar.gz: 97b372c3e3598d391d254c6b01819a17100475d108fc10f04b2c2d7d4074feb5a00c4703aebe031ccd0800df43344cee7a8c88601d24c0aceeb7150aeed48997
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authentication-zero (0.0.18)
4
+ authentication-zero (0.0.19)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -17,15 +17,15 @@ The purpose of authentication zero is to generate a pre-built authentication sys
17
17
 
18
18
  ## Security and best practices
19
19
 
20
- - [Current attributes](https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html): Abstract super class that provides a thread-isolated attributes singleton, which resets automatically before and after each request.
21
20
  - [has_secure_password](https://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html#method-i-has_secure_password): Adds methods to set and authenticate against a BCrypt password.
22
21
  - [has_secure_token](https://api.rubyonrails.org/classes/ActiveRecord/SecureToken/ClassMethods.html#method-i-has_secure_token): Adds methods to generate unique tokens.
22
+ - [encrypts](https://guides.rubyonrails.org/active_record_encryption.html) Encrypts the session_token on database so if an attacker gained access to your database, a snapshot of it, or your application logs, they wouldn't be able to make sense of the encrypted information.
23
+ - [httponly cookies](https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html): A cookie with the httponly attribute is inaccessible to the JavaScript, this precaution helps mitigate cross-site scripting (XSS) attacks.
23
24
  - [signed_id](https://api.rubyonrails.org/classes/ActiveRecord/SignedId.html): Returns a signed id that is tamper proof, so it's safe to send in an email or otherwise share with the outside world.
24
- - [Signed cookies](https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html): Returns a jar that'll automatically generate a signed representation of cookie value and verify it when reading from the cookie again.
25
- - [Http only cookies](https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html): A cookie with the httponly attribute is inaccessible to the JavaScript, this precaution helps mitigate cross-site scripting (XSS) attacks.
26
- - [Log filtering](https://guides.rubyonrails.org/action_controller_overview.html#log-filtering): Parameters 'token' and 'password' are marked [FILTERED] in the log.
25
+ - [Current Attributes](https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html): Abstract super class that provides a thread-isolated attributes singleton, which resets automatically before and after each request.
26
+ - [Log Filtering](https://guides.rubyonrails.org/action_controller_overview.html#log-filtering): Parameters 'token' and 'password' are marked [FILTERED] in the log.
27
27
  - [Callbacks](https://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html): We use callbacks to send emails after changing an email or password.
28
- - [Action mailer](https://api.rubyonrails.org/classes/ActionMailer/Base.html): Action Mailer allows you to send email from your application using a mailer model and views.
28
+ - [Action Mailer](https://api.rubyonrails.org/classes/ActionMailer/Base.html): Action Mailer allows you to send email from your application using a mailer model and views.
29
29
 
30
30
  ## Installation
31
31
 
@@ -38,6 +38,11 @@ gem "authentication-zero"
38
38
 
39
39
  Then run `bundle install`
40
40
 
41
+ You'll need to set up active record encryption, run the command below and follow the instructions.
42
+ ```
43
+ $ rails db:encryption:init
44
+ ```
45
+
41
46
  You'll need to set the root path in your routes.rb, for this example let's use the following:
42
47
 
43
48
  ```ruby
@@ -1,3 +1,3 @@
1
1
  module AuthenticationZero
2
- VERSION = "0.0.18"
2
+ VERSION = "0.0.19"
3
3
  end
@@ -59,7 +59,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
59
59
 
60
60
  private
61
61
  def authenticate
62
- if #{singular_table_name} = authenticate_with_http_token { |t, _| #{class_name}.find_signed_session_token(t) }
62
+ if #{singular_table_name} = authenticate_with_http_token { |t, _| #{class_name}.find_by_session_token(t) }
63
63
  Current.#{singular_table_name} = #{singular_table_name}
64
64
  else
65
65
  request_http_token_authentication
@@ -73,7 +73,7 @@ class AuthenticationGenerator < Rails::Generators::NamedBase
73
73
 
74
74
  private
75
75
  def authenticate
76
- if #{singular_table_name} = #{class_name}.find_by_session_token(cookies.signed[:session_token])
76
+ if #{singular_table_name} = #{class_name}.find_by_session_token(cookies[:session_token])
77
77
  Current.#{singular_table_name} = #{singular_table_name}
78
78
  else
79
79
  redirect_to sign_in_path, alert: "You need to sign in or sign up before continuing"
@@ -5,7 +5,7 @@ class SessionsController < ApplicationController
5
5
  @<%= singular_table_name %> = <%= class_name %>.find_by_email(params[:email])
6
6
 
7
7
  if @<%= singular_table_name %>.try(:authenticate, params[:password])
8
- render json: { session_token: @<%= singular_table_name %>.signed_session_token }
8
+ render json: { session_token: @<%= singular_table_name %>.session_token }
9
9
  else
10
10
  render json: { error: "Invalid email or password" }, status: :unauthorized
11
11
  end
@@ -9,7 +9,7 @@ class RegistrationsController < ApplicationController
9
9
  @<%= singular_table_name %> = <%= class_name %>.new(<%= "#{singular_table_name}_params" %>)
10
10
 
11
11
  if @<%= singular_table_name %>.save
12
- cookies.signed[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
12
+ cookies[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
13
13
  redirect_to root_path, notice: "Welcome! You have signed up successfully"
14
14
  else
15
15
  render :new, status: :unprocessable_entity
@@ -10,9 +10,9 @@ class SessionsController < ApplicationController
10
10
 
11
11
  if @<%= singular_table_name %>.try(:authenticate, params[:password])
12
12
  if params[:remember_me] == "1"
13
- cookies.signed.permanent[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
13
+ cookies.permanent[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
14
14
  else
15
- cookies.signed[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
15
+ cookies[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
16
16
  end
17
17
 
18
18
  redirect_to root_path, notice: "Signed in successfully"
@@ -2,6 +2,8 @@ class <%= class_name %> < ApplicationRecord
2
2
  has_secure_password :password
3
3
  has_secure_token :session_token
4
4
 
5
+ encrypts :session_token, deterministic: true
6
+
5
7
  validates :email, presence: true, uniqueness: true
6
8
  validates :email, format: { with: /\A[^@\s]+@[^@\s]+\z/ }
7
9
  validates_length_of :password, minimum: 8, allow_blank: true
@@ -21,15 +23,4 @@ class <%= class_name %> < ApplicationRecord
21
23
  PasswordMailer.with(<%= singular_table_name %>: self).changed.deliver_later
22
24
  end
23
25
  end
24
- <% if options.api? %>
25
- def signed_session_token
26
- self.class.signed_id_verifier.generate(session_token)
27
- end
28
-
29
- def self.find_signed_session_token(signed_session_token)
30
- if session_token = signed_id_verifier.verified(signed_session_token)
31
- find_by_session_token(session_token)
32
- end
33
- end
34
- <% end -%>
35
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authentication-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nixon