Class: RailsBase::Authentication::SingleSignOnCreate

Inherits:
ServiceBase
  • Object
show all
Defined in:
app/services/rails_base/authentication/single_sign_on_create.rb

Instance Method Summary collapse

Methods inherited from ServiceBase

inherited, #internal_validate, #service_base_logging

Methods included from ServiceLogging

#aletered_message, #class_name, #log, #log_prefix, #logger, #service_id

Instance Method Details

#callObject



11
12
13
14
15
16
# File 'app/services/rails_base/authentication/single_sign_on_create.rb', line 11

def call
  msg = "Creating SSO token [#{reason}]: user_id:#{user.id}; "\
    "uses:#{uses.nil? ? 'unlimited' : uses}; expires_at:#{expires_at}"
  log(level: :info, msg: msg)
  context.data = create_sso_token
end

#create_sso_tokenObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/rails_base/authentication/single_sign_on_create.rb', line 18

def create_sso_token
  params = {
    user: user,
    max_use: uses,
    data_use: data_type,
    expires_at: expires_at,
    reason: reason,
    length: token_length,
    extra: url_redirect,
  }.compact
  ShortLivedData.create_data_key(**params)
end

#data_typeObject



31
32
33
# File 'app/services/rails_base/authentication/single_sign_on_create.rb', line 31

def data_type
  ShortLivedData::VALID_DATA_USE_LENGTH.include?(token_type&.to_sym) ? token_type.to_sym : nil
end

#validate!Object



35
36
37
38
39
40
41
42
# File 'app/services/rails_base/authentication/single_sign_on_create.rb', line 35

def validate!
  raise "Expected user to be a User. Received #{user.class}" unless user.is_a? User
  raise "Expected token_length to be a Int. Received #{token_length.class}" unless token_length.is_a? Integer
  raise "Expected reason to be present." if reason.nil?

  time_class = ActiveSupport::TimeWithZone
  raise "Expected expires_at to be a Received #{time_class}. Received #{expires_at.class}" unless expires_at.is_a? time_class
end