Documentation
¶
Overview ¶
Package auth decides how a request identifies itself to the API.
There are two families, and the second is why this package exists. STATIC is what every tool does: a bearer, an API key, a basic — a fixed value, from a flag, applied to every call. DYNAMIC is what many production APIs require: trading key+secret for a short-lived JWT, typically valid for an hour or two. With static auth, an MCP server for those APIs works until the token expires and then returns 401 until somebody restarts it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Basic ¶
type Basic struct{ User, Password string }
Basic sets `Authorization: Basic <base64(user:password)>`.
type Flow ¶
type Flow struct {
// URL of the endpoint that issues the token.
URL string
// Fields sent as form-urlencoded, which is what authentication endpoints usually accept.
Fields map[string]string
// TokenPath says where the token sits in the JSON response, as nested keys.
// E.g. {"data":{"token":"x"}} → []string{"data","token"}.
TokenPath []string
// TTL is how long the token is valid. The renewal margin is derived from it.
TTL time.Duration
// Client is injectable for tests.
Client *http.Client
// contains filtered or unexported fields
}
Flow is dynamic auth: it trades credentials for a short-lived token and renews it on its own.
The token is kept in memory and renewed BEFORE it expires, with a margin. Renewing on a 401 would also work, but it burns one call every couple of hours and turns a predictable event into a visible failure for whoever is on the other side.
func (*Flow) Invalidate ¶
func (f *Flow) Invalidate()
Invalidate throws away the stored token — for when the API answered 401 despite the validity it announced itself. The next call authenticates again.