#[non_exhaustive]pub struct Claims {
pub root: String,
pub publish: Patterns,
pub subscribe: Patterns,
pub expires: Option<SystemTime>,
pub issued: Option<SystemTime>,
}Expand description
The payload of a token: a root, plus the publish/subscribe patterns granted beneath it.
Build one from Default with the with_* setters, sign it with
Key::sign, and scope it to a connection with
authorize. A pattern names exactly what it says: alice
is one broadcast, alice/** is a subtree, and ** is everything under the root.
let claims = moq_auth::Claims::default()
.with_root("room/123")
.with_publish(["alice/**".parse().unwrap()])
.with_subscribe(["**".parse().unwrap()]);Legacy moq-token claims are read too: each put/get prefix p is the subtree
p/**. Claims that only grant subtrees are written that way, so every published
verifier accepts them; anything else is written as publish/subscribe, which an
older verifier refuses rather than misreads. Any other field fails verification.
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 patterns below. It’s mostly for compression and is optional, defaulting to the empty string.
publish: PatternsIf specified, the user can publish any matching broadcasts. If not specified, the user will not publish any broadcasts.
subscribe: PatternsIf 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 (exp).
issued: Option<SystemTime>The issued time of the token as a unix timestamp (iat).
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 patterns are relative to.
Sourcepub fn with_publish(self, patterns: impl IntoIterator<Item = Pattern>) -> Self
pub fn with_publish(self, patterns: impl IntoIterator<Item = Pattern>) -> Self
Grant publish access to these patterns, relative to the root.
Sourcepub fn with_subscribe(self, patterns: impl IntoIterator<Item = Pattern>) -> Self
pub fn with_subscribe(self, patterns: impl IntoIterator<Item = Pattern>) -> Self
Grant subscribe access to these patterns, 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 pattern is
relative to path.
path and root must overlap, in either direction:
pathextends the root (rootdemo, pathdemo/room), so the extraroomnarrows each pattern and drops the ones outside it.pathis a parent of the root (rootdemo, path ``), sodemois prepended to each pattern 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
pattern falls outside path.
This is authorization only. Verify the signature first with
Key::verify, which is where expiry is enforced.