Class: OpenAI::Auth::X509TokenExchange Private

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/auth/x509_token_exchange.rb,
sig/openai/auth/x509_token_exchange.rbs

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Performs the fixed certificate-authenticated OpenAI token exchange.

Instance Method Summary collapse

Constructor Details

#initialize(config, transport:) ⇒ X509TokenExchange

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of X509TokenExchange.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/openai/auth/x509_token_exchange.rb', line 26

def initialize(config, transport:)
  unless X509Transport.exact_instance?(config, X509WorkloadIdentity)
    raise ArgumentError, "X.509 exchange requires an X509WorkloadIdentity"
  end

  unless X509Transport.exact_instance?(transport, X509Transport)
    raise ArgumentError, "X.509 exchange requires an attested X509Transport"
  end

  @config = config
  @transport = transport
end

Instance Method Details

#bound_to?(identity, transport:) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



47
48
49
# File 'lib/openai/auth/x509_token_exchange.rb', line 47

def bound_to?(identity, transport:)
  @config.equal?(identity) && @transport.equal?(transport)
end

#fetch(deadline: nil) ⇒ Hash{Symbol=>String, Float}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • deadline (Float, nil) (defaults to: nil)

    absolute monotonic request deadline

  • deadline: (Float, nil) (defaults to: nil)

Returns:

  • (Hash{Symbol=>String, Float})


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/openai/auth/x509_token_exchange.rb', line 53

def fetch(deadline: nil)
  request = OpenAI::HTTPClient::Request.new(
    method: :post,
    url: URI(TOKEN_URL),
    headers: {"accept" => "application/json", "content-type" => "application/json"},
    body: JSON.generate(
      grant_type: GRANT_TYPE,
      subject_token_type: SUBJECT_TOKEN_TYPE,
      identity_provider_id: @config.identity_provider_id,
      service_account_id: @config.
    ),
    timeout: remaining_timeout(deadline)
  )
  response = @transport.execute(request)
  successful = (200..299).cover?(response.status)
  body = parse_response(response, deadline: deadline, strict: successful)
  if successful
    token = validate_token_response(body, response: response)
    remaining_timeout(deadline)
    return token
  end

  raise_error(response, body)
rescue OpenAI::Errors::APIConnectionError => error
  raise error.class.new(url: URI(TOKEN_URL)), cause: nil
end

#inspectString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Avoid exposing nested workload identity configuration in diagnostics.

Returns:

  • (String)


42
43
44
# File 'lib/openai/auth/x509_token_exchange.rb', line 42

def inspect
  "#<#{self.class.name}:0x#{object_id.to_s(16)}>"
end