class EtCcdClient::TidamClient

Attributes

config[RW]
logger[RW]
service_token[RW]
user_details[RW]
user_token[RW]

Public Class Methods

new(config: ::EtCcdClient.config) click to toggle source
# File lib/et_ccd_client/tidam_client.rb, line 9
def initialize(config: ::EtCcdClient.config)
  self.config = config
  self.logger = config.logger
  self.service_token = nil
  self.user_token = nil
  self.user_details = nil
end

Public Instance Methods

login(user_id: config.user_id, role: config.user_role) click to toggle source
# File lib/et_ccd_client/tidam_client.rb, line 17
def login(user_id: config.user_id, role: config.user_role)
  logger.tagged('EtCcdClient::IdamClient') do
    self.service_token = exchange_service_token
    self.user_token = exchange_tidam_user_token(user_id, role)
    self.user_details = get_user_details(user_id, role)
  end
end

Private Instance Methods

exchange_service_token() click to toggle source
# File lib/et_ccd_client/tidam_client.rb, line 30
def exchange_service_token
  url = config.idam_service_token_exchange_url
  data = { microservice: config.microservice, oneTimePassword: otp }.to_json
  logger.debug("ET > Idam service token exchange (#{url}) - #{data}")
  resp = RestClient::Request.execute(method: :post, url: url, payload: data, headers: { content_type: 'application/json' }, verify_ssl: config.verify_ssl)
  resp.body.tap do |resp_body|
    logger.debug "ET < Idam service token exchange - #{resp_body}"
  end
end
exchange_tidam_user_token(user_id, user_role) click to toggle source
# File lib/et_ccd_client/tidam_client.rb, line 40
def exchange_tidam_user_token(user_id, user_role)
  url = config.idam_user_token_exchange_url
  logger.debug("ET > Idam user token exchange (#{url}) - id: #{user_id} role: #{user_role}")
  resp = RestClient::Request.execute(method: :post, url: url, payload: { id: user_id, role: user_role }, verify_ssl: config.verify_ssl)
  resp.body.tap do |resp_body|
    logger.debug "ET < Idam user token exchange - #{resp_body}"
  end
end
get_user_details(user_id, role) click to toggle source
# File lib/et_ccd_client/tidam_client.rb, line 49
def get_user_details(user_id, role)
  {
    'id' => user_id,
    'roles' => role.split(',').map(&:strip)
  }
end
otp() click to toggle source
# File lib/et_ccd_client/tidam_client.rb, line 56
def otp
  totp.now
end
totp() click to toggle source
# File lib/et_ccd_client/tidam_client.rb, line 60
def totp
  @totp ||= ROTP::TOTP.new(config.microservice_secret)
end