#[non_exhaustive]pub struct Claims {
pub root: String,
pub publish: Vec<String>,
pub subscribe: Vec<String>,
pub expires: Option<SystemTime>,
pub issued: Option<SystemTime>,
}Expand description
The payload of a token: a root, plus the publish/subscribe prefixes granted beneath it.
Build one from Default with the with_* setters, sign it with
Key::sign, and scope it to a connection with
authorize.
let claims = moq_token::Claims::default()
.with_root("room/123")
.with_publish(["alice"])
.with_subscribe([""]);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.root: StringThe root for the publish/subscribe options below. It’s mostly for compression and is optional, defaulting to the empty string.
publish: Vec<String>If specified, the user can publish any matching broadcasts. If not specified, the user will not publish any broadcasts.
subscribe: Vec<String>If specified, the user can subscribe to any matching broadcasts. If not specified, the user will not receive announcements and cannot subscribe to any broadcasts.
expires: Option<SystemTime>The expiration time of the token as a unix timestamp.
issued: Option<SystemTime>The issued time of the token as a unix timestamp.
Implementations§
Source§impl Claims
impl Claims
Sourcepub fn with_root(self, root: impl Into<String>) -> Self
pub fn with_root(self, root: impl Into<String>) -> Self
Set the root that the publish/subscribe prefixes are relative to.
Sourcepub fn with_publish(
self,
paths: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_publish( self, paths: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Grant publish access to these prefixes, relative to the root.
Sourcepub fn with_subscribe(
self,
paths: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_subscribe( self, paths: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Grant subscribe access to these prefixes, relative to the root.
Sourcepub fn with_expires(self, at: impl Into<Option<SystemTime>>) -> Self
pub fn with_expires(self, at: impl Into<Option<SystemTime>>) -> Self
Expire the token at this time. Enforced by Key::verify.
Accepts an Option so a caller can pass one through without unwrapping it.
Sourcepub fn with_issued(self, at: impl Into<Option<SystemTime>>) -> Self
pub fn with_issued(self, at: impl Into<Option<SystemTime>>) -> Self
Record when the token was issued. Purely informational; nothing enforces it.
Accepts an Option so a caller can pass one through without unwrapping it.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Returns an error when the token grants nothing at all, making it useless.
The access these claims grant at path, rebased so each returned prefix is
relative to path.
path and root must overlap, in either direction:
pathextends the root (rootdemo, pathdemo/room), so the extraroomnarrows each prefix and drops the ones outside it.pathis a parent of the root (rootdemo, path ``), sodemois prepended to each prefix to keep it anchored where the token points.
Matching is segment-aware, so a root of foo does not cover foobar.
Slashes at the boundaries are implicit: /demo/ and demo are the same path.
Returns Error::RootMismatch when the two don’t
overlap, and Error::NoAccess when they do but every
prefix falls outside path.
This is authorization only. Verify the signature first with
Key::verify, which is where expiry is enforced.