devise_jwt_auth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +13 -0
  3. data/README.md +99 -0
  4. data/Rakefile +42 -0
  5. data/app/controllers/devise_jwt_auth/application_controller.rb +80 -0
  6. data/app/controllers/devise_jwt_auth/concerns/resource_finder.rb +44 -0
  7. data/app/controllers/devise_jwt_auth/concerns/set_user_by_jwt_token.rb +111 -0
  8. data/app/controllers/devise_jwt_auth/confirmations_controller.rb +88 -0
  9. data/app/controllers/devise_jwt_auth/omniauth_callbacks_controller.rb +291 -0
  10. data/app/controllers/devise_jwt_auth/passwords_controller.rb +217 -0
  11. data/app/controllers/devise_jwt_auth/refresh_token_controller.rb +41 -0
  12. data/app/controllers/devise_jwt_auth/registrations_controller.rb +203 -0
  13. data/app/controllers/devise_jwt_auth/sessions_controller.rb +131 -0
  14. data/app/controllers/devise_jwt_auth/unlocks_controller.rb +99 -0
  15. data/app/models/devise_jwt_auth/concerns/active_record_support.rb +16 -0
  16. data/app/models/devise_jwt_auth/concerns/confirmable_support.rb +27 -0
  17. data/app/models/devise_jwt_auth/concerns/mongoid_support.rb +19 -0
  18. data/app/models/devise_jwt_auth/concerns/tokens_serialization.rb +19 -0
  19. data/app/models/devise_jwt_auth/concerns/user.rb +117 -0
  20. data/app/models/devise_jwt_auth/concerns/user_omniauth_callbacks.rb +28 -0
  21. data/app/validators/devise_jwt_auth_email_validator.rb +23 -0
  22. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  23. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  24. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  25. data/app/views/devise_jwt_auth/omniauth_external_window.html.erb +38 -0
  26. data/config/locales/da-DK.yml +52 -0
  27. data/config/locales/de.yml +51 -0
  28. data/config/locales/en.yml +57 -0
  29. data/config/locales/es.yml +51 -0
  30. data/config/locales/fr.yml +51 -0
  31. data/config/locales/he.yml +52 -0
  32. data/config/locales/it.yml +48 -0
  33. data/config/locales/ja.yml +48 -0
  34. data/config/locales/ko.yml +51 -0
  35. data/config/locales/nl.yml +32 -0
  36. data/config/locales/pl.yml +50 -0
  37. data/config/locales/pt-BR.yml +48 -0
  38. data/config/locales/pt.yml +50 -0
  39. data/config/locales/ro.yml +48 -0
  40. data/config/locales/ru.yml +52 -0
  41. data/config/locales/sq.yml +48 -0
  42. data/config/locales/sv.yml +52 -0
  43. data/config/locales/uk.yml +61 -0
  44. data/config/locales/vi.yml +52 -0
  45. data/config/locales/zh-CN.yml +48 -0
  46. data/config/locales/zh-HK.yml +50 -0
  47. data/config/locales/zh-TW.yml +50 -0
  48. data/lib/devise_jwt_auth.rb +14 -0
  49. data/lib/devise_jwt_auth/blacklist.rb +2 -0
  50. data/lib/devise_jwt_auth/controllers/helpers.rb +161 -0
  51. data/lib/devise_jwt_auth/controllers/url_helpers.rb +10 -0
  52. data/lib/devise_jwt_auth/engine.rb +96 -0
  53. data/lib/devise_jwt_auth/errors.rb +8 -0
  54. data/lib/devise_jwt_auth/rails/routes.rb +118 -0
  55. data/lib/devise_jwt_auth/token_factory.rb +51 -0
  56. data/lib/devise_jwt_auth/url.rb +44 -0
  57. data/lib/devise_jwt_auth/version.rb +5 -0
  58. data/lib/generators/devise_jwt_auth/USAGE +31 -0
  59. data/lib/generators/devise_jwt_auth/install_generator.rb +91 -0
  60. data/lib/generators/devise_jwt_auth/install_generator_helpers.rb +98 -0
  61. data/lib/generators/devise_jwt_auth/install_mongoid_generator.rb +46 -0
  62. data/lib/generators/devise_jwt_auth/install_views_generator.rb +18 -0
  63. data/lib/generators/devise_jwt_auth/templates/devise_jwt_auth.rb +74 -0
  64. data/lib/generators/devise_jwt_auth/templates/devise_jwt_auth_create_users.rb.erb +51 -0
  65. data/lib/generators/devise_jwt_auth/templates/user.rb.erb +9 -0
  66. data/lib/generators/devise_jwt_auth/templates/user_mongoid.rb.erb +56 -0
  67. data/lib/tasks/devise_token_auth_tasks.rake +6 -0
  68. data/test/controllers/custom/custom_confirmations_controller_test.rb +25 -0
  69. data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +33 -0
  70. data/test/controllers/custom/custom_passwords_controller_test.rb +79 -0
  71. data/test/controllers/custom/custom_refresh_token_controller_test.rb +36 -0
  72. data/test/controllers/custom/custom_registrations_controller_test.rb +59 -0
  73. data/test/controllers/custom/custom_sessions_controller_test.rb +39 -0
  74. data/test/controllers/demo_group_controller_test.rb +150 -0
  75. data/test/controllers/demo_mang_controller_test.rb +286 -0
  76. data/test/controllers/demo_user_controller_test.rb +650 -0
  77. data/test/controllers/devise_jwt_auth/confirmations_controller_test.rb +194 -0
  78. data/test/controllers/devise_jwt_auth/omniauth_callbacks_controller_test.rb +462 -0
  79. data/test/controllers/devise_jwt_auth/passwords_controller_test.rb +881 -0
  80. data/test/controllers/devise_jwt_auth/refresh_token_controller_test.rb +84 -0
  81. data/test/controllers/devise_jwt_auth/registrations_controller_test.rb +944 -0
  82. data/test/controllers/devise_jwt_auth/sessions_controller_test.rb +510 -0
  83. data/test/controllers/devise_jwt_auth/unlocks_controller_test.rb +197 -0
  84. data/test/controllers/overrides/confirmations_controller_test.rb +47 -0
  85. data/test/controllers/overrides/omniauth_callbacks_controller_test.rb +53 -0
  86. data/test/controllers/overrides/passwords_controller_test.rb +65 -0
  87. data/test/controllers/overrides/refresh_token_controller_test.rb +37 -0
  88. data/test/controllers/overrides/registrations_controller_test.rb +47 -0
  89. data/test/controllers/overrides/sessions_controller_test.rb +35 -0
  90. data/test/dummy/README.rdoc +28 -0
  91. data/test/dummy/app/active_record/confirmable_user.rb +11 -0
  92. data/test/dummy/app/active_record/lockable_user.rb +7 -0
  93. data/test/dummy/app/active_record/mang.rb +5 -0
  94. data/test/dummy/app/active_record/only_email_user.rb +7 -0
  95. data/test/dummy/app/active_record/scoped_user.rb +9 -0
  96. data/test/dummy/app/active_record/unconfirmable_user.rb +9 -0
  97. data/test/dummy/app/active_record/unregisterable_user.rb +9 -0
  98. data/test/dummy/app/active_record/user.rb +6 -0
  99. data/test/dummy/app/controllers/application_controller.rb +18 -0
  100. data/test/dummy/app/controllers/auth_origin_controller.rb +7 -0
  101. data/test/dummy/app/controllers/custom/confirmations_controller.rb +13 -0
  102. data/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +13 -0
  103. data/test/dummy/app/controllers/custom/passwords_controller.rb +39 -0
  104. data/test/dummy/app/controllers/custom/refresh_token_controller.rb +20 -0
  105. data/test/dummy/app/controllers/custom/registrations_controller.rb +39 -0
  106. data/test/dummy/app/controllers/custom/sessions_controller.rb +29 -0
  107. data/test/dummy/app/controllers/demo_group_controller.rb +15 -0
  108. data/test/dummy/app/controllers/demo_mang_controller.rb +14 -0
  109. data/test/dummy/app/controllers/demo_user_controller.rb +27 -0
  110. data/test/dummy/app/controllers/overrides/confirmations_controller.rb +37 -0
  111. data/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +16 -0
  112. data/test/dummy/app/controllers/overrides/passwords_controller.rb +45 -0
  113. data/test/dummy/app/controllers/overrides/refresh_token_controller.rb +22 -0
  114. data/test/dummy/app/controllers/overrides/registrations_controller.rb +29 -0
  115. data/test/dummy/app/controllers/overrides/sessions_controller.rb +36 -0
  116. data/test/dummy/app/helpers/application_helper.rb +1058 -0
  117. data/test/dummy/app/models/concerns/favorite_color.rb +19 -0
  118. data/test/dummy/app/mongoid/confirmable_user.rb +52 -0
  119. data/test/dummy/app/mongoid/lockable_user.rb +38 -0
  120. data/test/dummy/app/mongoid/mang.rb +46 -0
  121. data/test/dummy/app/mongoid/only_email_user.rb +33 -0
  122. data/test/dummy/app/mongoid/scoped_user.rb +50 -0
  123. data/test/dummy/app/mongoid/unconfirmable_user.rb +44 -0
  124. data/test/dummy/app/mongoid/unregisterable_user.rb +47 -0
  125. data/test/dummy/app/mongoid/user.rb +49 -0
  126. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  127. data/test/dummy/config.ru +18 -0
  128. data/test/dummy/config/application.rb +48 -0
  129. data/test/dummy/config/application.yml.bk +0 -0
  130. data/test/dummy/config/boot.rb +11 -0
  131. data/test/dummy/config/environment.rb +7 -0
  132. data/test/dummy/config/environments/development.rb +46 -0
  133. data/test/dummy/config/environments/production.rb +84 -0
  134. data/test/dummy/config/environments/test.rb +50 -0
  135. data/test/dummy/config/initializers/assets.rb +10 -0
  136. data/test/dummy/config/initializers/backtrace_silencers.rb +9 -0
  137. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  138. data/test/dummy/config/initializers/devise.rb +290 -0
  139. data/test/dummy/config/initializers/devise_jwt_auth.rb +55 -0
  140. data/test/dummy/config/initializers/figaro.rb +3 -0
  141. data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  142. data/test/dummy/config/initializers/inflections.rb +18 -0
  143. data/test/dummy/config/initializers/mime_types.rb +6 -0
  144. data/test/dummy/config/initializers/omniauth.rb +11 -0
  145. data/test/dummy/config/initializers/session_store.rb +5 -0
  146. data/test/dummy/config/initializers/wrap_parameters.rb +16 -0
  147. data/test/dummy/config/routes.rb +57 -0
  148. data/test/dummy/config/spring.rb +3 -0
  149. data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +58 -0
  150. data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +57 -0
  151. data/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb +8 -0
  152. data/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb +7 -0
  153. data/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +55 -0
  154. data/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +56 -0
  155. data/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +56 -0
  156. data/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +56 -0
  157. data/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +56 -0
  158. data/test/dummy/db/migrate/20190924101113_devise_token_auth_create_confirmable_users.rb +49 -0
  159. data/test/dummy/db/schema.rb +198 -0
  160. data/test/dummy/lib/migration_database_helper.rb +43 -0
  161. data/test/dummy/tmp/generators/app/models/user.rb +9 -0
  162. data/test/dummy/tmp/generators/config/initializers/devise_jwt_auth.rb +74 -0
  163. data/test/dummy/tmp/generators/config/routes.rb +4 -0
  164. data/test/dummy/tmp/generators/db/migrate/20200206224309_devise_jwt_auth_create_users.rb +51 -0
  165. data/test/factories/users.rb +41 -0
  166. data/test/lib/devise_jwt_auth/blacklist_test.rb +11 -0
  167. data/test/lib/devise_jwt_auth/token_factory_test.rb +115 -0
  168. data/test/lib/devise_jwt_auth/url_test.rb +26 -0
  169. data/test/lib/generators/devise_jwt_auth/install_generator_test.rb +219 -0
  170. data/test/lib/generators/devise_jwt_auth/install_generator_with_namespace_test.rb +224 -0
  171. data/test/lib/generators/devise_jwt_auth/install_views_generator_test.rb +25 -0
  172. data/test/models/concerns/mongoid_support_test.rb +31 -0
  173. data/test/models/concerns/tokens_serialization_test.rb +72 -0
  174. data/test/models/confirmable_user_test.rb +35 -0
  175. data/test/models/only_email_user_test.rb +29 -0
  176. data/test/models/user_test.rb +110 -0
  177. data/test/support/controllers/routes.rb +43 -0
  178. data/test/test_helper.rb +91 -0
  179. metadata +503 -0
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeviseJwtAuth::Url
4
+
5
+ def self.generate(url, params = {})
6
+ uri = URI(url)
7
+
8
+ res = "#{uri.scheme}://#{uri.host}"
9
+ res += ":#{uri.port}" if (uri.port && uri.port != 80 && uri.port != 443)
10
+ res += uri.path.to_s if uri.path
11
+ query = [uri.query, params.to_query].reject(&:blank?).join('&')
12
+ res += "?#{query}"
13
+ res += "##{uri.fragment}" if uri.fragment
14
+ # repeat any query params after the fragment to deal with Angular eating any pre fragment query params, used
15
+ # in the reset password redirect url
16
+ res += "?#{query}" if uri.fragment
17
+
18
+ res
19
+ end
20
+
21
+ def self.whitelisted?(url)
22
+ url.nil? || \
23
+ !!DeviseJwtAuth.redirect_whitelist.find do |pattern|
24
+ !!Wildcat.new(pattern).match(url)
25
+ end
26
+ end
27
+
28
+ # wildcard convenience class
29
+ class Wildcat
30
+ def self.parse_to_regex(str)
31
+ escaped = Regexp.escape(str).gsub('\*','.*?')
32
+ Regexp.new("^#{escaped}$", Regexp::IGNORECASE)
33
+ end
34
+
35
+ def initialize(str)
36
+ @regex = self.class.parse_to_regex(str)
37
+ end
38
+
39
+ def match(str)
40
+ !!@regex.match(str)
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeviseJwtAuth
4
+ VERSION = '0.1.0'.freeze
5
+ end
@@ -0,0 +1,31 @@
1
+ Description:
2
+ This generator will install all the necessary configuration and migration
3
+ files for the devise_jwt_auth gem. See
4
+ https://github.com/lynndylanhurley/devise_jwt_auth for more information.
5
+
6
+ Arguments:
7
+ USER_CLASS # The name of the class to use for user authentication. Default is
8
+ # 'User'
9
+ MOUNT_PATH # The path at which to mount the authentication routes. Default is
10
+ # 'auth'. More detail documentation is here:
11
+ # https://devise-token-auth.gitbook.io/devise-token-auth/usage
12
+
13
+ Example:
14
+ rails generate devise_jwt_auth:install User auth
15
+
16
+ This will create:
17
+ config/initializers/devise_jwt_auth.rb
18
+ db/migrate/<%= Time.zone.now.utc.strftime("%Y%m%d%H%M%S") %>_create_devise_jwt_auth_create_users.rb
19
+ app/models/user.rb
20
+
21
+ If 'app/models/user.rb' already exists, the following line will be inserted
22
+ after the class definition:
23
+ include DeviseJwtAuth::Concerns::User
24
+
25
+ The following line will be inserted into your application controller at
26
+ app/controllers/application_controller.rb:
27
+ include DeviseJwtAuth::Concerns::SetUserByToken
28
+
29
+ The following line will be inserted at the top of 'config/routes.rb' if it
30
+ does not already exist:
31
+ mount_devise_jwt_auth_for "User", at: 'auth'
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'install_generator_helpers'
4
+
5
+ module DeviseJwtAuth
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+ include DeviseJwtAuth::InstallGeneratorHelpers
9
+
10
+ class_option :primary_key_type, type: :string, desc: 'The type for primary key'
11
+
12
+ def copy_migrations
13
+ if self.class.migration_exists?('db/migrate', "devise_jwt_auth_create_#{user_class.pluralize.gsub('::','').underscore}")
14
+ say_status('skipped', "Migration 'devise_jwt_auth_create_#{user_class.pluralize.gsub('::','').underscore}' already exists")
15
+ else
16
+ migration_template(
17
+ 'devise_jwt_auth_create_users.rb.erb',
18
+ "db/migrate/devise_jwt_auth_create_#{user_class.pluralize.gsub('::','').underscore}.rb"
19
+ )
20
+ end
21
+ end
22
+
23
+ def create_user_model
24
+ fname = "app/models/#{user_class.underscore}.rb"
25
+ if File.exist?(File.join(destination_root, fname))
26
+ inclusion = 'include DeviseJwtAuth::Concerns::User'
27
+ unless parse_file_for_line(fname, inclusion)
28
+
29
+ active_record_needle = (Rails::VERSION::MAJOR == 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
30
+ inject_into_file fname, after: "class #{user_class} < #{active_record_needle}\n" do <<-'RUBY'
31
+ # Include default devise modules.
32
+ devise :database_authenticatable, :registerable,
33
+ :recoverable, :rememberable, :trackable, :validatable,
34
+ :confirmable, :omniauthable
35
+ include DeviseJwtAuth::Concerns::User
36
+ RUBY
37
+ end
38
+ end
39
+ else
40
+ template('user.rb.erb', fname)
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def self.next_migration_number(path)
47
+ Time.zone.now.utc.strftime('%Y%m%d%H%M%S')
48
+ end
49
+
50
+ def json_supported_database?
51
+ (postgres? && postgres_correct_version?) || (mysql? && mysql_correct_version?)
52
+ end
53
+
54
+ def postgres?
55
+ database_name == 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
56
+ end
57
+
58
+ def postgres_correct_version?
59
+ database_version > '9.3'
60
+ end
61
+
62
+ def mysql?
63
+ database_name == 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
64
+ end
65
+
66
+ def mysql_correct_version?
67
+ database_version > '5.7.7'
68
+ end
69
+
70
+ def database_name
71
+ ActiveRecord::Base.connection.class.name
72
+ end
73
+
74
+ def database_version
75
+ ActiveRecord::Base.connection.select_value('SELECT VERSION()')
76
+ end
77
+
78
+ def rails5?
79
+ Rails.version.start_with? '5'
80
+ end
81
+
82
+ def primary_key_type
83
+ primary_key_string if rails5?
84
+ end
85
+
86
+ def primary_key_string
87
+ key_string = options[:primary_key_type]
88
+ ", id: :#{key_string}" if key_string
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,98 @@
1
+ module DeviseJwtAuth
2
+ module InstallGeneratorHelpers
3
+ class << self
4
+ def included(mod)
5
+ mod.class_eval do
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ argument :user_class, type: :string, default: 'User'
9
+ argument :mount_path, type: :string, default: 'auth'
10
+
11
+ def create_initializer_file
12
+ copy_file('devise_jwt_auth.rb', 'config/initializers/devise_jwt_auth.rb')
13
+ end
14
+
15
+ def include_controller_concerns
16
+ fname = 'app/controllers/application_controller.rb'
17
+ line = 'include DeviseJwtAuth::Concerns::SetUserByToken'
18
+
19
+ if File.exist?(File.join(destination_root, fname))
20
+ if parse_file_for_line(fname, line)
21
+ say_status('skipped', 'Concern is already included in the application controller.')
22
+ elsif is_rails_api?
23
+ inject_into_file fname, after: "class ApplicationController < ActionController::API\n" do <<-'RUBY'
24
+ include DeviseJwtAuth::Concerns::SetUserByToken
25
+ RUBY
26
+ end
27
+ else
28
+ inject_into_file fname, after: "class ApplicationController < ActionController::Base\n" do <<-'RUBY'
29
+ include DeviseJwtAuth::Concerns::SetUserByToken
30
+ RUBY
31
+ end
32
+ end
33
+ else
34
+ say_status('skipped', "app/controllers/application_controller.rb not found. Add 'include DeviseJwtAuth::Concerns::SetUserByToken' to any controllers that require authentication.")
35
+ end
36
+ end
37
+
38
+ def add_route_mount
39
+ f = 'config/routes.rb'
40
+ str = "mount_devise_jwt_auth_for '#{user_class}', at: '#{mount_path}'"
41
+
42
+ if File.exist?(File.join(destination_root, f))
43
+ line = parse_file_for_line(f, 'mount_devise_jwt_auth_for')
44
+
45
+ if line
46
+ existing_user_class = true
47
+ else
48
+ line = 'Rails.application.routes.draw do'
49
+ existing_user_class = false
50
+ end
51
+
52
+ if parse_file_for_line(f, str)
53
+ say_status('skipped', "Routes already exist for #{user_class} at #{mount_path}")
54
+ else
55
+ insert_after_line(f, line, str)
56
+
57
+ if existing_user_class
58
+ scoped_routes = ''\
59
+ "as :#{user_class.underscore} do\n"\
60
+ " # Define routes for #{user_class} within this block.\n"\
61
+ " end\n"
62
+ insert_after_line(f, str, scoped_routes)
63
+ end
64
+ end
65
+ else
66
+ say_status('skipped', "config/routes.rb not found. Add \"mount_devise_jwt_auth_for '#{user_class}', at: '#{mount_path}'\" to your routes file.")
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def insert_after_line(filename, line, str)
73
+ gsub_file filename, /(#{Regexp.escape(line)})/mi do |match|
74
+ "#{match}\n #{str}"
75
+ end
76
+ end
77
+
78
+ def parse_file_for_line(filename, str)
79
+ match = false
80
+
81
+ File.open(File.join(destination_root, filename)) do |f|
82
+ f.each_line do |line|
83
+ match = line if line =~ /(#{Regexp.escape(str)})/mi
84
+ end
85
+ end
86
+ match
87
+ end
88
+
89
+ def is_rails_api?
90
+ fname = 'app/controllers/application_controller.rb'
91
+ line = 'class ApplicationController < ActionController::API'
92
+ parse_file_for_line(fname, line)
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'install_generator_helpers'
4
+
5
+ module DeviseJwtAuth
6
+ class InstallMongoidGenerator < Rails::Generators::Base
7
+ include DeviseJwtAuth::InstallGeneratorHelpers
8
+
9
+ def create_user_model
10
+ fname = "app/models/#{user_class.underscore}.rb"
11
+ if File.exist?(File.join(destination_root, fname))
12
+ inclusion = 'include DeviseJwtAuth::Concerns::User'
13
+ unless parse_file_for_line(fname, inclusion)
14
+ inject_into_file fname, before: /end\s\z/ do <<-'RUBY'
15
+
16
+ include Mongoid::Locker
17
+
18
+ field :locker_locked_at, type: Time
19
+ field :locker_locked_until, type: Time
20
+
21
+ locker locked_at_field: :locker_locked_at,
22
+ locked_until_field: :locker_locked_until
23
+
24
+ ## Required
25
+ field :provider, type: String
26
+ field :uid, type: String, default: ''
27
+
28
+ ## Tokens
29
+ field :tokens, type: Hash, default: {}
30
+
31
+ # Include default devise modules. Others available are:
32
+ # :confirmable, :lockable, :timeoutable and :omniauthable
33
+ devise :database_authenticatable, :registerable,
34
+ :recoverable, :rememberable, :trackable, :validatable
35
+ include DeviseJwtAuth::Concerns::User
36
+
37
+ index({ uid: 1, provider: 1}, { name: 'uid_provider_index', unique: true, background: true })
38
+ RUBY
39
+ end
40
+ end
41
+ else
42
+ template('user_mongoid.rb.erb', fname)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeviseJwtAuth
4
+ class InstallViewsGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../../app/views/devise/mailer', __dir__)
6
+
7
+ def copy_mailer_templates
8
+ copy_file(
9
+ 'confirmation_instructions.html.erb',
10
+ 'app/views/devise/mailer/confirmation_instructions.html.erb'
11
+ )
12
+ copy_file(
13
+ 'reset_password_instructions.html.erb',
14
+ 'app/views/devise/mailer/reset_password_instructions.html.erb'
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ DeviseJwtAuth.setup do |config|
4
+ # By default, you will only receive an access token when authenticating a
5
+ # user. To receive new access tokens, you should either reauthenticate or
6
+ # use the HTTP only refresh cookie that is sent during the authentication
7
+ # process and make refresh token requests.
8
+ # self.send_new_access_token_on_each_request = false
9
+
10
+ # By default, refresh token HTTP Only cookies last for 2 weeks. These tokens
11
+ # are used for requesting shorter-lived acccess tokens.
12
+ # self.refresh_token_lifespan = 2.weeks
13
+
14
+ # By default, access tokens last for 15 minutes. These tokens are used to
15
+ # access protected resources. When these tokens expire, you need to
16
+ # reauthenticate the user or use a refresh token cookie to get a new access
17
+ # token.
18
+ # self.access_token_lifespan = 15.minutes
19
+
20
+ # This is the name of the HTTP Only cookie that will be sent to the client
21
+ # for the purpose of requesting new access tokens.
22
+ # self.refresh_token_name = 'refresh-token'
23
+
24
+ # This is the name of the token that will be sent in the JSON responses used
25
+ # for accessing protected resources. NEVER store this token in a cookie or
26
+ # any form of local storage on the client. Save it in memory as a javascript
27
+ # variable or in some kind of context manager like Redux. Send it in your
28
+ # request headers when you want to be authenticated.
29
+ # self.access_token_name = 'access-token'
30
+
31
+ # This is the refresh token encryption key. You should set this in an
32
+ # environment variable or secret key base that isn't store in a repository.
33
+ # Also, its a good idea to NOT use the same key for access tokens.
34
+ self.refresh_token_encryption_key = 'your-refresh-token-secret-key-here'
35
+
36
+ # This is the refresh token encryption key. You should set this in an
37
+ # environment variable or secret key base that isn't store in a repository.
38
+ # Also, its a good idea to NOT use the same key for access tokens.
39
+ self.access_token_encryption_key = 'your-access-token-secret-key-here'
40
+
41
+ # This route will be the prefix for all oauth2 redirect callbacks. For
42
+ # example, using the default '/omniauth', the github oauth2 provider will
43
+ # redirect successful authentications to '/omniauth/github/callback'
44
+ # config.omniauth_prefix = "/omniauth"
45
+
46
+ # By default sending current password is not needed for the password update.
47
+ # Uncomment to enforce current_password param to be checked before all
48
+ # attribute updates. Set it to :password if you want it to be checked only if
49
+ # password is updated.
50
+ # config.check_current_password_before_update = :attributes
51
+
52
+ # By default we will use callbacks for single omniauth.
53
+ # It depends on fields like email, provider and uid.
54
+ # config.default_callbacks = true
55
+
56
+ # By default, only Bearer Token authentication is implemented out of the box.
57
+ # If, however, you wish to integrate with legacy Devise authentication, you can
58
+ # do so by enabling this flag. NOTE: This feature is highly experimental!
59
+ # config.enable_standard_devise_support = false
60
+
61
+ # By default DeviseJwtAuth will not send confirmation email, even when including
62
+ # devise confirmable module. If you want to use devise confirmable module and
63
+ # send email, set it to true. (This is a setting for compatibility)
64
+ # config.send_confirmation_email = true
65
+
66
+ # TODO: Document these settings
67
+ # self.default_confirm_success_url = nil
68
+ # self.default_password_reset_url = nil
69
+ # self.redirect_whitelist = nil
70
+ # self.update_token_version_after_password_reset = true
71
+ # self.bypass_sign_in = true
72
+ # self.require_client_password_reset_token = false
73
+
74
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DeviseJwtAuthCreate<%= user_class.pluralize.gsub("::","") %> < ActiveRecord::Migration<%= "[#{Rails::VERSION::STRING[0..2]}]" if Rails::VERSION::MAJOR > 4 %>
4
+ def change
5
+ <% table_name = @user_class.pluralize.gsub("::","").underscore %>
6
+ create_table(:<%= table_name %><%= primary_key_type %>) do |t|
7
+ ## Required
8
+ t.string :provider, null: false, default: 'email'
9
+ t.string :uid, null: false, default: ''
10
+
11
+ ## Database authenticatable
12
+ t.string :encrypted_password, null: false, default: ''
13
+
14
+ ## Recoverable
15
+ t.string :reset_password_token
16
+ t.datetime :reset_password_sent_at
17
+ t.boolean :allow_password_change, default: false
18
+
19
+ ## Rememberable
20
+ t.datetime :remember_created_at
21
+
22
+ ## Confirmable
23
+ t.string :confirmation_token
24
+ t.datetime :confirmed_at
25
+ t.datetime :confirmation_sent_at
26
+ t.string :unconfirmed_email # Only if using reconfirmable
27
+
28
+ ## Lockable
29
+ # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
30
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
31
+ # t.datetime :locked_at
32
+
33
+ ## User Info
34
+ t.string :name
35
+ t.string :nickname
36
+ t.string :image
37
+ t.string :email
38
+
39
+ ## Tokens
40
+ <%= json_supported_database? ? 't.json :tokens' : 't.text :tokens' %>
41
+
42
+ t.timestamps
43
+ end
44
+
45
+ add_index :<%= table_name %>, :email, unique: true
46
+ add_index :<%= table_name %>, [:uid, :provider], unique: true
47
+ add_index :<%= table_name %>, :reset_password_token, unique: true
48
+ add_index :<%= table_name %>, :confirmation_token, unique: true
49
+ # add_index :<%= table_name %>, :unlock_token, unique: true
50
+ end
51
+ end