macro_rules! scope {
    ($($token:literal),+ $(,)?) => { ... };
    ($($token:expr),+ $(,)?) => { ... };
    () => { ... };
}
Expand description

Construct a scope from a list of tokens.

use aliri_oauth2::scope;

let scope = scope!["users.read", "users.update", "users.list"];

This is equivalent to the following:

use aliri_oauth2::{oauth2, Scope};

let scope = Scope::empty()
    .and(oauth2::ScopeToken::from_static("users.read"))
    .and(oauth2::ScopeToken::from_static("users.update"))
    .and(oauth2::ScopeToken::from_static("users.list"));

Panics

This macro will attempt to convert all the passed in string literals into tokens using ScopeToken::from_static which will panic if any are invalid.

use aliri_oauth2::scope;

let scope = scope!["users read", "users.update", "users.list"];

Errors

If the values passed in are not literals, then the tokens will be parsed at runtime, and any errors will be propagated back to the caller.

use aliri_oauth2::scope;

let scope = scope![String::from("users.read")].unwrap();
assert!(scope![String::from("users read")].is_err());