linked_rails-auth 0.0.2 → 0.0.4

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/linked_rails/auth/access_tokens_controller.rb +11 -8
  3. data/app/controllers/linked_rails/auth/confirmations_controller.rb +9 -7
  4. data/app/controllers/linked_rails/auth/otp_attempts_controller.rb +5 -6
  5. data/app/controllers/linked_rails/auth/otp_secrets_controller.rb +10 -6
  6. data/app/controllers/linked_rails/auth/passwords_controller.rb +10 -6
  7. data/app/controllers/linked_rails/auth/registrations_controller.rb +5 -6
  8. data/app/controllers/linked_rails/auth/sessions_controller.rb +5 -12
  9. data/app/controllers/linked_rails/auth/unlocks_controller.rb +6 -6
  10. data/app/forms/linked_rails/auth/otp_secret_form.rb +0 -1
  11. data/app/helpers/linked_rails/auth/otp_helper.rb +1 -1
  12. data/app/models/linked_rails/auth/access_token.rb +0 -8
  13. data/app/models/linked_rails/auth/confirmation.rb +8 -16
  14. data/app/models/linked_rails/auth/otp_attempt.rb +1 -2
  15. data/app/models/linked_rails/auth/otp_base.rb +7 -11
  16. data/app/models/linked_rails/auth/otp_secret.rb +0 -2
  17. data/app/models/linked_rails/auth/password.rb +8 -8
  18. data/app/models/linked_rails/auth/registration.rb +8 -12
  19. data/app/models/linked_rails/auth/session.rb +1 -11
  20. data/app/models/linked_rails/auth/unlock.rb +0 -8
  21. data/app/policies/linked_rails/auth/otp_secret_policy.rb +2 -2
  22. data/app/serializers/linked_rails/auth/otp_attempt_serializer.rb +3 -4
  23. data/app/serializers/linked_rails/auth/otp_secret_serializer.rb +7 -6
  24. data/app/serializers/linked_rails/auth/password_serializer.rb +6 -8
  25. data/lib/generators/linked_rails/auth/install_generator.rb +7 -6
  26. data/lib/generators/linked_rails/auth/templates/locales.yml +24 -0
  27. data/lib/linked_rails/auth/errors/unknown_email.rb +1 -1
  28. data/lib/linked_rails/auth/errors/wrong_password.rb +1 -1
  29. data/lib/linked_rails/auth/routes.rb +17 -19
  30. data/lib/linked_rails/auth/version.rb +1 -1
  31. data/lib/linked_rails/auth.rb +0 -8
  32. metadata +3 -11
  33. data/app/actions/linked_rails/auth/access_token_action_list.rb +0 -16
  34. data/app/actions/linked_rails/auth/confirmation_action_list.rb +0 -17
  35. data/app/actions/linked_rails/auth/otp_attempt_action_list.rb +0 -13
  36. data/app/actions/linked_rails/auth/otp_secret_action_list.rb +0 -31
  37. data/app/actions/linked_rails/auth/password_action_list.rb +0 -25
  38. data/app/actions/linked_rails/auth/registration_action_list.rb +0 -15
  39. data/app/actions/linked_rails/auth/session_action_list.rb +0 -22
  40. data/app/actions/linked_rails/auth/unlock_action_list.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdac2ac7b1c19172bd134b16bb0a68b37d0e3554dbe2fa81758a8979ca978b16
4
- data.tar.gz: f5a06a7413a6ea914343bb2e30c4777768772ecbde68550f3ac7185cdc346438
3
+ metadata.gz: 0a53fa6c27c504534477bb37b6b7d5d147e1c98a6c6c87d5370b78b8359b9439
4
+ data.tar.gz: 8c15e3103885126daf13bb4dc4ed162caaf86e935182ab10110e0e6ab18fc89d
5
5
  SHA512:
6
- metadata.gz: a74b845b028974e126b38cfc146869118d090337d9fde50558135294e9e9b377484e9a00f27855976fe0e1ebe42ce0e87992706f25f4199cbd1cabb30ae012ac
7
- data.tar.gz: 99e7c1594200bcd42df838e537af3071f3664e855500041d781aeda362e7f7c77c620dbbb52bac74f8d4b329ed814994eeb160e37e685783913fca83f0f7f807
6
+ metadata.gz: d86610473276dc2d3068b74d3b2e28769573e03bccbd5993b728ccb7955bc6a97f86e1077c7384f517fe6c36ee41275cef92a12d34180d962ccc30bdd575f451
7
+ data.tar.gz: 925ffe6ec29358d29275131576587899951f688d56f0d165f89ead10e86ab14c51218938da1e7a48539acc17dce2df132d6031954aeb29ab0e5efd89d0a82015
@@ -3,6 +3,14 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class AccessTokensController < Doorkeeper::TokensController # rubocop:disable Metrics/ClassLength
6
+ include LinkedRails::Controller
7
+
8
+ controller_class LinkedRails.access_token_class
9
+ has_singular_create_action(
10
+ type: [Vocab.ontola['Create::Auth::AccessToken'], Vocab.schema.CreateAction],
11
+ target_url: -> { LinkedRails.iri(path: '/login') }
12
+ )
13
+
6
14
  def create
7
15
  headers.merge!(authorize_response.headers)
8
16
 
@@ -49,8 +57,9 @@ module LinkedRails
49
57
  error = get_error_response_from_exception(exception)
50
58
  headers.merge!(error.headers)
51
59
  Bugsnag.notify(exception)
52
- Rails.logger.info(error.body.merge(class: exception.class.name).to_json)
53
- self.response_body = error.body.merge(class: exception.class.name).to_json
60
+ klass = exception.class.name.demodulize.underscore.upcase
61
+ self.response_body = error.body.merge(code: klass).to_json
62
+ Rails.logger.info(self.response_body)
54
63
  self.status = error.status
55
64
  end
56
65
 
@@ -120,12 +129,6 @@ module LinkedRails
120
129
  token_with_errors.errors.add(field, exception.message)
121
130
  token_with_errors
122
131
  end
123
-
124
- class << self
125
- def controller_class
126
- LinkedRails.access_token_class
127
- end
128
- end
129
132
  end
130
133
  end
131
134
  end
@@ -3,7 +3,15 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class ConfirmationsController < Devise::ConfirmationsController
6
- active_response :show, :update
6
+ include LinkedRails::Controller
7
+
8
+ controller_class LinkedRails.confirmation_class
9
+ active_response :show
10
+ has_singular_create_action(
11
+ form: -> { resource.class.try(:form_class) },
12
+ type: [Vocab.ontola['Create::Auth::Confirmation'], Vocab.schema.CreateAction]
13
+ )
14
+ has_singular_update_action(form: -> { nil })
7
15
 
8
16
  private
9
17
 
@@ -76,12 +84,6 @@ module LinkedRails
76
84
  notice: find_message(:confirmed)
77
85
  )
78
86
  end
79
-
80
- class << self
81
- def controller_class
82
- LinkedRails.confirmation_class
83
- end
84
- end
85
87
  end
86
88
  end
87
89
  end
@@ -3,6 +3,11 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class OtpAttemptsController < LinkedRails.controller_parent_class
6
+ controller_class LinkedRails.otp_attempt_class
7
+ has_singular_create_action(
8
+ type: Vocab.schema[:CreateAction]
9
+ )
10
+
6
11
  private
7
12
 
8
13
  def create_success
@@ -10,12 +15,6 @@ module LinkedRails
10
15
 
11
16
  head 200
12
17
  end
13
-
14
- class << self
15
- def controller_class
16
- LinkedRails.otp_attempt_class
17
- end
18
- end
19
18
  end
20
19
  end
21
20
  end
@@ -3,7 +3,17 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class OtpSecretsController < LinkedRails.controller_parent_class
6
+ controller_class LinkedRails.otp_secret_class
6
7
  active_response :show
8
+ has_singular_create_action(
9
+ type: Vocab.schema[:CreateAction]
10
+ )
11
+ has_resource_destroy_action(
12
+ description: -> { I18n.t('actions.otp_secrets.destroy.description', name: resource.owner.email) }
13
+ )
14
+ has_singular_destroy_action(
15
+ description: -> { I18n.t('actions.otp_secrets.destroy.description', name: resource.owner.email) }
16
+ )
7
17
 
8
18
  private
9
19
 
@@ -29,12 +39,6 @@ module LinkedRails
29
39
 
30
40
  super.merge(active: true)
31
41
  end
32
-
33
- class << self
34
- def controller_class
35
- LinkedRails.otp_secret_class
36
- end
37
- end
38
42
  end
39
43
  end
40
44
  end
@@ -3,8 +3,16 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class PasswordsController < Devise::PasswordsController
6
+ include LinkedRails::Controller
7
+
6
8
  skip_before_action :require_no_authentication, only: :create
7
9
 
10
+ controller_class LinkedRails.password_class
11
+ has_singular_create_action(
12
+ type: [Vocab.ontola['Create::Auth::Password'], Vocab.schema.CreateAction]
13
+ )
14
+ has_singular_update_action(label: nil)
15
+
8
16
  private
9
17
 
10
18
  def after_sending_reset_password_instructions_path_for(_resource_name)
@@ -15,6 +23,8 @@ module LinkedRails
15
23
  LinkedRails.iri(path: '/u/session/new').path
16
24
  end
17
25
 
26
+ def assert_reset_token_passed; end
27
+
18
28
  def create_execute
19
29
  @current_resource = resource_class.send_reset_password_instructions(resource_params)
20
30
  successfully_sent?(current_resource)
@@ -52,12 +62,6 @@ module LinkedRails
52
62
  def update_success_location
53
63
  after_resetting_password_path_for(current_resource)
54
64
  end
55
-
56
- class << self
57
- def controller_class
58
- LinkedRails.password_class
59
- end
60
- end
61
65
  end
62
66
  end
63
67
  end
@@ -3,8 +3,13 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class RegistrationsController < Devise::RegistrationsController
6
+ include LinkedRails::Controller
7
+
6
8
  skip_before_action :assert_is_devise_resource!, only: :show
9
+
10
+ controller_class LinkedRails.registration_class
7
11
  active_response :show
12
+ has_singular_create_action
8
13
 
9
14
  private
10
15
 
@@ -22,12 +27,6 @@ module LinkedRails
22
27
  def resource_params
23
28
  params.require(permit_param_key)
24
29
  end
25
-
26
- class << self
27
- def controller_class
28
- LinkedRails.registration_class
29
- end
30
- end
31
30
  end
32
31
  end
33
32
  end
@@ -2,8 +2,11 @@
2
2
 
3
3
  module LinkedRails
4
4
  module Auth
5
- class SessionsController < ApplicationController
6
- active_response :create
5
+ class SessionsController < LinkedRails.controller_parent_class
6
+ controller_class LinkedRails.session_class
7
+ has_singular_create_action(
8
+ type: [Vocab.ontola['Create::Auth::Session'], Vocab.schema.CreateAction]
9
+ )
7
10
 
8
11
  private
9
12
 
@@ -40,16 +43,6 @@ module LinkedRails
40
43
  def permit_params
41
44
  params.require(:session).permit(:redirect_url, :email)
42
45
  end
43
-
44
- def r_param
45
- new_resource_params[:redirect_url] || (params.key?(:session) ? permit_params[:redirect_url] : nil)
46
- end
47
-
48
- class << self
49
- def controller_class
50
- LinkedRails.session_class
51
- end
52
- end
53
46
  end
54
47
  end
55
48
  end
@@ -3,6 +3,12 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class UnlocksController < Devise::UnlocksController
6
+ controller_class LinkedRails.unlock_class
7
+ has_singular_create_action(
8
+ form: -> { resource.class.try(:form_class) }
9
+ )
10
+ has_singular_update_action
11
+
6
12
  private
7
13
 
8
14
  def after_sending_unlock_instructions_path_for(_resource)
@@ -33,12 +39,6 @@ module LinkedRails
33
39
  params.fetch(resource_name, nil) ||
34
40
  params.fetch(controller_name.singularize, {})
35
41
  end
36
-
37
- class << self
38
- def controller_class
39
- LinkedRails.unlock_class
40
- end
41
- end
42
42
  end
43
43
  end
44
44
  end
@@ -4,7 +4,6 @@ module LinkedRails
4
4
  module Auth
5
5
  class OtpSecretForm < LinkedRails.form_parent_class
6
6
  resource :provision_image,
7
- description: -> { I18n.t('otp_secrets.properties.provision_image.description') },
8
7
  path: Vocab.schema.image
9
8
  field :otp_attempt, description: '', min_count: 1
10
9
  end
@@ -4,7 +4,7 @@ module LinkedRails
4
4
  module Auth
5
5
  module OtpHelper
6
6
  def handle_expired_session
7
- raise LinkedRails::Auth::Errors::Expired, I18n.t('messages.otp_secrets.expired')
7
+ raise LinkedRails::Auth::Errors::Expired, I18n.t('actions.otp_secrets.errors.expired')
8
8
  end
9
9
 
10
10
  def session_from_param(session_param)
@@ -3,10 +3,6 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class AccessToken < LinkedRails::Resource
6
- enhance LinkedRails::Enhancements::Actionable
7
- enhance LinkedRails::Enhancements::Creatable
8
- enhance LinkedRails::Enhancements::Singularable
9
-
10
6
  attr_accessor :email, :redirect_url, :password
11
7
  alias root_relative_iri root_relative_singular_iri
12
8
 
@@ -15,10 +11,6 @@ module LinkedRails
15
11
  end
16
12
 
17
13
  class << self
18
- def action_list
19
- LinkedRails.access_token_action_list_class
20
- end
21
-
22
14
  def form_class
23
15
  LinkedRails.access_token_form_class
24
16
  end
@@ -3,10 +3,6 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class Confirmation < LinkedRails::Resource
6
- enhance LinkedRails::Enhancements::Actionable
7
- enhance LinkedRails::Enhancements::Creatable
8
- enhance LinkedRails::Enhancements::Updatable
9
- enhance LinkedRails::Enhancements::Singularable
10
6
  attr_accessor :confirmation_token, :email, :user, :password_token
11
7
  alias root_relative_iri root_relative_singular_iri
12
8
 
@@ -15,10 +11,10 @@ module LinkedRails
15
11
  end
16
12
 
17
13
  def confirm!
18
- owner!.confirm
14
+ user!.confirm
19
15
  end
20
16
 
21
- delegate :confirmed?, to: :owner!
17
+ delegate :confirmed?, to: :user!
22
18
 
23
19
  def singular_iri_opts
24
20
  {confirmation_token: confirmation_token}
@@ -28,15 +24,11 @@ module LinkedRails
28
24
  LinkedRails.iri
29
25
  end
30
26
 
31
- def owner!
32
- owner || raise(ActiveRecord::RecordNotFound)
27
+ def user!
28
+ user || raise(ActiveRecord::RecordNotFound)
33
29
  end
34
30
 
35
31
  class << self
36
- def action_list
37
- LinkedRails.confirmation_action_list_class
38
- end
39
-
40
32
  def form_class
41
33
  LinkedRails.confirmation_form_class
42
34
  end
@@ -45,10 +37,6 @@ module LinkedRails
45
37
  Vocab.ontola
46
38
  end
47
39
 
48
- def singular_iri_template
49
- @singular_iri_template ||= URITemplate.new("/#{singular_route_key}{?confirmation_token}")
50
- end
51
-
52
40
  def requested_singular_resource(params, _user_context)
53
41
  return new unless params.key?(:confirmation_token)
54
42
 
@@ -61,6 +49,10 @@ module LinkedRails
61
49
  )
62
50
  end
63
51
 
52
+ def singular_iri_template
53
+ @singular_iri_template ||= URITemplate.new("/#{singular_route_key}{?confirmation_token}")
54
+ end
55
+
64
56
  def singular_route_key
65
57
  'u/confirmation'
66
58
  end
@@ -3,13 +3,12 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class OtpAttempt < OtpBase
6
- def raise_on_persisting(_opts = {})
6
+ def raise_on_persisting(**_opts)
7
7
  raise "#{self.class.name} should not be persisted"
8
8
  end
9
9
  ActiveRecord::Persistence.instance_methods.each do |method|
10
10
  alias_method method, :raise_on_persisting unless method.to_s.include?('?')
11
11
  end
12
-
13
12
  alias root_relative_iri root_relative_singular_iri
14
13
 
15
14
  def save
@@ -6,10 +6,6 @@ module LinkedRails
6
6
  self.table_name = 'otp_secrets'
7
7
  self.abstract_class = true
8
8
 
9
- enhance LinkedRails::Enhancements::Actionable
10
- enhance LinkedRails::Enhancements::Creatable
11
- enhance LinkedRails::Enhancements::Singularable
12
-
13
9
  extend OtpHelper
14
10
  include OtpHelper
15
11
 
@@ -21,29 +17,29 @@ module LinkedRails
21
17
 
22
18
  attr_accessor :encoded_session, :otp_attempt
23
19
 
20
+ def singular_iri_opts
21
+ {session: encoded_session}
22
+ end
23
+
24
24
  private
25
25
 
26
26
  def decoded_session
27
27
  @decoded_session ||= session_from_param(encoded_session)
28
28
  end
29
29
 
30
- def singular_iri_opts
31
- {session: encoded_session}
32
- end
33
-
34
30
  def validate_otp_attempt
35
31
  return if persisted? && authenticate_otp(otp_attempt, drift: LinkedRails::Auth.otp_drift)
36
32
 
37
- errors.add(:otp_attempt, I18n.t('messages.otp_secrets.invalid'))
33
+ errors.add(:otp_attempt, I18n.t('actions.otp_secrets.errors.invalid'))
38
34
  end
39
35
 
40
36
  class << self
41
37
  def iri_template
42
- @iri_template ||= URITemplate.new("/#{route_key}{/id}{?session}{#fragment}")
38
+ @iri_template ||= URITemplate.new("/#{route_key}{/id}{#fragment}")
43
39
  end
44
40
 
45
41
  def singular_iri_template
46
- @singular_iri_template ||= URITemplate.new("{/parent_iri*}/#{singular_route_key}{?session}{#fragment}")
42
+ @singular_iri_template ||= URITemplate.new("/#{singular_route_key}{?session}{#fragment}")
47
43
  end
48
44
 
49
45
  def owner_for_otp(params, user_context)
@@ -5,8 +5,6 @@ require 'rqrcode'
5
5
  module LinkedRails
6
6
  module Auth
7
7
  class OtpSecret < OtpBase
8
- enhance LinkedRails::Enhancements::Destroyable
9
-
10
8
  validate :validate_otp_attempt, on: %i[update]
11
9
 
12
10
  def image
@@ -3,18 +3,14 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class Password < LinkedRails::Resource
6
- enhance LinkedRails::Enhancements::Actionable
7
- enhance LinkedRails::Enhancements::Creatable
8
- enhance LinkedRails::Enhancements::Updatable
9
- enhance LinkedRails::Enhancements::Singularable
10
6
  attr_accessor :email, :password, :password_confirmation, :user, :reset_password_token
11
7
  alias root_relative_iri root_relative_singular_iri
12
8
 
13
- class << self
14
- def action_list
15
- LinkedRails.password_action_list_class
16
- end
9
+ def singular_iri_opts
10
+ {reset_password_token: reset_password_token}
11
+ end
17
12
 
13
+ class << self
18
14
  def decrypt_token(token)
19
15
  Devise.token_generator.digest(self, :reset_password_token, token)
20
16
  end
@@ -41,6 +37,10 @@ module LinkedRails
41
37
  def singular_route_key
42
38
  'u/password'
43
39
  end
40
+
41
+ def singular_iri_template
42
+ @singular_iri_template ||= URITemplate.new("/#{singular_route_key}{?reset_password_token}")
43
+ end
44
44
  end
45
45
  end
46
46
  end
@@ -3,17 +3,13 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class Registration < LinkedRails.user_class
6
- enhance LinkedRails::Enhancements::Actionable
7
- enhance LinkedRails::Enhancements::Creatable
8
- enhance LinkedRails::Enhancements::Singularable
9
-
10
6
  attr_accessor :redirect_url
11
7
 
12
- class << self
13
- def action_list
14
- LinkedRails.registration_action_list_class
15
- end
8
+ def singular_iri_opts
9
+ {redirect_url: redirect_url}
10
+ end
16
11
 
12
+ class << self
17
13
  def form_class
18
14
  LinkedRails.registration_form_class
19
15
  end
@@ -22,14 +18,14 @@ module LinkedRails
22
18
  Vocab.ontola
23
19
  end
24
20
 
25
- def iri_template
26
- LinkedRails.user_class.iri_template
27
- end
28
-
29
21
  def requested_singular_resource(_params, user_context)
30
22
  build_new(user_context: user_context)
31
23
  end
32
24
 
25
+ def singular_iri_template
26
+ @singular_iri_template ||= URITemplate.new("/#{singular_route_key}{?redirect_url}")
27
+ end
28
+
33
29
  def singular_route_key
34
30
  'u/registration'
35
31
  end
@@ -3,23 +3,14 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class Session < LinkedRails::Resource
6
- enhance LinkedRails::Enhancements::Actionable
7
- enhance LinkedRails::Enhancements::Creatable
8
- enhance LinkedRails::Enhancements::Destroyable
9
- enhance LinkedRails::Enhancements::Singularable
10
- alias root_relative_iri root_relative_singular_iri
11
-
12
6
  attr_accessor :email, :redirect_url
7
+ alias root_relative_iri root_relative_singular_iri
13
8
 
14
9
  def singular_iri_opts
15
10
  {redirect_url: redirect_url}
16
11
  end
17
12
 
18
13
  class << self
19
- def action_list
20
- LinkedRails.session_action_list_class
21
- end
22
-
23
14
  def form_class
24
15
  LinkedRails.session_form_class
25
16
  end
@@ -31,7 +22,6 @@ module LinkedRails
31
22
  def singular_iri_template
32
23
  @singular_iri_template ||= URITemplate.new("/#{singular_route_key}{?redirect_url}")
33
24
  end
34
- alias iri_template singular_iri_template
35
25
 
36
26
  def requested_singular_resource(params, _user_context)
37
27
  new(redirect_url: params[:redirect_url])
@@ -3,10 +3,6 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class Unlock < LinkedRails::Resource
6
- enhance LinkedRails::Enhancements::Actionable
7
- enhance LinkedRails::Enhancements::Creatable
8
- enhance LinkedRails::Enhancements::Updatable, except: %i[Serializer]
9
- enhance LinkedRails::Enhancements::Singularable
10
6
  attr_accessor :email, :unlock_token, :user
11
7
  alias root_relative_iri root_relative_singular_iri
12
8
 
@@ -19,10 +15,6 @@ module LinkedRails
19
15
  end
20
16
 
21
17
  class << self
22
- def action_list
23
- LinkedRails.unlock_action_list_class
24
- end
25
-
26
18
  def decrypt_token(token)
27
19
  Devise.token_generator.digest(self, :unlock_token, token)
28
20
  end
@@ -10,7 +10,7 @@ module LinkedRails
10
10
  end
11
11
 
12
12
  def create?
13
- return forbid_with_message(I18n.t('messages.otp_secrets.already_exists')) if user_context.otp_active?
13
+ return forbid_with_message(I18n.t('actions.otp_secrets.errors.already_exists')) if user_context.otp_active?
14
14
 
15
15
  user_context.guest? || current_user?
16
16
  end
@@ -18,7 +18,7 @@ module LinkedRails
18
18
  def destroy?
19
19
  raise(ActiveRecord::RecordNotFound) unless administrate_otp? || current_user?
20
20
 
21
- return forbid_with_message(I18n.t('messages.otp_secrets.not_activated')) unless record.active?
21
+ return forbid_with_message(I18n.t('actions.otp_secrets.errors.not_activated')) unless record.active?
22
22
 
23
23
  current_user? || administrate_otp?
24
24
  end
@@ -3,10 +3,9 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class OtpAttemptSerializer < LinkedRails.serializer_parent_class
6
- attribute :otp_attempt,
7
- predicate: LinkedRails.app_ns[:otp],
8
- datatype: RDF::XSD[:integer],
9
- if: method(:never)
6
+ secret_attribute :otp_attempt,
7
+ predicate: Vocab.app[:otp],
8
+ datatype: RDF::XSD[:integer]
10
9
  end
11
10
  end
12
11
  end
@@ -3,12 +3,13 @@
3
3
  module LinkedRails
4
4
  module Auth
5
5
  class OtpSecretSerializer < LinkedRails.serializer_parent_class
6
- attribute :otp_attempt,
7
- predicate: LinkedRails.app_ns[:otp],
8
- datatype: RDF::XSD[:integer],
9
- if: method(:never)
10
- attribute :active, predicate: LinkedRails.app_ns[:otpActive]
11
- has_one :image, predicate: Vocab.schema.image
6
+ secret_attribute :otp_attempt,
7
+ predicate: Vocab.app[:otp],
8
+ datatype: RDF::XSD[:integer]
9
+ attribute :active, predicate: Vocab.ontola[:otpActive]
10
+ has_one :image,
11
+ predicate: Vocab.schema.image,
12
+ serializer: LinkedRails::MediaObjectSerializer
12
13
  end
13
14
  end
14
15
  end
@@ -4,14 +4,12 @@ module LinkedRails
4
4
  module Auth
5
5
  class PasswordSerializer < LinkedRails.serializer_parent_class
6
6
  attribute :email, predicate: Vocab.schema.email, datatype: RDF::XSD[:string]
7
- attribute :password,
8
- predicate: Vocab.ontola[:password],
9
- datatype: Vocab.ontola['datatype/password'],
10
- if: method(:never)
11
- attribute :password_confirmation,
12
- predicate: Vocab.ontola[:passwordConfirmation],
13
- datatype: Vocab.ontola['datatype/password'],
14
- if: method(:never)
7
+ secret_attribute :password,
8
+ predicate: Vocab.ontola[:password],
9
+ datatype: Vocab.ontola['datatype/password']
10
+ secret_attribute :password_confirmation,
11
+ predicate: Vocab.ontola[:passwordConfirmation],
12
+ datatype: Vocab.ontola['datatype/password']
15
13
  attribute :reset_password_token, predicate: Vocab.ontola[:resetPasswordToken], datatype: RDF::XSD[:string]
16
14
  end
17
15
  end
@@ -23,6 +23,7 @@ module LinkedRails
23
23
  update_user_model
24
24
  insert_doorkeeper
25
25
  create_doorkeeper_app
26
+ inject_controller_include
26
27
 
27
28
  readme 'README'
28
29
  end
@@ -77,16 +78,16 @@ module LinkedRails
77
78
  uncomment_lines file, 'use_refresh_token'
78
79
 
79
80
  replace_doorkeeper_line(
80
- '# default_scopes :public',
81
- 'default_scopes :guest'
81
+ 'default_scopes :public',
82
+ ' default_scopes :guest'
82
83
  )
83
84
  replace_doorkeeper_line(
84
- '# optional_scopes :write, :update',
85
- 'optional_scopes :user'
85
+ 'optional_scopes :write, :update',
86
+ ' optional_scopes :user'
86
87
  )
87
88
  replace_doorkeeper_line(
88
- '# grant_flows %w[authorization_code client_credentials]',
89
- 'grant_flows %w[client_credentials authorization_code password]'
89
+ 'grant_flows %w\[authorization_code client_credentials\]',
90
+ ' grant_flows %w[client_credentials authorization_code password]'
90
91
  )
91
92
  replace_doorkeeper_line("resource_owner_authenticator do\n(.*?)end\n", authentication, true)
92
93
  end
@@ -1,5 +1,9 @@
1
1
  en:
2
2
  actions:
3
+ access_tokens:
4
+ create:
5
+ label: "Sign in"
6
+ submit: "Send"
3
7
  confirmations:
4
8
  create:
5
9
  label: "Send confirmation link again"
@@ -9,6 +13,7 @@ en:
9
13
  submit: "Confirm"
10
14
  otp_attempts:
11
15
  create:
16
+ label: 'Two factor authentication'
12
17
  submit: "Continue"
13
18
  otp_secrets:
14
19
  create:
@@ -19,6 +24,25 @@ en:
19
24
  description: "Are you sure you want to disable the two factor authentication of **%{name}**?"
20
25
  submit: "Confirm"
21
26
  success: "Two factor authentication is disabled"
27
+ errors:
28
+ invalid: "The authentication code is incorrect."
29
+ not_activated: "Two factor authentication is not yet activated."
30
+ already_exists: "Two factor authentication is already activated."
31
+ create:
32
+ success: "Welcome back!"
33
+ expired: "The request expired. Please try logging in again."
34
+ passwords:
35
+ create:
36
+ label: 'Send password reset link'
37
+ submit: "Send"
38
+ registrations:
39
+ create:
40
+ label: 'Register'
41
+ submit: "Continue"
42
+ sessions:
43
+ create:
44
+ label: 'Sign in or register'
45
+ submit: "Continue"
22
46
  devise:
23
47
  failure:
24
48
  invalid_email: 'We couldn''t find a user with this email.'
@@ -4,7 +4,7 @@ module LinkedRails
4
4
  module Auth
5
5
  module Errors
6
6
  class UnknownEmail < Doorkeeper::Errors::InvalidGrantReuse
7
- def initialize(_options = {})
7
+ def initialize(**_options)
8
8
  message = I18n.t('devise.failure.invalid_email')
9
9
  super(message)
10
10
  end
@@ -4,7 +4,7 @@ module LinkedRails
4
4
  module Auth
5
5
  module Errors
6
6
  class WrongPassword < Doorkeeper::Errors::InvalidGrantReuse
7
- def initialize(_options = {})
7
+ def initialize(**_options)
8
8
  message = I18n.t('devise.failure.invalid_password')
9
9
  super(message)
10
10
  end
@@ -22,43 +22,41 @@ module LinkedRails
22
22
  unlocks: 'linked_rails/auth/unlocks'
23
23
  }.freeze
24
24
 
25
- def use_linked_rails_auth(opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
26
- linked_rails_doorkeeper_routes(opts)
27
- linked_rails_device_routes(opts)
25
+ def use_linked_rails_auth(**opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
26
+ linked_rails_doorkeeper_routes(**opts)
27
+ linked_rails_device_routes(**opts)
28
28
 
29
29
  scope 'u' do
30
30
  get 'sign_in', to: redirect('/u/session/new')
31
31
  end
32
32
  devise_scope :user do
33
- auth_resource(AccessToken, opts)
34
- auth_resource(Confirmation, opts)
35
- auth_resource(OtpAttempt, opts)
36
- auth_resource(OtpSecret, opts)
33
+ auth_resource(LinkedRails.access_token_class, **opts)
34
+ auth_resource(LinkedRails.confirmation_class, **opts)
35
+ auth_resource(LinkedRails.otp_attempt_class, **opts)
36
+ auth_resource(LinkedRails.otp_secret_class, **opts)
37
37
  linked_resource(
38
- OtpSecret,
39
- controller: opts[:otp_secrets] || LINKED_RAILS_CONTROLLERS[:otp_secrets],
40
- nested: false
38
+ LinkedRails.otp_secret_class,
39
+ controller: opts[:otp_secrets] || LINKED_RAILS_CONTROLLERS[:otp_secrets]
41
40
  )
42
- auth_resource(Password, opts)
43
- auth_resource(Registration, opts)
44
- auth_resource(Session, opts)
45
- auth_resource(Unlock, opts)
41
+ auth_resource(LinkedRails.password_class, **opts)
42
+ auth_resource(LinkedRails.registration_class, **opts)
43
+ auth_resource(LinkedRails.session_class, **opts)
44
+ auth_resource(LinkedRails.unlock_class, **opts)
46
45
  end
47
46
  end
48
47
 
49
48
  private
50
49
 
51
- def auth_resource(klass, opts)
50
+ def auth_resource(klass, **opts)
52
51
  key = klass.name.demodulize.tableize.to_sym
53
52
 
54
53
  singular_linked_resource(
55
54
  klass,
56
- controller: opts[key] || LINKED_RAILS_CONTROLLERS[key],
57
- nested: false
55
+ controller: opts[key] || LINKED_RAILS_CONTROLLERS[key]
58
56
  )
59
57
  end
60
58
 
61
- def linked_rails_device_routes(opts)
59
+ def linked_rails_device_routes(**opts)
62
60
  devise_for(
63
61
  opts[:devise_scope] || :users,
64
62
  path: :u,
@@ -69,7 +67,7 @@ module LinkedRails
69
67
  )
70
68
  end
71
69
 
72
- def linked_rails_doorkeeper_routes(opts)
70
+ def linked_rails_doorkeeper_routes(**opts)
73
71
  use_doorkeeper do
74
72
  DOORKEEPER_CONTROLLERS.each do |linked_rails_key, doorkeeper_key|
75
73
  if opts.key?(linked_rails_key)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module LinkedRails
4
4
  module Auth
5
- VERSION = '0.0.2'
5
+ VERSION = '0.0.4'
6
6
  end
7
7
  end
@@ -20,27 +20,19 @@ end
20
20
  LinkedRails.configurable_class(nil, :user, default: 'User')
21
21
  LinkedRails.configurable_class(nil, :guest_user, default: 'LinkedRails::Auth::GuestUser')
22
22
  LinkedRails.configurable_class(nil, :access_token, default: 'LinkedRails::Auth::AccessToken')
23
- LinkedRails.configurable_class(nil, :access_token_action_list, default: 'LinkedRails::Auth::AccessTokenActionList')
24
23
  LinkedRails.configurable_class(nil, :access_token_form, default: 'LinkedRails::Auth::AccessTokenForm')
25
24
  LinkedRails.configurable_class(nil, :confirmation, default: 'LinkedRails::Auth::Confirmation')
26
- LinkedRails.configurable_class(nil, :confirmation_action_list, default: 'LinkedRails::Auth::ConfirmationActionList')
27
25
  LinkedRails.configurable_class(nil, :confirmation_form, default: 'LinkedRails::Auth::ConfirmationForm')
28
26
  LinkedRails.configurable_class(nil, :password, default: 'LinkedRails::Auth::Password')
29
- LinkedRails.configurable_class(nil, :password_action_list, default: 'LinkedRails::Auth::PasswordActionList')
30
27
  LinkedRails.configurable_class(nil, :password_form, default: 'LinkedRails::Auth::PasswordForm')
31
28
  LinkedRails.configurable_class(nil, :registration, default: 'LinkedRails::Auth::Registration')
32
- LinkedRails.configurable_class(nil, :registration_action_list, default: 'LinkedRails::Auth::RegistrationActionList')
33
29
  LinkedRails.configurable_class(nil, :registration_form, default: 'LinkedRails::Auth::RegistrationForm')
34
30
  LinkedRails.configurable_class(nil, :session, default: 'LinkedRails::Auth::Session')
35
- LinkedRails.configurable_class(nil, :session_action_list, default: 'LinkedRails::Auth::SessionActionList')
36
31
  LinkedRails.configurable_class(nil, :session_form, default: 'LinkedRails::Auth::SessionForm')
37
32
  LinkedRails.configurable_class(nil, :unlock, default: 'LinkedRails::Auth::Unlock')
38
- LinkedRails.configurable_class(nil, :unlock_action_list, default: 'LinkedRails::Auth::UnlockActionList')
39
33
  LinkedRails.configurable_class(nil, :unlock_form, default: 'LinkedRails::Auth::UnlockForm')
40
34
  LinkedRails.configurable_class(nil, :otp_attempt, default: 'LinkedRails::Auth::OtpAttempt')
41
- LinkedRails.configurable_class(nil, :otp_attempt_action_list, default: 'LinkedRails::Auth::OtpAttemptActionList')
42
35
  LinkedRails.configurable_class(nil, :otp_attempt_form, default: 'LinkedRails::Auth::OtpAttemptForm')
43
36
  LinkedRails.configurable_class(nil, :otp_owner, default: 'User')
44
37
  LinkedRails.configurable_class(nil, :otp_secret, default: 'LinkedRails::Auth::OtpSecret')
45
- LinkedRails.configurable_class(nil, :otp_secret_action_list, default: 'LinkedRails::Auth::OtpSecretActionList')
46
38
  LinkedRails.configurable_class(nil, :otp_secret_form, default: 'LinkedRails::Auth::OtpSecretForm')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linked_rails-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Dingemans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-26 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_otp
@@ -160,14 +160,6 @@ files:
160
160
  - LICENSE
161
161
  - README.md
162
162
  - Rakefile
163
- - app/actions/linked_rails/auth/access_token_action_list.rb
164
- - app/actions/linked_rails/auth/confirmation_action_list.rb
165
- - app/actions/linked_rails/auth/otp_attempt_action_list.rb
166
- - app/actions/linked_rails/auth/otp_secret_action_list.rb
167
- - app/actions/linked_rails/auth/password_action_list.rb
168
- - app/actions/linked_rails/auth/registration_action_list.rb
169
- - app/actions/linked_rails/auth/session_action_list.rb
170
- - app/actions/linked_rails/auth/unlock_action_list.rb
171
163
  - app/controllers/linked_rails/auth/access_tokens_controller.rb
172
164
  - app/controllers/linked_rails/auth/confirmations_controller.rb
173
165
  - app/controllers/linked_rails/auth/otp_attempts_controller.rb
@@ -250,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
242
  - !ruby/object:Gem::Version
251
243
  version: '0'
252
244
  requirements: []
253
- rubygems_version: 3.1.2
245
+ rubygems_version: 3.2.22
254
246
  signing_key:
255
247
  specification_version: 4
256
248
  summary: Easily use devise and doorkeeper in LinkedRails projects
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LinkedRails
4
- module Auth
5
- class AccessTokenActionList < LinkedRails.action_list_parent_class
6
- def self.actionable_class
7
- LinkedRails.access_token_class
8
- end
9
-
10
- has_singular_create_action(
11
- type: [Vocab.ontola['Create::Auth::AccessToken'], Vocab.schema.CreateAction],
12
- url: -> { LinkedRails.iri(path: '/login') }
13
- )
14
- end
15
- end
16
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LinkedRails
4
- module Auth
5
- class ConfirmationActionList < LinkedRails.action_list_parent_class
6
- def self.actionable_class
7
- LinkedRails.confirmation_class
8
- end
9
-
10
- has_singular_create_action(
11
- form: -> { resource.class.try(:form_class) },
12
- type: [Vocab.ontola['Create::Auth::Confirmation'], Vocab.schema.CreateAction]
13
- )
14
- has_singular_update_action(form: -> { nil })
15
- end
16
- end
17
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LinkedRails
4
- module Auth
5
- class OtpAttemptActionList < LinkedRails.action_list_parent_class
6
- def self.actionable_class
7
- LinkedRails.otp_attempt_class
8
- end
9
-
10
- has_singular_create_action(type: Vocab.schema[:CreateAction])
11
- end
12
- end
13
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LinkedRails
4
- module Auth
5
- class OtpSecretActionList < LinkedRails.action_list_parent_class
6
- def self.actionable_class
7
- LinkedRails.otp_secret_class
8
- end
9
-
10
- has_singular_create_action(
11
- type: Vocab.schema[:CreateAction],
12
- url: lambda {
13
- LinkedRails.iri(
14
- path: 'u/otp_secret',
15
- query: {session: resource.encoded_session}.compact.to_param.presence
16
- )
17
- },
18
- root_relative_iri: lambda {
19
- RDF::URI(
20
- path: '/u/otp_secret/new',
21
- query: {session: resource.encoded_session}.compact.to_param.presence
22
- )
23
- }
24
- )
25
-
26
- has_singular_destroy_action(
27
- description: -> { I18n.t('actions.otp_secrets.destroy.description', name: resource.owner.display_name) }
28
- )
29
- end
30
- end
31
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LinkedRails
4
- module Auth
5
- class PasswordActionList < LinkedRails.action_list_parent_class
6
- def self.actionable_class
7
- LinkedRails.password_class
8
- end
9
-
10
- has_singular_create_action(
11
- type: [Vocab.ontola['Create::Auth::Password'], Vocab.schema.CreateAction]
12
- )
13
-
14
- has_singular_update_action(
15
- label: nil,
16
- root_relative_iri: lambda {
17
- RDF::URI(
18
- path: '/u/password/edit',
19
- query: {reset_password_token: resource.reset_password_token}.compact.to_param.presence
20
- )
21
- }
22
- )
23
- end
24
- end
25
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LinkedRails
4
- module Auth
5
- class RegistrationActionList < LinkedRails.action_list_parent_class
6
- def self.actionable_class
7
- LinkedRails.registration_class
8
- end
9
-
10
- has_singular_create_action(
11
- root_relative_iri: '/u/registration/new'
12
- )
13
- end
14
- end
15
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LinkedRails
4
- module Auth
5
- class SessionActionList < LinkedRails.action_list_parent_class
6
- def self.actionable_class
7
- LinkedRails.session_class
8
- end
9
-
10
- has_singular_create_action(
11
- root_relative_iri: lambda {
12
- uri = resource.root_relative_iri.dup
13
- uri.path ||= ''
14
- uri.path += '/new'
15
- uri.query = {redirect_url: resource.redirect_url}.compact.to_param.presence
16
- uri.to_s
17
- },
18
- type: [Vocab.ontola['Create::Auth::Session'], Vocab.schema.CreateAction]
19
- )
20
- end
21
- end
22
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LinkedRails
4
- module Auth
5
- class UnlockActionList < LinkedRails.action_list_parent_class
6
- def self.actionable_class
7
- LinkedRails.unlock_class
8
- end
9
-
10
- has_singular_create_action(
11
- form: -> { resource.class.try(:form_class) }
12
- )
13
-
14
- has_singular_update_action
15
- end
16
- end
17
- end