Class: Mpp::Extensions::MCP::MCPCredential

Inherits:
Data
  • Object
show all
Defined in:
lib/mpp/extensions/mcp/types.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(challenge:, payload:, source: nil) ⇒ MCPCredential

Returns a new instance of MCPCredential.



74
75
76
# File 'lib/mpp/extensions/mcp/types.rb', line 74

def initialize(challenge:, payload:, source: nil)
  super
end

Instance Attribute Details

#challengeObject (readonly)

Returns the value of attribute challenge

Returns:

  • (Object)

    the current value of challenge



73
74
75
# File 'lib/mpp/extensions/mcp/types.rb', line 73

def challenge
  @challenge
end

#payloadObject (readonly)

Returns the value of attribute payload

Returns:

  • (Object)

    the current value of payload



73
74
75
# File 'lib/mpp/extensions/mcp/types.rb', line 73

def payload
  @payload
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



73
74
75
# File 'lib/mpp/extensions/mcp/types.rb', line 73

def source
  @source
end

Class Method Details

.from_core(credential, challenge) ⇒ Object



132
133
134
135
136
137
138
# File 'lib/mpp/extensions/mcp/types.rb', line 132

def self.from_core(credential, challenge)
  new(
    challenge: challenge,
    payload: credential.payload,
    source: credential.source
  )
end

.from_dict(data) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/mpp/extensions/mcp/types.rb', line 91

def self.from_dict(data)
  new(
    challenge: MCPChallenge.from_dict(data["challenge"]),
    payload: data["payload"],
    source: data["source"]
  )
end

.from_meta(meta) ⇒ Object



99
100
101
102
103
# File 'lib/mpp/extensions/mcp/types.rb', line 99

def self.from_meta(meta)
  return nil unless meta.key?(META_CREDENTIAL)

  from_dict(meta[META_CREDENTIAL])
end

Instance Method Details

#to_coreObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/mpp/extensions/mcp/types.rb', line 105

def to_core
  request_json = Mpp::Json.compact_encode(challenge.request)
  request_b64 = Base64.urlsafe_encode64(request_json, padding: false)

  opaque_b64 = nil
  if challenge.opaque
    opaque_json = Mpp::Json.compact_encode(challenge.opaque)
    opaque_b64 = Base64.urlsafe_encode64(opaque_json, padding: false)
  end

  echo = Mpp::ChallengeEcho.new(
    id: challenge.id,
    realm: challenge.realm,
    method: challenge.method,
    intent: challenge.intent,
    request: request_b64,
    expires: challenge.expires,
    digest: challenge.digest,
    opaque: opaque_b64
  )
  Mpp::Credential.new(
    challenge: echo,
    payload: payload,
    source: source
  )
end

#to_dictObject



78
79
80
81
82
83
84
85
# File 'lib/mpp/extensions/mcp/types.rb', line 78

def to_dict
  result = {
    "challenge" => challenge.to_dict,
    "payload" => payload
  }
  result["source"] = source if source
  result
end

#to_metaObject



87
88
89
# File 'lib/mpp/extensions/mcp/types.rb', line 87

def to_meta
  {META_CREDENTIAL => to_dict}
end