Spindle_client.OauthWhat a resource server needs of its authorization server, found as RFC 8414 says.
type keys = kid:string option -> Spindle_http.Jwk.t listThe issuer's keys, as Spindle.Bearer.keys reads them.
keys client ~issuer: the keys issuer signs its tokens with, from its metadata's jwks_uri. The metadata is the first found of /.well-known/oauth-authorization-server and then /.well-known/openid-configuration put before the issuer's path (RFC 8414 §3.1), and openid-configuration after it (OpenID Connect Discovery §4), in the order MCP gives, and is used only where its issuer is issuer exactly (RFC 8414 §3.3).
They are fetched when first asked for and kept. A kid the kept keys do not have fetches them again, at most once a minute -- so a key the issuer rotated in is found, and tokens naming keys nobody has cost one fetch a minute -- and so does none kept at all. A fetch that fails is a warn line, and the kept keys go on answering: none before one succeeds, so every token is refused until then. Each call answers the keys of the kid named, or every key where it names none.
What a client of a protected resource needs: the authorization server found from the resource (RFC 9728) and its own metadata (RFC 8414, OpenID Connect Discovery), a person signed in through their browser by the authorization code grant with PKCE S256 (RFC 7636), the token asked for that resource alone (RFC 8707), the answer checked to come from that server (RFC 9207), and the token refreshed as it expires.
let oauth =
Spindle_client.Oauth.create client ~clock:(Eio.Stdenv.clock env)
~metadata_document:"https://app.example.com/oauth/client.json"
~authorize:(fun url -> open_in_browser url)type registration = {issuer : string;the authorization server it was registered with
*)client_id : string;secret : string option;a confidential client's
*)}A client registered beforehand with one authorization server, and used with that one alone.
Where tokens are kept, by the resource they are for -- a keychain, a file the program owns. The library writes none itself.
val in_memory : unit -> storeTokens kept for as long as the program runs.
type nonrec error = [ | error| `Oauth of stringsigning in failed: a resource or an authorization server whose metadata could not be found or does not check, no way to identify this client to it, an answer that is not its own, or its refusal; in words, quoting no token
*) ]val error_to_string : [< error ] -> stringval create :
?registered:registration list ->
?metadata_document:string ->
?store:store ->
?wait:Mtime.Span.t ->
clock:_ Eio.Time.clock ->
authorize:(string -> unit) ->
t ->
oauthauthorize is given the URL a person signs in at, and opens it in their browser. The browser is sent back to http://127.0.0.1:<port>/callback, a port the system gives, which this client listens on while it waits, at most wait (5 min) for the person (RFC 8252 §7.3).
This client is identified to an authorization server by its registered id for that server where there is one, and otherwise by metadata_document, the HTTPS URL of a Client ID Metadata Document, where the server says it reads them, as MCP orders them. store (in_memory) keeps the tokens. clock says when one expires.
Raises Invalid_argument for a metadata_document that is no https URL with a path: a constant written in source.
The access token kept for resource, refreshed first where it expires within a minute and a refresh token was kept; None where none is kept, or one that cannot be refreshed.
val sign_in :
oauth ->
resource:string ->
?metadata:string ->
?scopes:string list ->
unit ->
(tokens, [> error ]) Stdlib.resultSigns a person in for resource -- the URL a request was made to -- and keeps the tokens. The resource's metadata is read from metadata, the URL a 401's challenge named, or else from its well-known URL with the resource's path, then without (RFC 9728 §3.1, as MCP orders them), and used only where it names resource (§3.3). Its first authorization server this client can identify itself to is asked for scopes and those of the tokens kept for resource, so a step up for one more scope keeps the others (as MCP asks), or else the metadata's scopes_supported.