its-ruby-auth 0.0.1

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 (49) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +7 -0
  5. data/app/controllers/ibrain/social_callbacks_controller.rb +58 -0
  6. data/app/graphql/ibrain/mutations/auth_mutation.rb +218 -0
  7. data/app/graphql/ibrain/mutations/generate_firebase_token_mutation.rb +35 -0
  8. data/app/graphql/ibrain/mutations/sign_in_mutation.rb +74 -0
  9. data/app/graphql/ibrain/mutations/sign_out_mutation.rb +16 -0
  10. data/app/graphql/ibrain/mutations/sign_up_mutation.rb +61 -0
  11. data/app/graphql/ibrain/mutations/social_sign_in_mutation.rb +71 -0
  12. data/app/graphql/ibrain/types/input/generate_firebase_token_input.rb +13 -0
  13. data/app/graphql/ibrain/types/input/sign_in_input.rb +12 -0
  14. data/app/graphql/ibrain/types/input/sign_up_input.rb +17 -0
  15. data/app/graphql/ibrain/types/input/social_login_input.rb +11 -0
  16. data/app/graphql/ibrain/types/input/social_sign_in_input.rb +11 -0
  17. data/app/models/ibrain/user.rb +88 -0
  18. data/app/repositories/apple_repository.rb +17 -0
  19. data/app/repositories/auth_repository.rb +102 -0
  20. data/app/repositories/firebase_repository.rb +69 -0
  21. data/app/repositories/line_repository.rb +57 -0
  22. data/config/initializers/devise.rb +314 -0
  23. data/config/initializers/ibrain_jwt_expiration.rb +9 -0
  24. data/config/locales/en.yml +17 -0
  25. data/config/locales/ja.yml +17 -0
  26. data/config/locales/vi.yml +17 -0
  27. data/config/routes.rb +20 -0
  28. data/lib/controllers/ibrain/user_confirmations_controller.rb +30 -0
  29. data/lib/controllers/ibrain/user_passwords_controller.rb +34 -0
  30. data/lib/controllers/ibrain/user_registrations_controller.rb +75 -0
  31. data/lib/controllers/ibrain/user_sessions_controller.rb +58 -0
  32. data/lib/controllers/ibrain/user_unlocks_controller.rb +30 -0
  33. data/lib/generators/ibrain/auth/install/install_generator.rb +34 -0
  34. data/lib/generators/ibrain/auth/install/templates/config/initializers/devise.rb.tt +311 -0
  35. data/lib/generators/ibrain/auth/install/templates/config/initializers/ibrain_auth.rb.tt +43 -0
  36. data/lib/generators/ibrain/auth/install/templates/config/initializers/ibrain_jwt.rb.tt +13 -0
  37. data/lib/generators/ibrain/auth/install/templates/config/initializers/omniauth.rb.tt +25 -0
  38. data/lib/generators/ibrain/auth/install/templates/db/schemas/users_migrate.erb +39 -0
  39. data/lib/generators/ibrain/auth/install/templates/db/schemas/users_schema.erb +37 -0
  40. data/lib/ibrain/auth/devise.rb +16 -0
  41. data/lib/ibrain/auth/engine.rb +42 -0
  42. data/lib/ibrain/auth/failure_app.rb +27 -0
  43. data/lib/ibrain/auth/version.rb +17 -0
  44. data/lib/ibrain/auth.rb +17 -0
  45. data/lib/ibrain/auth_configuration.rb +45 -0
  46. data/lib/ibrain/authentication_helpers.rb +13 -0
  47. data/lib/ibrain_auth.rb +9 -0
  48. data/lib/tasks/ibrain/auth_tasks.rake +5 -0
  49. metadata +287 -0
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ class User < Ibrain::Base
5
+ attr_accessor :jwt_token
6
+
7
+ include Devise::JWT::RevocationStrategies::JTIMatcher
8
+
9
+ self.abstract_class = true
10
+ self.table_name = Ibrain::Auth::Config.user_table_name
11
+
12
+ devise(*Ibrain::Auth::Config.devise_enabled_modules, jwt_revocation_strategy: self, omniauth_providers: Ibrain::Auth::Config.devise_omniauth_providers)
13
+
14
+ scope :find_by_line, ->(uid) {
15
+ find_by(uid: uid, provider: 'line')
16
+ }
17
+
18
+ scope :find_by_apple, ->(uid) {
19
+ find_by(uid: uid, provider: 'apple')
20
+ }
21
+
22
+ def jwt_payload
23
+ # for hasura
24
+ hasura_keys = {
25
+ 'https://hasura.io/jwt/claims': {
26
+ 'x-hasura-allowed-roles': Ibrain.user_class.roles.keys,
27
+ 'x-hasura-default-role': role,
28
+ 'x-hasura-user-id': id.to_s
29
+ }
30
+ }
31
+
32
+ super.merge(
33
+ {
34
+ 'role' => role,
35
+ 'exp' => determine_expiration
36
+ }, hasura_keys)
37
+ end
38
+
39
+ def can_skip_confirmation?
40
+ try(:is_admin?) || email.blank?
41
+ end
42
+
43
+ class << self
44
+ def ibrain_find(params, available_columns)
45
+ matched_value = params[:username] || params[:email]
46
+
47
+ if matched_value.present?
48
+ query = available_columns.map do |column_name|
49
+ <<~RUBY
50
+ #{column_name} = '#{matched_value}'
51
+ RUBY
52
+ end.join(' OR ')
53
+
54
+ where(query).first
55
+ end
56
+ end
57
+
58
+ def social_find_or_initialize(params)
59
+ user = find_by(provider: params[:provider], uid: params[:uid])
60
+ return user if user.present?
61
+
62
+ create!(params)
63
+ end
64
+
65
+ def create_with_line!(params)
66
+ user = created!({
67
+ uid: params['uid'],
68
+ provider: 'line',
69
+ remote_avatar_url: params['info']['image']
70
+ })
71
+
72
+ user.skip_confirmation! unless user&.confirmed?
73
+ user
74
+ end
75
+
76
+ def random_password
77
+ (('A'..'Z').to_a.sample(4) + ["~", "!", "@", "#", "$", "%", "^", "&", "*", "_", "-"].sample(1) + ('0'..'9').to_a.sample(2) + ('a'..'z').to_a.sample(4)).join
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def determine_expiration
84
+ expiration_time = IbrainJwtExpiration.expiration_time[role] || IbrainJwtExpiration.expiration_time['default']
85
+ expiration_time.from_now.to_i
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AppleRepository < Ibrain::BaseRepository
4
+ def initialize(record, params)
5
+ super(nil, record)
6
+
7
+ @params = params
8
+ @collection = Ibrain.user_class
9
+ end
10
+
11
+ def find_or_initialize!
12
+ user = @collection.find_by_apple(uid: params['uid'])
13
+ return user if user.present?
14
+
15
+ @collection.create_with_line!
16
+ end
17
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ ACCOUNT_COUMNS = %w[username email phone phone_number]
4
+
5
+ class AuthRepository < Ibrain::BaseRepository
6
+ def initialize(record, params)
7
+ super(nil, record)
8
+
9
+ @params = params
10
+ @collection = Ibrain.user_class
11
+ end
12
+
13
+ def create
14
+ user = collection.new(provider: 'manual')
15
+ user.assign_attributes(normalize_params.except(:id_token))
16
+ user.save!
17
+
18
+ user
19
+ end
20
+
21
+ def sign_in
22
+ return firebase_verify if is_social?
23
+
24
+ user = collection.ibrain_find(manual_params, available_columns)
25
+ return unless user.try(:valid_password?, manual_params[:password])
26
+
27
+ user
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :params, :collection
33
+
34
+ def firebase_url
35
+ "https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo?key=#{firebase_api_key}"
36
+ end
37
+
38
+ def firebase_update_url
39
+ "https://identitytoolkit.googleapis.com/v1/accounts:update?key=#{firebase_api_key}"
40
+ end
41
+
42
+ def firebase_api_key
43
+ Ibrain::Auth::Config.firebase_api_key
44
+ end
45
+
46
+ def base_headers
47
+ {
48
+ 'Content-Type' => 'application/json'
49
+ }
50
+ end
51
+
52
+ def normalize_params
53
+ params.permit(permitted_attributes)
54
+ end
55
+
56
+ def manual_params
57
+ params.permit(:username, :password)
58
+ end
59
+
60
+ def firebase_verify
61
+ response = HTTParty.post(firebase_url, headers: base_headers, body: { 'idToken' => normalize_params[:id_token] }.to_json )
62
+ user_information = response.try(:fetch, 'users', []).try(:at, 0)
63
+
64
+ uid = user_information.try(:fetch, 'localId', nil)
65
+ provider = user_information.
66
+ try(:fetch, 'providerUserInfo', []).
67
+ try(:at, 0).try(:fetch, 'providerId', '').
68
+ try(:gsub, '.com', '')
69
+ raise ActionController::InvalidAuthenticityToken, I18n.t('ibrain.errors.account.not_found') if uid.blank?
70
+
71
+ provider = 'custom' if user_information.try(:fetch, 'customAuth', false) && provider.blank?
72
+
73
+ collection.social_find_or_initialize({
74
+ uid: uid,
75
+ provider: provider,
76
+ remote_avatar_url: user_information.try(:fetch, 'photoUrl', nil),
77
+ email: user_information.try(:fetch, 'email', nil),
78
+ password: collection.random_password
79
+ })
80
+ end
81
+
82
+ def available_columns
83
+ collection.column_names.select { |f| ACCOUNT_COUMNS.include?(f) }
84
+ end
85
+
86
+ def is_social?
87
+ normalize_params[:id_token].present?
88
+ end
89
+
90
+ def permitted_attributes
91
+ Ibrain.user_class.permitted_attributes.reject { |k| permintted_columns.include?(k) }.map(&:to_sym).concat([:id_token]).concat([:password])
92
+ end
93
+
94
+ def permintted_columns
95
+ %w[
96
+ reset_password_token reset_password_sent_at
97
+ remember_created_at sign_in_count uid jti
98
+ current_sign_in_at last_sign_in_at current_sign_in_ip
99
+ last_sign_in_ip role encrypted_password id_token
100
+ ]
101
+ end
102
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open-uri'
4
+
5
+ class FirebaseRepository < Ibrain::BaseRepository
6
+ def initialize(record, params)
7
+ super(nil, record)
8
+
9
+ @private_key_json = load_private_file
10
+ @firebase_owner_email = Ibrain::Auth::Config.firebase_owner_email
11
+ @params = params
12
+ end
13
+
14
+ def generate_custom_token!
15
+ iat = Time.now.to_i
16
+ exp = 60.minutes.from_now.to_i
17
+ uid = retrieve_uid_execution
18
+
19
+ raise IbrainErrors::UnknownError.new I18n.t("ibrain.errors.custom_token.not_retrieve_uid") unless uid
20
+
21
+ payload = {
22
+ iss: firebase_owner_email,
23
+ sub: firebase_owner_email,
24
+ aud: Ibrain::Auth::Config.firebase_auth_url,
25
+ iat: iat,
26
+ exp: exp,
27
+ uid: uid,
28
+ claims: {}
29
+ }
30
+
31
+ JWT.encode payload, private_key, "RS256"
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :private_key_json, :firebase_owner_email, :params
37
+
38
+ def json_firebase
39
+ JSON.parse(private_key_json, symbolize_names: true)
40
+ end
41
+
42
+ def private_key
43
+ OpenSSL::PKey::RSA.new json_firebase[:private_key]
44
+ end
45
+
46
+ def load_private_file
47
+ is_remote = Ibrain::Auth::Config.firebase_private_key_path.include?("http")
48
+
49
+ if is_remote
50
+ uri = URI.parse(Ibrain::Auth::Config.firebase_private_key_path)
51
+ content = uri.open { |f| f.read }
52
+
53
+ return content
54
+ end
55
+
56
+ File.open(Ibrain::Auth::Config.firebase_private_key_path).read
57
+ end
58
+
59
+ def retrieve_uid_execution
60
+ if params[:access_token].present?
61
+ return LineRepository.singleton.retrieve_uid_by_access_token(access_token: params[:access_token])
62
+ end
63
+
64
+ LineRepository.singleton.retrieve_uid(
65
+ code: params[:code],
66
+ redirect_uri: params[:redirect_uri]
67
+ )
68
+ end
69
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ class LineRepository
4
+ LINE_BASE_HEADERS = {
5
+ 'Content-Type': "application/x-www-form-urlencoded"
6
+ }.freeze
7
+
8
+ LINE_TOKEN_URL = "https://api.line.me/oauth2/v2.1/token"
9
+ LINE_INFORMATION_URL = "https://api.line.me/v2/profile"
10
+
11
+ def self.singleton
12
+ @singleton ||= new
13
+ end
14
+
15
+ def retrieve_access_token(redirect_uri:, code:)
16
+ response = HTTParty.post(
17
+ LINE_TOKEN_URL,
18
+ headers: LINE_BASE_HEADERS,
19
+ body: URI.encode_www_form({
20
+ grant_type: "authorization_code",
21
+ code: code,
22
+ redirect_uri: redirect_uri,
23
+ client_id: Ibrain::Auth::Config.line_client_id,
24
+ client_secret: Ibrain::Auth::Config.line_client_secret
25
+ })
26
+ )
27
+
28
+ response.try(:fetch, "access_token", nil)
29
+ end
30
+
31
+ def retrieve_uid(redirect_uri:, code:)
32
+ token = retrieve_access_token(
33
+ redirect_uri: redirect_uri,
34
+ code: code
35
+ )
36
+
37
+ response = HTTParty.get(
38
+ LINE_INFORMATION_URL,
39
+ headers: LINE_BASE_HEADERS.merge({
40
+ 'Authorization' => "Bearer #{token}"
41
+ })
42
+ )
43
+
44
+ response.try(:fetch, 'userId', nil)
45
+ end
46
+
47
+ def retrieve_uid_by_access_token(access_token:)
48
+ response = HTTParty.get(
49
+ LINE_INFORMATION_URL,
50
+ headers: LINE_BASE_HEADERS.merge({
51
+ 'Authorization' => "Bearer #{access_token}"
52
+ })
53
+ )
54
+
55
+ response.try(:fetch, 'userId', nil)
56
+ end
57
+ end
@@ -0,0 +1,314 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Assuming you have not yet modified this file, each configuration option below
4
+ # is set to its default value. Note that some are commented out while others
5
+ # are not: uncommented lines are intended to protect your configuration from
6
+ # breaking changes in upgrades (i.e., in the event that future versions of
7
+ # Devise change the default values for those options).
8
+ #
9
+ # Use this hook to configure devise mailer, warden hooks and so forth.
10
+ # Many of these configuration options can be set straight in your model.
11
+ Devise.setup do |config|
12
+ # The secret key used by Devise. Devise uses this key to generate
13
+ # random tokens. Changing this key will render invalid all existing
14
+ # confirmation, reset password and unlock tokens in the database.
15
+ # Devise will use the `secret_key_base` as its `secret_key`
16
+ # by default. You can change it below and use your own secret key.
17
+ config.secret_key = SecureRandom.hex(50).inspect
18
+
19
+ # ==> Controller configuration
20
+ # Configure the parent class to the devise controllers.
21
+ # config.parent_controller = 'DeviseController'
22
+
23
+ # ==> Mailer Configuration
24
+ # Configure the e-mail address which will be shown in Devise::Mailer,
25
+ # note that it will be overwritten if you use your own mailer class
26
+ # with default "from" parameter.
27
+ config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
28
+
29
+ # Configure the class responsible to send e-mails.
30
+ # config.mailer = 'Devise::Mailer'
31
+
32
+ # Configure the parent class responsible to send e-mails.
33
+ # config.parent_mailer = 'ActionMailer::Base'
34
+
35
+ # ==> ORM configuration
36
+ # Load and configure the ORM. Supports :active_record (default) and
37
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
38
+ # available as additional gems.
39
+ require 'devise/orm/active_record'
40
+
41
+ # ==> Configuration for any authentication mechanism
42
+ # Configure which keys are used when authenticating a user. The default is
43
+ # just :email. You can configure it to use [:username, :subdomain], so for
44
+ # authenticating a user, both parameters are required. Remember that those
45
+ # parameters are used only when authenticating and not when retrieving from
46
+ # session. If you need permissions, you should implement that in a before filter.
47
+ # You can also supply a hash where the value is a boolean determining whether
48
+ # or not authentication should be aborted when the value is not present.
49
+ config.authentication_keys = [:username, :email]
50
+
51
+ # Configure parameters from the request object used for authentication. Each entry
52
+ # given should be a request method and it will automatically be passed to the
53
+ # find_for_authentication method and considered in your model lookup. For instance,
54
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
55
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
56
+ # config.request_keys = []
57
+
58
+ # Configure which authentication keys should be case-insensitive.
59
+ # These keys will be downcased upon creating or modifying a user and when used
60
+ # to authenticate or find a user. Default is :username.
61
+ config.case_insensitive_keys = [:username, :email]
62
+
63
+ # Configure which authentication keys should have whitespace stripped.
64
+ # These keys will have whitespace before and after removed upon creating or
65
+ # modifying a user and when used to authenticate or find a user. Default is :username.
66
+ config.strip_whitespace_keys = [:username, :email]
67
+
68
+ # Tell if authentication through request.params is enabled. True by default.
69
+ # It can be set to an array that will enable params authentication only for the
70
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
71
+ # enable it only for database (email + password) authentication.
72
+ # config.params_authenticatable = true
73
+
74
+ # Tell if authentication through HTTP Auth is enabled. False by default.
75
+ # It can be set to an array that will enable http authentication only for the
76
+ # given strategies, for example, `config.http_authenticatable = [:database]` will
77
+ # enable it only for database authentication.
78
+ # For API-only applications to support authentication "out-of-the-box", you will likely want to
79
+ # enable this with :database unless you are using a custom strategy.
80
+ # The supported strategies are:
81
+ # :database = Support basic authentication with authentication key + password
82
+ # config.http_authenticatable = false
83
+
84
+ # If 401 status code should be returned for AJAX requests. True by default.
85
+ # config.http_authenticatable_on_xhr = true
86
+
87
+ # The realm used in Http Basic Authentication. 'Application' by default.
88
+ # config.http_authentication_realm = 'Application'
89
+
90
+ # It will change confirmation, password recovery and other workflows
91
+ # to behave the same regardless if the e-mail provided was right or wrong.
92
+ # Does not affect registerable.
93
+ # config.paranoid = true
94
+
95
+ # By default Devise will store the user in session. You can skip storage for
96
+ # particular strategies by setting this option.
97
+ # Notice that if you are skipping storage for all authentication paths, you
98
+ # may want to disable generating routes to Devise's sessions controller by
99
+ # passing skip: :sessions to `devise_for` in your config/routes.rb
100
+ config.skip_session_storage = [:http_auth]
101
+
102
+ # By default, Devise cleans up the CSRF token on authentication to
103
+ # avoid CSRF token fixation attacks. This means that, when using AJAX
104
+ # requests for sign in and sign up, you need to get a new CSRF token
105
+ # from the server. You can disable this option at your own risk.
106
+ # config.clean_up_csrf_token_on_authentication = true
107
+
108
+ # When false, Devise will not attempt to reload routes on eager load.
109
+ # This can reduce the time taken to boot the app but if your application
110
+ # requires the Devise mappings to be loaded during boot time the application
111
+ # won't boot properly.
112
+ # config.reload_routes = true
113
+
114
+ # ==> Configuration for :database_authenticatable
115
+ # For bcrypt, this is the cost for hashing the password and defaults to 12. If
116
+ # using other algorithms, it sets how many times you want the password to be hashed.
117
+ # The number of stretches used for generating the hashed password are stored
118
+ # with the hashed password. This allows you to change the stretches without
119
+ # invalidating existing passwords.
120
+ #
121
+ # Limiting the stretches to just one in testing will increase the performance of
122
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
123
+ # a value less than 10 in other environments. Note that, for bcrypt (the default
124
+ # algorithm), the cost increases exponentially with the number of stretches (e.g.
125
+ # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
126
+ config.stretches = Rails.env.test? ? 1 : 12
127
+
128
+ # Set up a pepper to generate the hashed password.
129
+ # config.pepper = '3df46a10f22a3580f28b33634134bfbfe9c62f8fb9dc18c8d310d174f7699b939e6fa64761c45674580487804f1f514d0d9b11538d3fc90a1c514e21dd4f1ce1'
130
+
131
+ # Send a notification to the original email when the user's email is changed.
132
+ # config.send_email_changed_notification = false
133
+
134
+ # Send a notification email when the user's password is changed.
135
+ # config.send_password_change_notification = false
136
+
137
+ # ==> Configuration for :confirmable
138
+ # A period that the user is allowed to access the website even without
139
+ # confirming their account. For instance, if set to 2.days, the user will be
140
+ # able to access the website for two days without confirming their account,
141
+ # access will be blocked just in the third day.
142
+ # You can also set it to nil, which will allow the user to access the website
143
+ # without confirming their account.
144
+ # Default is 0.days, meaning the user cannot access the website without
145
+ # confirming their account.
146
+ # config.allow_unconfirmed_access_for = 2.days
147
+
148
+ # A period that the user is allowed to confirm their account before their
149
+ # token becomes invalid. For example, if set to 3.days, the user can confirm
150
+ # their account within 3 days after the mail was sent, but on the fourth day
151
+ # their account can't be confirmed with the token any more.
152
+ # Default is nil, meaning there is no restriction on how long a user can take
153
+ # before confirming their account.
154
+ # config.confirm_within = 3.days
155
+
156
+ # If true, requires any email changes to be confirmed (exactly the same way as
157
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
158
+ # db field (see migrations). Until confirmed, new email is stored in
159
+ # unconfirmed_email column, and copied to email column on successful confirmation.
160
+ config.reconfirmable = true
161
+
162
+ # Defines which key will be used when confirming an account
163
+ # config.confirmation_keys = [:email]
164
+
165
+ # ==> Configuration for :rememberable
166
+ # The time the user will be remembered without asking for credentials again.
167
+ # config.remember_for = 2.weeks
168
+
169
+ # Invalidates all the remember me tokens when the user signs out.
170
+ config.expire_all_remember_me_on_sign_out = true
171
+
172
+ # If true, extends the user's remember period when remembered via cookie.
173
+ # config.extend_remember_period = false
174
+
175
+ # Options to be passed to the created cookie. For instance, you can set
176
+ # secure: true in order to force SSL only cookies.
177
+ # config.rememberable_options = {}
178
+
179
+ # ==> Configuration for :validatable
180
+ # Range for password length.
181
+ config.password_length = 6..128
182
+
183
+ # Email regex used to validate email formats. It simply asserts that
184
+ # one (and only one) @ exists in the given string. This is mainly
185
+ # to give user feedback and not to assert the e-mail validity.
186
+ config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
187
+
188
+ # ==> Configuration for :timeoutable
189
+ # The time you want to timeout the user session without activity. After this
190
+ # time the user will be asked for credentials again. Default is 30 minutes.
191
+ # config.timeout_in = 30.minutes
192
+
193
+ # ==> Configuration for :lockable
194
+ # Defines which strategy will be used to lock an account.
195
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
196
+ # :none = No lock strategy. You should handle locking by yourself.
197
+ # config.lock_strategy = :failed_attempts
198
+
199
+ # Defines which key will be used when locking and unlocking an account
200
+ # config.unlock_keys = [:email]
201
+
202
+ # Defines which strategy will be used to unlock an account.
203
+ # :email = Sends an unlock link to the user email
204
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
205
+ # :both = Enables both strategies
206
+ # :none = No unlock strategy. You should handle unlocking by yourself.
207
+ # config.unlock_strategy = :both
208
+
209
+ # Number of authentication tries before locking an account if lock_strategy
210
+ # is failed attempts.
211
+ # config.maximum_attempts = 20
212
+
213
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
214
+ # config.unlock_in = 1.hour
215
+
216
+ # Warn on the last attempt before the account is locked.
217
+ # config.last_attempt_warning = true
218
+
219
+ # ==> Configuration for :recoverable
220
+ #
221
+ # Defines which key will be used when recovering the password for an account
222
+ # config.reset_password_keys = [:email]
223
+
224
+ # Time interval you can reset your password with a reset password key.
225
+ # Don't put a too small interval or your users won't have the time to
226
+ # change their passwords.
227
+ config.reset_password_within = 6.hours
228
+
229
+ # When set to false, does not sign a user in automatically after their password is
230
+ # reset. Defaults to true, so a user is signed in automatically after a reset.
231
+ # config.sign_in_after_reset_password = true
232
+
233
+ # ==> Configuration for :encryptable
234
+ # Allow you to use another hashing or encryption algorithm besides bcrypt (default).
235
+ # You can use :sha1, :sha512 or algorithms from others authentication tools as
236
+ # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
237
+ # for default behavior) and :restful_authentication_sha1 (then you should set
238
+ # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
239
+ #
240
+ # Require the `devise-encryptable` gem when using anything other than bcrypt
241
+ # config.encryptor = :sha512
242
+
243
+ # ==> Scopes configuration
244
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
245
+ # "users/sessions/new". It's turned off by default because it's slower if you
246
+ # are using only default views.
247
+ # config.scoped_views = false
248
+
249
+ # Configure the default scope given to Warden. By default it's the first
250
+ # devise role declared in your routes (usually :user).
251
+ # config.default_scope = :user
252
+
253
+ # Set this configuration to false if you want /users/sign_out to sign out
254
+ # only the current scope. By default, Devise signs out all scopes.
255
+ # config.sign_out_all_scopes = true
256
+
257
+ # ==> Navigation configuration
258
+ # Lists the formats that should be treated as navigational. Formats like
259
+ # :html, should redirect to the sign in page when the user does not have
260
+ # access, but formats like :xml or :json, should return 401.
261
+ #
262
+ # If you have any extra navigational formats, like :iphone or :mobile, you
263
+ # should add them to the navigational formats lists.
264
+ #
265
+ # The "*/*" below is required to match Internet Explorer requests.
266
+ # config.navigational_formats = ['*/*', :html]
267
+
268
+ # The default HTTP method used to sign out a resource. Default is :delete.
269
+ config.sign_out_via = :delete
270
+
271
+ # ==> OmniAuth
272
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
273
+ # up on your models and hooks.
274
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
275
+
276
+ # ==> Warden configuration
277
+ # If you want to use other strategies, that are not supported by Devise, or
278
+ # change the failure app, you can configure them inside the config.warden block.
279
+ #
280
+ # config.warden do |manager|
281
+ # manager.intercept_401 = false
282
+ # manager.default_strategies(scope: :user).unshift :some_external_strategy
283
+ # end
284
+
285
+ # ==> Mountable engine configurations
286
+ # When using Devise inside an engine, let's call it `MyEngine`, and this engine
287
+ # is mountable, there are some extra configurations to be taken into account.
288
+ # The following options are available, assuming the engine is mounted as:
289
+ #
290
+ # mount MyEngine, at: '/my_engine'
291
+ #
292
+ # The router that invoked `devise_for`, in the example above, would be:
293
+ # config.router_name = :my_engine
294
+ #
295
+ # When using OmniAuth, Devise cannot automatically set OmniAuth path,
296
+ # so you need to do it manually. For the users scope, it would be:
297
+ # config.omniauth_path_prefix = '/my_engine/users/auth'
298
+
299
+ # ==> Turbolinks configuration
300
+ # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly:
301
+ #
302
+ # ActiveSupport.on_load(:devise_failure_app) do
303
+ # include Turbolinks::Controller
304
+ # end
305
+
306
+ # ==> Configuration for :registerable
307
+
308
+ # When set to false, does not sign a user in automatically after their password is
309
+ # changed. Defaults to true, so a user is signed in automatically after changing a password.
310
+ # config.sign_in_after_change_password = true
311
+
312
+ config.remember_for = 2.weeks
313
+ config.timeout_in = 2.weeks
314
+ end
@@ -0,0 +1,9 @@
1
+ module IbrainJwtExpiration
2
+ mattr_accessor :expiration_time
3
+
4
+ self.expiration_time = {
5
+ 'admin' => 8.hours,
6
+ 'user' => 30.days,
7
+ 'default' => 8.hours
8
+ }
9
+ end
@@ -0,0 +1,17 @@
1
+ en:
2
+ ibrain:
3
+ system:
4
+ messages:
5
+ success: Retrieving data successfully
6
+ ok: Retrieving data successfully
7
+ errors:
8
+ session:
9
+ invalid_session: Invalid login session. Please try again!
10
+ expired_session: The login session has expired.
11
+ account:
12
+ not_found: Account not found
13
+ incorrect: Username or Password is incorrect!
14
+ not_verified: Please verify your account before login
15
+ is_deactivated: Account inactive
16
+ custom_token:
17
+ not_retrieve_uid: Can not retrieve uid