Class: OAuth2::MCP::BearerChallenge

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

Overview

Formats WWW-Authenticate Bearer challenges for MCP HTTP responses.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_metadata:, scope: nil, error: nil, error_description: nil) ⇒ BearerChallenge

Returns a new instance of BearerChallenge.



541
542
543
544
545
546
# File 'lib/oauth2/mcp.rb', line 541

def initialize(resource_metadata:, scope: nil, error: nil, error_description: nil)
  @resource_metadata = .to_s
  @scope = scope
  @error = error
  @error_description = error_description
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



539
540
541
# File 'lib/oauth2/mcp.rb', line 539

def error
  @error
end

#error_descriptionObject (readonly)

Returns the value of attribute error_description.



539
540
541
# File 'lib/oauth2/mcp.rb', line 539

def error_description
  @error_description
end

#resource_metadataObject (readonly)

Returns the value of attribute resource_metadata.



539
540
541
# File 'lib/oauth2/mcp.rb', line 539

def 
  @resource_metadata
end

#scopeObject (readonly)

Returns the value of attribute scope.



539
540
541
# File 'lib/oauth2/mcp.rb', line 539

def scope
  @scope
end

Instance Method Details

#to_headerObject



548
549
550
551
552
553
554
555
556
557
# File 'lib/oauth2/mcp.rb', line 548

def to_header
  parameters = {
    resource_metadata: ,
    scope: format_scope(scope),
    error: error,
    error_description: error_description,
  }.compact

  "Bearer #{parameters.map { |key, value| %(#{key}="#{escape(value)}") }.join(", ")}"
end