Sha256: cd4d8f87cb602dce576a18cc54f775e5fa634b16754044d93adaedfba9fd9dde

Contents?: true

Size: 1.45 KB

Versions: 14

Compression:

Stored size: 1.45 KB

Contents

module RailsBase::Authentication
  class SingleSignOnCreate < RailsBase::ServiceBase
    delegate :user, to: :context
    delegate :token_length, to: :context
    delegate :uses, to: :context
    delegate :expires_at, to: :context
    delegate :reason, to: :context
    delegate :token_type, to: :context
    delegate :url_redirect, to: :context

    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

    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

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

    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
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rails_base-0.61.0 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.60.0 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.58.0 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.57.0 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.56.0 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.55.0 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.54.0 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.53.1 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.53.0 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.52.3 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.52.1 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.52.0 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.51.1 app/services/rails_base/authentication/single_sign_on_create.rb
rails_base-0.51.0 app/services/rails_base/authentication/single_sign_on_create.rb