class OmniAuth::Strategies::PrivatbankUa
Constants
- DATA_DOMAIN
- OAUTH_DOMAIN
Public Instance Methods
callback_url()
click to toggle source
# File lib/omniauth/strategies/privatbank-ua.rb, line 43 def callback_url full_host + script_name + callback_path # + query_string end
raw_info()
click to toggle source
# File lib/omniauth/strategies/privatbank-ua.rb, line 39 def raw_info @raw_info ||= customer_data end
Protected Instance Methods
build_access_token()
click to toggle source
# File lib/omniauth/strategies/privatbank-ua.rb, line 49 def build_access_token verifier = request.params['code'] calculated_secret = Digest::SHA1.hexdigest "#{options.client_id}#{options.client_secret}#{verifier}" client = ::OAuth2::Client.new(options.client_id, calculated_secret, deep_symbolize(options.client_options)) client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize({header_format: "Bearer %s, Id #{options.client_id}"})) end
Private Instance Methods
customer_data()
click to toggle source
# File lib/omniauth/strategies/privatbank-ua.rb, line 60 def customer_data data = request_customer_data if data['state'] == 'ok' person = data['customer'] if person['type'] == 'physical' decrypt_customer_data(person) end person else raise NoCustomerError.new(data.to_s) end end
customer_data_post_params()
click to toggle source
# File lib/omniauth/strategies/privatbank-ua.rb, line 108 def customer_data_post_params { "type" => "physical", "fields" => [ "firstName", "middleName", "lastName", "phone", "inn", "clId", "clIdText", "birthDay", "email", "sex", "resident", "dateModification" ] } end
decrypt(field_value)
click to toggle source
# File lib/omniauth/strategies/privatbank-ua.rb, line 100 def decrypt(field_value) private_key.private_decrypt(Base64::decode64(field_value)) end
decrypt_customer_data(person)
click to toggle source
# File lib/omniauth/strategies/privatbank-ua.rb, line 87 def decrypt_customer_data(person) if person['signature'].present? fields = ['inn', 'firstName', 'middleName', 'lastName', 'phone', 'email'] fields.each do |field_name| begin person[field_name] = decrypt(person[field_name]) rescue Exception => e OmniAuth.config.logger.error("#{self.class} could not decrypt field: #{field_name}, because: #{e.message}") end end end end
private_key()
click to toggle source
# File lib/omniauth/strategies/privatbank-ua.rb, line 104 def private_key @private_key ||= OpenSSL::PKey::RSA.new(File.read(options.private_key_path)) end
request_customer_data()
click to toggle source
# File lib/omniauth/strategies/privatbank-ua.rb, line 73 def request_customer_data access_token.post("#{options.data_site}/ResourceService/checked/data", { headers: { 'Content-Type' => "application/json", 'Accept' => "application/json" }, body: customer_data_post_params.to_json } ).parsed rescue ::Errno::ETIMEDOUT raise ::Timeout::Error end