Skip to main content

Module auth

Module auth 

Source
Expand description

In-band authorization: present tokens to the peer and learn what they grant.

Each side of a session presents the credential its connection already carried (the URL, a client certificate, or nothing) right after setup, and learns the Grant it earned. Session::auth returns the Handle: grant is the union of every token this side presented, and add presents another without reconnecting. The returned Credential is cloneable; dropping its last clone withdraws it. A Route can name it, so the request advertising the route carries it too, and swapping it renews that request in place.

A handle passed to Client::with_auth outlives its sessions: each session built on it presents every token it holds, so a route naming one of its Credentials keeps it across a reconnect. Only the peer’s verdict ends such a token; a session ending leaves it for the next. It backs one active session at a time, plus the ones draining after a GOAWAY.

The other direction, answering the peer’s tokens, is automatic: the session grants what its own origin handles allow. A server that verifies tokens itself takes the client’s from server::Handshake::requests before accepting, and then answers every token the client presents. Either way, authorize re-authorizes the peer on a live session, narrower or wider, on every version, whether or not it speaks AUTH.

Every token the peer presents is one kind of Request, answered on the same queue, wherever it rode: its own AUTH stream, or a moq-transport AUTHORIZATION TOKEN on a request. Requests naming the same token on one session share its verification and lifetime. The session enforces each grant it issues. A request that carried a token is held to that token’s grant alone and ends with it; any other request is held to the session’s scope, which a token carried by a request never joins.

Older moq-lite versions and moq-transport carry no AUTH exchange: there the grant stays None. On moq-transport a Credential is still answered, with a grant that stays unknown, since a request that names it carries its token; on moq-lite without AUTH its answer is Error::Unsupported. moq-lite carries a grant’s prefixes as they are, and refuses one too large for a single AUTH_OK rather than trim it.

Structs§

Credential
One credential this side presented, returned by Handle’s add.
EmptyToken
An empty token, which presents no credential.
Grant
What a peer lets this side do, in this side’s own paths.
Handle
The tokens this side presents and the grant they earn, across every session built on it.
Issued
A grant issued to one of the peer’s tokens, which the session enforces. Dropping it ends the grant: an AUTH token’s leaves the scope, and a request’s token ends the request.
Request
A token the peer presented, waiting for an answer.
Requests
The tokens the peer presents, for an application that answers them itself.
Token
A credential to present when dialing, such as a JWT.
Tokens
The tokens a connection presents on every session it dials, and the peer’s answer to them.
Watch
Watches a grant: the live session’s union, or one credential’s.