Sha256: 0c1be5d369812ccfabf9d47ab68b06b470eb7860279efb238135294560a41977

Contents?: true

Size: 1.02 KB

Versions: 14

Compression:

Stored size: 1.02 KB

Contents

module RailsBase::Authentication
	class MfaSetEncryptToken < RailsBase::ServiceBase
		delegate :user, to: :context
		delegate :expires_at, to: :context
		delegate :purpose, to: :context

		def call
			params = {
				value: value,
				purpose: purpose || Constants::MSET_PURPOSE,
				expires_at: expires_at
			}

			context.encrypted_val = RailsBase::Encryption.encode(params)
		end

		def value
			# user_id with the same expires_at will return the same Encryption token
			# to overcome this, do 2 things
			# 1: Rotate the secret on every boot (ensures tplem changes on semi regular basis)
			# 2: Add rand strings to the hash -- Ensures the token is different every time
			{ user_id: user.id, rand: rand.to_s, expires_at: expires_at }.to_json
		end

		def validate!
			raise "Expected user to be a User. Received #{user.class}" unless user.is_a? User

			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/mfa_set_encrypt_token.rb
rails_base-0.60.0 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.58.0 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.57.0 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.56.0 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.55.0 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.54.0 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.53.1 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.53.0 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.52.3 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.52.1 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.52.0 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.51.1 app/services/rails_base/authentication/mfa_set_encrypt_token.rb
rails_base-0.51.0 app/services/rails_base/authentication/mfa_set_encrypt_token.rb