Module: A2A::Client::Auth

Defined in:
lib/a2a/modules.rb,
lib/a2a/client/auth.rb,
lib/a2a/client/auth/jwt.rb,
lib/a2a/client/auth/oauth2.rb,
lib/a2a/client/auth/api_key.rb,
lib/a2a/client/auth/interceptor.rb

Defined Under Namespace

Classes: ApiKey, Interceptor, JWT, OAuth2

Class Method Summary collapse

Class Method Details

.from_config(config) ⇒ Object

Create authentication strategy from configuration

Parameters:

  • config (Hash)

    Authentication configuration

Returns:

  • (Object)

    Authentication strategy instance



50
51
52
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
# File 'lib/a2a/client/auth.rb', line 50

def self.from_config(config)
  case config["type"] || config[:type]
  when "oauth2"
    OAuth2.new(
      client_id: config["client_id"] || config[:client_id],
      client_secret: config["client_secret"] || config[:client_secret],
      token_url: config["token_url"] || config[:token_url],
      scope: config["scope"] || config[:scope]
    )
  when "jwt"
    JWT.new(
      token: config["token"] || config[:token],
      secret: config["secret"] || config[:secret],
      algorithm: config["algorithm"] || config[:algorithm] || "HS256",
      payload: config["payload"] || config[:payload],
      headers: config["headers"] || config[:headers],
      expires_in: config["expires_in"] || config[:expires_in]
    )
  when "api_key"
    ApiKey.new(
      key: config["key"] || config[:key],
      name: config["name"] || config[:name] || "X-API-Key",
      location: config["location"] || config[:location] || "header"
    )
  else
    raise ArgumentError, "Unknown authentication type: #{config['type'] || config[:type]}"
  end
end

.from_security_scheme(scheme, credentials) ⇒ Object

Create authentication strategy from security scheme

Parameters:

  • scheme (Hash)

    Security scheme definition from agent card

  • credentials (Hash)

    Authentication credentials

Returns:

  • (Object)

    Authentication strategy instance



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/a2a/client/auth.rb', line 85

def self.from_security_scheme(scheme, credentials)
  case scheme["type"]
  when "oauth2"
    OAuth2.new(
      client_id: credentials["client_id"],
      client_secret: credentials["client_secret"],
      token_url: scheme["tokenUrl"],
      scope: credentials["scope"]
    )
  when "http"
    case scheme["scheme"]
    when "bearer"
      JWT.new(token: credentials["token"])
    when "basic"
      # Basic auth configuration
      {
        type: "basic",
        username: credentials["username"],
        password: credentials["password"]
      }
    else
      raise ArgumentError, "Unsupported HTTP scheme: #{scheme['scheme']}"
    end
  when "apiKey"
    ApiKey.from_security_scheme(scheme, credentials["key"])
  else
    raise ArgumentError, "Unsupported security scheme type: #{scheme['type']}"
  end
end

.interceptor_from_config(config) ⇒ Interceptor

Create interceptor from configuration

Parameters:

  • config (Hash)

    Authentication configuration

Returns:

  • (Interceptor)

    Configured authentication interceptor



120
121
122
123
# File 'lib/a2a/client/auth.rb', line 120

def self.interceptor_from_config(config)
  strategy = from_config(config)
  Interceptor.new(strategy, auto_retry: config["auto_retry"] || config[:auto_retry] || true)
end

.interceptor_from_security_scheme(scheme, credentials) ⇒ Interceptor

Create interceptor from security scheme

Parameters:

  • scheme (Hash)

    Security scheme definition

  • credentials (Hash)

    Authentication credentials

Returns:

  • (Interceptor)

    Configured authentication interceptor



131
132
133
134
# File 'lib/a2a/client/auth.rb', line 131

def self.interceptor_from_security_scheme(scheme, credentials)
  strategy = from_security_scheme(scheme, credentials)
  Interceptor.new(strategy)
end