MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / GetProtectedResourceMetadata

Function GetProtectedResourceMetadata

oauthex/resource_meta.go:124–148  ·  view source on GitHub ↗

GetProtectedResourceMetadata issues a GET request to retrieve protected resource metadata from a resource server. The metadataURL is typically a URL with a host:port and possibly a path. The resourceURL is the resource URI the metadataURL is for. The following checks are performed: - The metadataURL

(ctx context.Context, metadataURL, resourceURL string, c *http.Client)

Source from the content-addressed store, hash-verified

122// - The resource field of the resulting metadata must match the resourceURL.
123// - The authorization_servers field of the resulting metadata is checked for dangerous URL schemes.
124func GetProtectedResourceMetadata(ctx context.Context, metadataURL, resourceURL string, c *http.Client) (_ *ProtectedResourceMetadata, err error) {
125 defer util.Wrapf(&err, "GetProtectedResourceMetadata(%q)", metadataURL)
126 // Only allow HTTP for local addresses (testing or development purposes).
127 if err := checkHTTPSOrLoopback(metadataURL); err != nil {
128 return nil, fmt.Errorf("metadataURL: %v", err)
129 }
130 prm, err := getJSON[ProtectedResourceMetadata](ctx, c, metadataURL, 1<<20)
131 if err != nil {
132 return nil, err
133 }
134 // Validate the Resource field (see RFC 9728, section 3.3).
135 if prm.Resource != resourceURL {
136 return nil, fmt.Errorf("got metadata resource %q, want %q", prm.Resource, resourceURL)
137 }
138 // Validate the authorization server URLs to prevent XSS attacks (see #526).
139 for i, u := range prm.AuthorizationServers {
140 if err := checkURLScheme(u); err != nil {
141 return nil, fmt.Errorf("authorization_servers[%d]: %v", i, err)
142 }
143 if err := checkHTTPSOrLoopback(u); err != nil {
144 return nil, fmt.Errorf("authorization_servers[%d]: %v", i, err)
145 }
146 }
147 return prm, nil
148}
149
150// ParseWWWAuthenticate parses a WWW-Authenticate header string.
151// The header format is defined in RFC 9110, Section 11.6.1, and can contain

Calls 3

WrapfFunction · 0.92
checkHTTPSOrLoopbackFunction · 0.85
checkURLSchemeFunction · 0.70

Used in the wild real call sites across dependent graphs

searching dependent graphs…