Package rfc8707

import "funnyhaha.technology/rfc/rfc8707"
View the source code

Overview

Package rfc8707 implements resource indicators, from RFC 8707 (Resource Indicators for OAuth 2.0): the "resource" parameter a client sends to say which protected resource it wants a token for, and the invalid_target error an authorization server returns when it won't issue one.

mcp := rfc8707.MustResource("https://mcp.example.com/mcp")
r, err := rfc8707.ParseResource(form.Get(rfc8707.Param))
if err != nil || !r.Equal(mcp) {
	// Respond with rfc8707.ErrorInvalidTarget.
}

The Model Context Protocol requires clients to send the parameter in both the authorization and token requests, and servers to issue tokens only for the resource named.

The RFC text is in rfc8707.txt in this directory, and the doc comments cite its sections.

Index

Constants

const ErrorInvalidTarget = "invalid_target"
source

ErrorInvalidTarget is the error code for a requested resource that's "invalid, missing, unknown, or malformed", at the authorization or token endpoint (Section 2).

const Param = "resource"
source

Param is the name of the request parameter that carries a resource (Section 2). Section 2 lets a client send it more than once, to ask for several resources.

Variables

var ErrInvalidResource = errors.New("invalid resource")
source

ErrInvalidResource is returned by ParseResource for a value that isn't an absolute URI without a fragment.

Types

Resource source

type Resource struct {
	// contains filtered or unexported fields
}

Resource is a resource indicator: the absolute URI of the protected resource a token is for. Use ParseResource to check a string.

See RFC 8707, Section 2.

MustResource source

func MustResource(s string) Resource

MustResource is like ParseResource but panics if s isn't valid. Use it while wiring a server.

ParseResource source

func ParseResource(s string) (Resource, error)

ParseResource returns s as a Resource, or ErrInvalidResource if it isn't an absolute URI (RFC 3986, Section 4.3) or has a fragment, which Section 2 forbids. A query is allowed, since Section 2 only says it SHOULD NOT be there.

(Resource) Equal source

func (r Resource) Equal(other Resource) bool

Equal reports whether r and other identify the same resource. The scheme and host are compared case-insensitively, as RFC 3986, Section 6.2.2.1, allows, and everything else exactly. A trailing slash is significant.

(Resource) String source

func (r Resource) String() string

String returns the resource's URI as it was parsed.