Class: RubyLLM::MCP::Auth::PKCE

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

Overview

Proof Key for Code Exchange (PKCE) implementation (RFC 7636) Required for OAuth 2.1 security

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePKCE

Returns a new instance of PKCE.



309
310
311
312
313
# File 'lib/ruby_llm/mcp/auth.rb', line 309

def initialize
  @code_verifier = generate_code_verifier
  @code_challenge = generate_code_challenge(@code_verifier)
  @code_challenge_method = "S256" # SHA256 - only secure method for OAuth 2.1
end

Instance Attribute Details

#code_challengeObject (readonly)

Returns the value of attribute code_challenge.



307
308
309
# File 'lib/ruby_llm/mcp/auth.rb', line 307

def code_challenge
  @code_challenge
end

#code_challenge_methodObject (readonly)

Returns the value of attribute code_challenge_method.



307
308
309
# File 'lib/ruby_llm/mcp/auth.rb', line 307

def code_challenge_method
  @code_challenge_method
end

#code_verifierObject (readonly)

Returns the value of attribute code_verifier.



307
308
309
# File 'lib/ruby_llm/mcp/auth.rb', line 307

def code_verifier
  @code_verifier
end

Class Method Details

.from_h(data) ⇒ PKCE

Deserialize from hash

Parameters:

  • data (Hash)

    PKCE data

Returns:

  • (PKCE)

    new instance



328
329
330
331
332
333
334
335
# File 'lib/ruby_llm/mcp/auth.rb', line 328

def self.from_h(data)
  pkce = allocate
  pkce.instance_variable_set(:@code_verifier, data[:code_verifier] || data["code_verifier"])
  pkce.instance_variable_set(:@code_challenge, data[:code_challenge] || data["code_challenge"])
  pkce.instance_variable_set(:@code_challenge_method,
                             data[:code_challenge_method] || data["code_challenge_method"] || "S256")
  pkce
end

Instance Method Details

#to_hHash

Serialize to hash

Returns:

  • (Hash)

    PKCE parameters



317
318
319
320
321
322
323
# File 'lib/ruby_llm/mcp/auth.rb', line 317

def to_h
  {
    code_verifier: @code_verifier,
    code_challenge: @code_challenge,
    code_challenge_method: @code_challenge_method
  }
end