Class: A2A::SecurityScheme::OAuth2

Inherits:
Object
  • Object
show all
Defined in:
lib/a2a/security_scheme/oauth2.rb

Constant Summary collapse

FLOW_TYPES =
[
  OAuthFlow::AuthorizationCode,
  OAuthFlow::ClientCredentials,
  OAuthFlow::DeviceCode
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flows:, oauth2_metadata_url: nil, description: nil) ⇒ OAuth2

Returns a new instance of OAuth2.



14
15
16
17
18
19
20
21
22
# File 'lib/a2a/security_scheme/oauth2.rb', line 14

def initialize(flows:, oauth2_metadata_url: nil, description: nil)
  unless flows.is_a?(Hash) && flows.size == 1 && FLOW_TYPES.any? { |t| flows.values.first.is_a?(t) }
    raise ArgumentError, "flows must be a Hash with exactly one OAuthFlow entry"
  end

  @flows = flows
  @oauth2_metadata_url = 
  @description = description
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/a2a/security_scheme/oauth2.rb', line 6

def description
  @description
end

#flowsObject (readonly)

Returns the value of attribute flows.



6
7
8
# File 'lib/a2a/security_scheme/oauth2.rb', line 6

def flows
  @flows
end

#oauth2_metadata_urlObject (readonly)

Returns the value of attribute oauth2_metadata_url.



6
7
8
# File 'lib/a2a/security_scheme/oauth2.rb', line 6

def 
  @oauth2_metadata_url
end

Class Method Details

.from_h(hash) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/a2a/security_scheme/oauth2.rb', line 24

def self.from_h(hash)
  new(
    flows: OAuthFlow.from_h(hash.fetch("flows")),
    oauth2_metadata_url: hash["oauth2MetadataUrl"],
    description: hash["description"]
  )
end

Instance Method Details

#to_hObject



32
33
34
35
36
37
38
39
40
# File 'lib/a2a/security_scheme/oauth2.rb', line 32

def to_h
  {
    "oauth2SecurityScheme" => {
      "flows" => serialize_flows,
      "oauth2MetadataUrl" => ,
      "description" => description
    }.compact
  }
end