Struct oxide_auth::primitives::scope::Scope[][src]

pub struct Scope { /* fields omitted */ }
Expand description

Scope of a given grant or resource, a set of scope-tokens separated by spaces.

Scopes are interpreted as a conjunction of scope tokens, i.e. a scope is fulfilled if all of its scope tokens are fulfilled. This induces a partial ordering on scopes where scope A is less or equal than scope B if all scope tokens of A are also found in B. This can be interpreted as the rule

A token with scope B is allowed to access a resource requiring scope A iff A <= B

Example

let grant_scope    = "some_scope other_scope".parse::<Scope>().unwrap();
let resource_scope = "some_scope".parse::<Scope>().unwrap();
let uncomparable   = "some_scope third_scope".parse::<Scope>().unwrap();

// Holding a grant with `grant_scope` allows access to the resource since:
assert!(resource_scope <= grant_scope);
assert!(resource_scope.allow_access(&grant_scope));

// But holders would not be allowed to access another resource with scope `uncomparable`:
assert!(!(uncomparable <= grant_scope));
assert!(!uncomparable.allow_access(&grant_scope));

// This would also not work the other way around:
assert!(!(grant_scope <= uncomparable));
assert!(!grant_scope.allow_access(&uncomparable));

Scope-tokens are restricted to the following subset of ascii:

  • The character ‘!’
  • The character range ‘\x32’ to ‘\x5b’ which includes numbers and upper case letters
  • The character range ‘\x5d’ to ‘\x7e’ which includes lower case letters Individual scope-tokens are separated by spaces.

In particular, the characters ‘\x22’ (") and ‘\x5c’ (\) are not allowed.

Implementations

Determines if this scope has enough privileges to access some resource requiring the scope on the right side. This operation is equivalent to comparison via >=.

Determines if a resouce protected by this scope should allow access to a token with the grant on the right side. This operation is equivalent to comparison via <=.

Create an iterator over the individual scopes.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.