pub struct Scope {
pub root: String,
pub publish: Vec<String>,
pub subscribe: Vec<String>,
}Expand description
The immutable ceiling on what a key may grant, embedded in its JWK.
Paths in publish and subscribe are relative to root, matching token claim
semantics. A key signs a token only when every path the token grants sits at or
beneath one the scope allows, in the same role; see allows.
The scope is fixed at key generation. Widening it means minting a new key, which is the point: a leaked scoped key can never be talked into signing more than it already could. A key with no scope at all is unrestricted, so keys minted before scopes existed keep working.
Fields§
§root: StringThe root for the publish/subscribe prefixes below.
publish: Vec<String>Prefixes this key may grant to publishers.
subscribe: Vec<String>Prefixes this key may grant to subscribers.
Implementations§
Source§impl Scope
impl Scope
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Returns an error when the scope permits nothing, making the key unusable.
Sourcepub fn allows(&self, claims: &Claims) -> bool
pub fn allows(&self, claims: &Claims) -> bool
Whether every path claims grants is covered by this scope, per role.
Both sides are resolved against their own root before comparing, so the same
grant expressed as root: "demo" + put: ["room"] or as put: ["demo/room"]
is treated identically. Matching is segment-aware, so a scope of live does
not cover lively, and the roles are checked independently: a publish-only
scope never authorizes a subscribe grant.
An empty prefix covers everything beneath the scope root, so a scope of
root: "demo" + put: [""] grants publish anywhere under demo.