Sha256: d03b39c66230c3bb7b38763ad4881614ca7cbf50b48169039805a9279d1e336b

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 KB

Contents

require "addressable/template"
require "addressable/uri"
require 'et_ccd_client/config'
module EtCcdClient
  class UiIdamClient
    include CommonRestClient
    attr_reader :service_token, :user_token, :user_details

    def initialize(config: ::EtCcdClient.config)
      self.config = config
      self.logger = config.logger
      self.user_details = nil
    end

    def login(username: config.sidam_username, password: config.sidam_password)
      logger.tagged('EtCcdClient::UiIdamClient') do
        self.user_token = exchange_sidam_user_token(username, password)
        self.user_details = get_user_details
      end
    end

    private

    attr_writer :user_token, :user_details
    attr_accessor :config, :logger

    def exchange_sidam_user_token(username, password)
      url = "#{config.idam_base_url}/loginUser"
      resp = post_request(url, {username: username, password: password}, extra_headers: { content_type: 'application/x-www-form-urlencoded', accept: 'application/json' }, log_subject: "IdamUI user token exchange")
      token = resp['access_token']
      token
    end

    def get_user_details
      url = "#{config.idam_base_url}/details"
      get_request(url, extra_headers: { 'Accept' => 'application/json', 'Authorization' => user_token }, log_subject: "UiIdam get user details")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
et_ccd_client-0.4.0 lib/et_ccd_client/ui_idam_client.rb
et_ccd_client-0.3.4 lib/et_ccd_client/ui_idam_client.rb
et_ccd_client-0.3.3 lib/et_ccd_client/ui_idam_client.rb
et_ccd_client-0.3.2 lib/et_ccd_client/ui_idam_client.rb
et_ccd_client-0.3.1 lib/et_ccd_client/ui_idam_client.rb