Module: Rails::Auth

Defined in:
lib/rails/auth.rb,
lib/rails/auth/engine.rb,
lib/rails/auth/version.rb,
app/models/rails/auth/current.rb,
app/mailers/rails/auth/user_mailer.rb,
app/jobs/rails/auth/application_job.rb,
app/models/rails/auth/security_event.rb,
app/models/rails/auth/application_record.rb,
app/controllers/rails/auth/mfa_controller.rb,
app/helpers/rails/auth/application_helper.rb,
app/mailers/rails/auth/application_mailer.rb,
app/models/concerns/rails/auth/sessionable.rb,
app/controllers/rails/auth/unlocks_controller.rb,
app/controllers/rails/auth/profiles_controller.rb,
app/controllers/rails/auth/security_controller.rb,
app/controllers/rails/auth/sessions_controller.rb,
app/models/concerns/rails/auth/authenticatable.rb,
app/controllers/rails/auth/application_controller.rb,
app/controllers/rails/auth/confirmations_controller.rb,
app/controllers/rails/auth/registrations_controller.rb,
app/controllers/rails/auth/impersonations_controller.rb,
app/controllers/rails/auth/password_resets_controller.rb,
app/controllers/rails/auth/otp_verifications_controller.rb,
app/controllers/concerns/rails/auth/authenticatable_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, Authenticatable, AuthenticatableController, Sessionable Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, ConfirmationsController, Current, Engine, ImpersonationsController, MfaController, OtpVerificationsController, PasswordResetsController, ProfilesController, RegistrationsController, SecurityController, SecurityEvent, SessionsController, UnlocksController, UserMailer

Constant Summary collapse

VERSION =
"0.1.2"
@@user_class_name =
"User"
@@session_class_name =
"Session"
@@mailer_sender =
"from@example.com"
@@confirmation_token_format =

:hex or :numeric

:hex
@@confirmation_token_length =
20

Class Method Summary collapse

Class Method Details

.decode_jwt(token) ⇒ Object



51
52
53
54
55
56
# File 'lib/rails/auth.rb', line 51

def self.decode_jwt(token)
  body = ::JWT.decode(token, self.jwt_secret.to_s)[0]
  HashWithIndifferentAccess.new body
rescue ::JWT::DecodeError
  nil
end

.encode_jwt(payload, exp = 24.hours.from_now) ⇒ Object



46
47
48
49
# File 'lib/rails/auth.rb', line 46

def self.encode_jwt(payload, exp = 24.hours.from_now)
  payload[:exp] = exp.to_i
  ::JWT.encode(payload, self.jwt_secret.to_s)
end

.jwt_secretObject



30
31
32
# File 'lib/rails/auth.rb', line 30

def self.jwt_secret
  @@jwt_secret || ENV["RAILS_AUTH_JWT_SECRET"] || (Rails.application&.respond_to?(:secret_key_base) ? Rails.application.secret_key_base : "default_secret_for_testing_only")
end

.session_classObject



42
43
44
# File 'lib/rails/auth.rb', line 42

def self.session_class
  @@session_class_name.constantize
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Rails::Auth)

    the object that the method was called on



34
35
36
# File 'lib/rails/auth.rb', line 34

def self.setup
  yield self
end

.table_name_prefixObject



9
10
11
# File 'lib/rails/auth.rb', line 9

def self.table_name_prefix
  ""
end

.user_classObject



38
39
40
# File 'lib/rails/auth.rb', line 38

def self.user_class
  @@user_class_name.constantize
end