Class: MCPClient::Auth::ClientInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_client/auth.rb

Overview

Registered OAuth client information

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id:, metadata:, client_secret: nil, client_id_issued_at: nil, client_secret_expires_at: nil) ⇒ ClientInfo



151
152
153
154
155
156
157
158
# File 'lib/mcp_client/auth.rb', line 151

def initialize(client_id:, metadata:, client_secret: nil, client_id_issued_at: nil,
               client_secret_expires_at: nil)
  @client_id = client_id
  @client_secret = client_secret
  @client_id_issued_at = client_id_issued_at
  @client_secret_expires_at = client_secret_expires_at
   = 
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



144
145
146
# File 'lib/mcp_client/auth.rb', line 144

def client_id
  @client_id
end

#client_id_issued_atObject (readonly)

Returns the value of attribute client_id_issued_at.



144
145
146
# File 'lib/mcp_client/auth.rb', line 144

def client_id_issued_at
  @client_id_issued_at
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



144
145
146
# File 'lib/mcp_client/auth.rb', line 144

def client_secret
  @client_secret
end

#client_secret_expires_atObject (readonly)

Returns the value of attribute client_secret_expires_at.



144
145
146
# File 'lib/mcp_client/auth.rb', line 144

def client_secret_expires_at
  @client_secret_expires_at
end

#metadataObject (readonly)

Returns the value of attribute metadata.



144
145
146
# File 'lib/mcp_client/auth.rb', line 144

def 
  
end

Class Method Details

.build_metadata_from_hash(metadata_data) ⇒ ClientMetadata

Build ClientMetadata from hash data



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/mcp_client/auth.rb', line 199

def self.()
  .new(
    redirect_uris: [:redirect_uris] || ['redirect_uris'] || [],
    token_endpoint_auth_method: extract_auth_method(),
    grant_types: [:grant_types] || ['grant_types'] ||
                 %w[authorization_code refresh_token],
    response_types: [:response_types] || ['response_types'] || ['code'],
    scope: [:scope] || ['scope'],
    client_name: [:client_name] || ['client_name'],
    client_uri: [:client_uri] || ['client_uri'],
    logo_uri: [:logo_uri] || ['logo_uri'],
    tos_uri: [:tos_uri] || ['tos_uri'],
    policy_uri: [:policy_uri] || ['policy_uri'],
    contacts: [:contacts] || ['contacts']
  )
end

.extract_auth_method(metadata_data) ⇒ String

Extract token endpoint auth method from metadata



219
220
221
222
# File 'lib/mcp_client/auth.rb', line 219

def self.extract_auth_method()
  [:token_endpoint_auth_method] ||
    ['token_endpoint_auth_method'] || 'none'
end

.from_h(data) ⇒ ClientInfo

Create client info from hash



183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/mcp_client/auth.rb', line 183

def self.from_h(data)
   = data[:metadata] || data['metadata'] || {}
   = ()

  new(
    client_id: data[:client_id] || data['client_id'],
    client_secret: data[:client_secret] || data['client_secret'],
    client_id_issued_at: data[:client_id_issued_at] || data['client_id_issued_at'],
    client_secret_expires_at: data[:client_secret_expires_at] || data['client_secret_expires_at'],
    metadata: 
  )
end

Instance Method Details

#client_secret_expired?Boolean

Check if client secret is expired



162
163
164
165
166
# File 'lib/mcp_client/auth.rb', line 162

def client_secret_expired?
  return false unless @client_secret_expires_at

  Time.now.to_i >= @client_secret_expires_at
end

#to_hHash

Convert to hash for serialization



170
171
172
173
174
175
176
177
178
# File 'lib/mcp_client/auth.rb', line 170

def to_h
  {
    client_id: @client_id,
    client_secret: @client_secret,
    client_id_issued_at: @client_id_issued_at,
    client_secret_expires_at: @client_secret_expires_at,
    metadata: .to_h
  }.compact
end