pub struct Scope {
pub root: String,
pub publish: Patterns,
pub subscribe: Patterns,
}Expand description
The immutable ceiling on what a key may grant, embedded in its JWK.
Patterns in publish and subscribe are relative to root, matching token claim
semantics. A key signs a token only when every pattern the token grants is
contained by 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.
Legacy put/get prefix scopes load as subtree patterns, and a scope that only
grants subtrees is written that way so older readers load it too.
Fields§
§root: StringThe root for the publish/subscribe patterns below.
publish: PatternsPatterns this key may grant to publishers.
subscribe: PatternsPatterns 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 pattern claims grants is covered by this scope, per role.
Both sides are placed beneath their own root before comparing, so the same
grant expressed as root: "demo" + publish: ["room/**"] or as
publish: ["demo/room/**"] is treated identically. Containment is per pattern,
so a scope of live/** does not cover lively/**, and the roles are checked
independently: a publish-only scope never authorizes a subscribe grant.
** covers everything beneath the scope root, so a scope of root: "demo" +
publish: ["**"] grants publish anywhere under demo.