nyauth 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/controllers/concerns/nyauth/client_concern.rb +1 -0
  4. data/app/controllers/concerns/nyauth/session_concern.rb +13 -2
  5. data/app/controllers/nyauth/base_controller.rb +7 -0
  6. data/app/controllers/nyauth/confirmation_requests_controller.rb +2 -3
  7. data/app/controllers/nyauth/confirmations_controller.rb +2 -3
  8. data/app/controllers/nyauth/passwords_controller.rb +1 -5
  9. data/app/controllers/nyauth/registrations_controller.rb +1 -4
  10. data/app/controllers/nyauth/reset_password_requests_controller.rb +1 -4
  11. data/app/controllers/nyauth/reset_passwords_controller.rb +1 -4
  12. data/app/controllers/nyauth/sessions_controller.rb +2 -5
  13. data/app/helpers/nyauth/application_helper.rb +4 -0
  14. data/app/models/concerns/nyauth/authenticatable.rb +1 -1
  15. data/lib/generators/nyauth/templates/nyauth_install_initializer.rb +1 -0
  16. data/lib/nyauth/configuration.rb +3 -1
  17. data/lib/nyauth/middleware.rb +1 -0
  18. data/lib/nyauth/nyan.rb +1 -0
  19. data/lib/nyauth/session_serializer.rb +2 -1
  20. data/lib/nyauth/version.rb +1 -1
  21. data/spec/dummy/config/initializers/nyauth.rb +1 -0
  22. data/spec/dummy/db/test.sqlite3 +0 -0
  23. data/spec/dummy/log/development.log +1279 -0
  24. data/spec/dummy/log/test.log +5024 -0
  25. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/1SgsiPCC0_OqwmFFIeO-NDjvo5Cj0FU348WFcY_2j6c.cache +1 -0
  26. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/2NBqGhntP-vkXcqELAsDTzmnheGw93xJN_VGA0pgaRE.cache +2 -0
  27. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +2 -0
  28. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/9i_17ApHgLHXHlwXbU9QEfNrNMgVPjAoAk0EfGS-cWw.cache +1 -0
  29. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/CNXGLOU1u3FFzGFDMg_4iNcdCDd2iAmoOaiRROni8Tk.cache +2 -0
  30. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/IWK3eA3Xg7xhMT1dZKZVm3upMCwIJ0SQ9OSvgr5EQSQ.cache +1 -0
  31. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/M-01bce3-wk7ejaA8vPEwUWCLHoDDBrUXjHsxjmvj5M.cache +0 -0
  32. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/M7oa-ssP0ThBOv3o2FcsdNgXY3vxnpfs-rW3tIOkwkU.cache +2 -0
  33. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/MjbfHEk5fL4HFRCXVVkwYMHu5guRcO-FGLFU485dMV8.cache +0 -0
  34. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/NeJ0a8W4OrDx7L-0PPkc484TRX7ReOk8iMHFUA96r8c.cache +1 -0
  35. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +3 -0
  36. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/PefL8G86ueryC3XcvIG9eI1OB29lP3VNB-BdcF-kisA.cache +1 -0
  37. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/RDcmknHrxZY-Yz12bLt6TFfj9Wn_F4np3vZaysEl0nQ.cache +1 -0
  38. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/TCPOmqTgyNFovZmHXHUPPumf8jHDXCMHIu91bxyq_qM.cache +1 -0
  39. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/TbwAyWIHAKNshn19Q4B2Ukz3T5mduRykZjm3fove1I0.cache +0 -0
  40. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/cD-xX85wEbUx0FzXhj4CwiGLwYA65KFOABy8pO7xa2s.cache +0 -0
  41. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/jd_OAtZU3_tKwIEXznG0fpajbw6aSC6FZbPI4_OI3Qs.cache +1 -0
  42. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/q67E19uacbtvHmcq693Fj-LzCJhNHm5-fXCKhuCOqos.cache +0 -0
  43. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/qNepDmbIi_nFZX0KJF-zUvTl9CohiLBxTD-P97k1Cs4.cache +1 -0
  44. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/rZS2dSuZR3CGbChyMtQnJmfrHS-eYItGdlz8HLRVRP4.cache +0 -0
  45. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/t1OSyz8ZOkqn7HP_G1--JL_iLGWUQs2V9NzsmGgQbuc.cache +0 -0
  46. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/vwm1k9Bq-HwABJMegaJmccXR8JXBcp7a46peIjalZug.cache +1 -0
  47. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/xNxWjlD2nQ_nHrl6FvGZ5mhn4F5A5XJAlz029Se49y4.cache +2 -0
  48. metadata +49 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f37035167e1f90170a80e5e56b0523d7bc51b64e
4
- data.tar.gz: 066c6ab929e8ec5a62bf4f408d907af17fb1a86e
3
+ metadata.gz: 5575c6f6f641ecad045a93b77c40faec4c42ab70
4
+ data.tar.gz: 4a052e63f7175875367985d4b5704c34a2df1eda
5
5
  SHA512:
6
- metadata.gz: 6345b60be6812d70b38e502fae73fe497b342db02843c56579ffa70d5d8f57445464019d6deb59711baeb536df2b33e521b9bd94548289088e3c699a2919cb1b
7
- data.tar.gz: 0fd6d78ce22fc48f4cb0a10bf7912ceedd8b1fec33db34a2dc3a167f87eb511c6fbcf9c197af15ef7bf51158ed529791dfeeff39a2ad81398b8309d8b98a6242
6
+ metadata.gz: 6d7949a04cca35acfa2e8a15082c245d347c50ab7bad3d064d5c065b5a1fce1fdb90690e49b3678b831a867e3a2277f43475facbd9e98b47a48861b13f3c061f
7
+ data.tar.gz: 3b57115fe59252703f48bedf7a7d48232b20e2a514c55b949c4711d41667c21fad63962bbea91aad14e26f85480deccd38eff6b59db6d348da5630bfb6ab33fc
data/README.md CHANGED
@@ -9,7 +9,7 @@ Simple & modulable authentication gem
9
9
  ```ruby
10
10
  class ApplicationController < ActionController::Base
11
11
  include Nyauth::ControllerConcern
12
- before_action -> { require_authentication! as: client_name }
12
+ before_action -> { require_authentication! as: nyauth_client_name }
13
13
  end
14
14
  ```
15
15
 
@@ -8,6 +8,7 @@ module Nyauth
8
8
 
9
9
  def initialize
10
10
  @nyauth_client_classes = {}
11
+
11
12
  super
12
13
  end
13
14
 
@@ -13,7 +13,7 @@ module Nyauth
13
13
  # sign_in(client)
14
14
  def sign_in(client)
15
15
  return unless client
16
- store_signed_in_session(client)
16
+ store_signed_in_status(client)
17
17
  end
18
18
 
19
19
  # ex.)
@@ -28,6 +28,11 @@ module Nyauth
28
28
  # sign_out
29
29
  def sign_out
30
30
  reset_session
31
+
32
+ if Nyauth.configuration.use_cookie_auth
33
+ # ex.) cookies.signed[:user_id]
34
+ cookies.delete :nyauth_cookie_auth
35
+ end
31
36
  end
32
37
 
33
38
  # ex.)
@@ -36,6 +41,7 @@ module Nyauth
36
41
  options.reverse_merge!(as: :user)
37
42
  return if self.class.allow_actions == :all
38
43
  return if self.class.allow_actions.present? && request[:action].to_sym.in?(self.class.allow_actions)
44
+
39
45
  unless signed_in?(options)
40
46
  session["#{options[:as]}_return_to"] = request.url if request.get?
41
47
  redirect_to new_session_path_for(options[:as])
@@ -47,8 +53,13 @@ module Nyauth
47
53
  nyauth_nyan.session.fetch(options[:as])
48
54
  end
49
55
 
50
- def store_signed_in_session(client)
56
+ def store_signed_in_status(client)
51
57
  nyauth_nyan.session.store(client, client.class.name.demodulize.underscore)
58
+
59
+ if Nyauth.configuration.use_cookie_auth
60
+ # ex.) cookies.signed[:user_id]
61
+ cookies.signed[:nyauth_cookie_auth] = "#{client.class.name.demodulize.underscore}:#{client.id}"
62
+ end
52
63
  end
53
64
 
54
65
  private
@@ -0,0 +1,7 @@
1
+ module Nyauth
2
+ class BaseController < ApplicationController
3
+ include Nyauth::ControllerConcern
4
+ self.responder = Nyauth::AppResponder
5
+ respond_to :html, :json
6
+ end
7
+ end
@@ -1,9 +1,8 @@
1
1
  module Nyauth
2
- class ConfirmationRequestsController < ApplicationController
3
- include Nyauth::ControllerConcern
2
+ class ConfirmationRequestsController < Nyauth::BaseController
4
3
  allow_everyone
5
4
  self.responder = Nyauth::AppResponder
6
- respond_to :html, :json
5
+
7
6
  before_action :set_service
8
7
  after_action :send_mail, only: [:create], if: -> { @service.errors.blank? }
9
8
 
@@ -1,9 +1,8 @@
1
1
  module Nyauth
2
- class ConfirmationsController < ApplicationController
3
- include Nyauth::ControllerConcern
2
+ class ConfirmationsController < Nyauth::BaseController
4
3
  allow_everyone
5
4
  self.responder = ConfirmationResponder
6
- respond_to :html, :json
5
+
7
6
  before_action :set_client
8
7
 
9
8
  def update
@@ -1,10 +1,6 @@
1
1
  module Nyauth
2
- class PasswordsController < ApplicationController
3
- include Nyauth::ControllerConcern
2
+ class PasswordsController < Nyauth::BaseController
4
3
  before_action -> { require_authentication! as: nyauth_client_name }
5
-
6
- self.responder = Nyauth::AppResponder
7
- respond_to :html, :json
8
4
  before_action :set_client
9
5
 
10
6
  def edit
@@ -1,9 +1,6 @@
1
1
  module Nyauth
2
- class RegistrationsController < ApplicationController
3
- include Nyauth::ControllerConcern
2
+ class RegistrationsController < Nyauth::BaseController
4
3
  allow_everyone
5
- self.responder = Nyauth::AppResponder
6
- respond_to :html, :json
7
4
  before_action :set_service
8
5
 
9
6
  def new
@@ -1,9 +1,6 @@
1
1
  module Nyauth
2
- class ResetPasswordRequestsController < ApplicationController
3
- include Nyauth::ControllerConcern
2
+ class ResetPasswordRequestsController < Nyauth::BaseController
4
3
  allow_everyone
5
- self.responder = Nyauth::AppResponder
6
- respond_to :html, :json
7
4
  before_action :set_service
8
5
  after_action :send_mail, only: [:create], if: -> { @service.errors.blank? }
9
6
 
@@ -1,9 +1,6 @@
1
1
  module Nyauth
2
- class ResetPasswordsController < ApplicationController
3
- include Nyauth::ControllerConcern
2
+ class ResetPasswordsController < Nyauth::BaseController
4
3
  allow_everyone
5
- self.responder = Nyauth::AppResponder
6
- respond_to :html, :json
7
4
  before_action :set_client
8
5
 
9
6
  def edit
@@ -1,10 +1,7 @@
1
1
  module Nyauth
2
- class SessionsController < ApplicationController
3
- include Nyauth::ControllerConcern
4
- before_action -> { require_authentication! as: nyauth_client_name }
2
+ class SessionsController < Nyauth::BaseController
5
3
  allow_everyone only: [:new, :create]
6
- self.responder = Nyauth::AppResponder
7
- respond_to :html, :json
4
+ before_action -> { require_authentication! as: nyauth_client_name }
8
5
  before_action :set_service
9
6
 
10
7
  def new
@@ -14,6 +14,7 @@ module Nyauth
14
14
  def detect_url_helper(feature, nyauth_client_name, *args)
15
15
  @__methods ||= Nyauth::Engine.routes.url_helpers.instance_methods + Rails.application.routes.url_helpers.instance_methods
16
16
  @__candidates ||= @__methods.reject{|m| m =~ /\A(:?rails_|_)/}.map(&:to_s)
17
+
17
18
  if respond_to?(:nyauth) && nyauth_client_name.to_sym == :user
18
19
  # mounted as nyauth
19
20
  detect_url_helper_for_nyauth(feature, *args)
@@ -25,6 +26,7 @@ module Nyauth
25
26
  def detect_url_helper_for_nyauth(feature, *args)
26
27
  path = @__candidates.grep(/\A#{feature}_path\z/).first
27
28
  return nil unless path
29
+
28
30
  nyauth.__send__(path, *args)
29
31
  end
30
32
 
@@ -34,7 +36,9 @@ module Nyauth
34
36
  else
35
37
  path = @__candidates.grep(/\A#{nyauth_client_name}_#{feature}_path\z/).first
36
38
  end
39
+
37
40
  return nil unless path
41
+
38
42
  main_app.__send__(path, *args)
39
43
  end
40
44
 
@@ -4,7 +4,6 @@ module Nyauth
4
4
  include Nyauth::PasswordDigestAbility
5
5
  include Nyauth::ResetPasswordAbility
6
6
 
7
-
8
7
  included do
9
8
  validates :email, presence: true
10
9
  end
@@ -13,6 +12,7 @@ module Nyauth
13
12
  def authenticate(given_email, given_password)
14
13
  record = where(email: given_email).last
15
14
  return nil unless record
15
+
16
16
  record.verify_password?(given_password) ? record : nil
17
17
  end
18
18
  end
@@ -3,6 +3,7 @@ Nyauth.configure do |config|
3
3
  config.confirmation_expire_limit = 1.hour
4
4
  config.reset_password_expire_limit = 1.hour
5
5
  config.mail_delivery_method = :deliver_now
6
+ config.use_cookie_auth = false
6
7
  config.redirect_path do |urls|
7
8
  # config.redirect_path_after_sign_in = -> (client_name) {
8
9
  # if client_name == :admin
@@ -14,7 +14,8 @@ module Nyauth
14
14
  :password_minium,
15
15
  :password_digest_stretches,
16
16
  :encryption_secret,
17
- :mail_delivery_method
17
+ :mail_delivery_method,
18
+ :use_cookie_auth
18
19
 
19
20
 
20
21
  def initialize
@@ -32,6 +33,7 @@ module Nyauth
32
33
  @password_digest_stretches = 1000
33
34
  @encryption_secret = ENV['NYAUTH_ENCRYPTION_SECRET']
34
35
  @mail_delivery_method = :deliver_now
36
+ @use_cookie_auth = false
35
37
  @redirect_path_block = Proc.new {}
36
38
  end
37
39
 
@@ -8,6 +8,7 @@ module Nyauth
8
8
 
9
9
  def call(env)
10
10
  return @app.call(env) if env['nyauth']
11
+
11
12
  env['nyauth'] = Nyauth::Nyan.new(env)
12
13
  Nyauth::Nyan.run_callback env['nyauth'] do
13
14
  @app.call(env)
data/lib/nyauth/nyan.rb CHANGED
@@ -16,6 +16,7 @@ module Nyauth
16
16
  callback.call(nyan, *options)
17
17
  end
18
18
  end
19
+
19
20
  @@_on_test_request = []
20
21
  yield
21
22
  end
@@ -19,6 +19,7 @@ module Nyauth
19
19
 
20
20
  def store(client, scope)
21
21
  return unless client
22
+
22
23
  session[key_for(scope)] = serialize(client)
23
24
  end
24
25
 
@@ -35,7 +36,7 @@ module Nyauth
35
36
  !!session[key_for(scope)]
36
37
  end
37
38
 
38
- def delete(scope, client=nil)
39
+ def delete(scope)
39
40
  session.delete(key_for(scope))
40
41
  end
41
42
 
@@ -1,3 +1,3 @@
1
1
  module Nyauth
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -1,3 +1,4 @@
1
1
  Nyauth.configure do |config|
2
2
  config.encryption_secret = ENV['NYAUTH_ENCRYPTION_SECRET'] || 'rails6dd08eff1c2cf5aecb54cb1a97266817b58cc27f06be9e95918c06607d3950d623a4fd4c0c306d2216cdaf3f99871e21e0e975a5e64ef5cf286b68ed8d7379a4'
3
+ config.use_cookie_auth = true
3
4
  end
Binary file