Class: OAuth2::MCP::OIDCDiscovery

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

Overview

Fetches OIDC provider metadata and JWKS for MCP token validation.

Constant Summary collapse

WELL_KNOWN_PATH =

Returns:

  • (String)
"/.well-known/openid-configuration"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(issuer:, client: nil) ⇒ OIDCDiscovery

Returns a new instance of OIDCDiscovery.

Parameters:

  • issuer: (String)
  • client: (Object) (defaults to: nil)


181
182
183
184
# File 'lib/oauth2/mcp.rb', line 181

def initialize(issuer:, client: nil)
  @issuer = issuer.to_s.delete_suffix("/")
  @client = client || OAuth2::Client.new(nil, nil, site: @issuer, raise_errors: true)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.

Returns:

  • (Object)


179
180
181
# File 'lib/oauth2/mcp.rb', line 179

def client
  @client
end

#issuerString (readonly)

Returns the value of attribute issuer.

Returns:

  • (String)


179
180
181
# File 'lib/oauth2/mcp.rb', line 179

def issuer
  @issuer
end

Instance Method Details

#configurationHash[untyped, untyped]

Returns:

  • (Hash[untyped, untyped])


186
187
188
# File 'lib/oauth2/mcp.rb', line 186

def configuration
  @configuration ||= fetch_json(WELL_KNOWN_PATH)
end

#jwksHash[untyped, untyped]

Returns:

  • (Hash[untyped, untyped])


190
191
192
# File 'lib/oauth2/mcp.rb', line 190

def jwks
  @jwks ||= fetch_json(configuration.fetch("jwks_uri"))
end

#jwt_validator(audience:, algorithms: nil, leeway: 60) ⇒ JWTValidator

Parameters:

  • audience: (String)
  • algorithms: (Array[String], nil) (defaults to: nil)
  • leeway: (Integer) (defaults to: 60)

Returns:



194
195
196
197
198
199
200
201
202
# File 'lib/oauth2/mcp.rb', line 194

def jwt_validator(audience:, algorithms: nil, leeway: 60)
  JWTValidator.new(
    jwks: jwks,
    issuer: issuer,
    audience: audience,
    algorithms: algorithms || default_algorithms,
    leeway: leeway
  )
end