Sha256: cde47cb314079537837819010fd3a8124869d31cd39d956ac08991f45d8b6e7b
Contents?: true
Size: 1.16 KB
Versions: 2
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true module Sandbox # Client is responsible for setting up test data in the sandbox instance class Client attr_accessor :app_id attr_accessor :key attr_accessor :base_url def initialize(app_id:, private_key:, base_url:) @app_id = app_id @base_url = base_url @key = OpenSSL::PKey::RSA.new(Base64.decode64(private_key)) end def setup_sharing_profile(profile) endpoint = "/apps/#{app_id}/tokens?\ nonce=#{SecureRandom.uuid}×tamp=#{Time.now.to_i}" uri = URI( "#{@base_url}/#{endpoint}" ) response = Net::HTTP.start( uri.hostname, uri.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE ) do |http| unsigned = Net::HTTP::Post.new uri unsigned.body = profile.to_json signed_request = Yoti::SignedRequest.new( unsigned, endpoint, profile ).sign http.request signed_request end raise "Failed to share profile #{response.code}: #{response.body}" unless response.code == '201' token = JSON.parse(response.body)['token'] token end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
yoti-1.6.1 | lib/yoti/sandbox/sandbox_client.rb |
yoti-1.6.0 | lib/yoti/sandbox/sandbox_client.rb |