[][src]Struct aliri_oauth2::ScopesPolicy

pub struct ScopesPolicy { /* fields omitted */ }

An access policy based on OAuth2 scopes

This access policy takes the form of alternatives around required scopes. This policy will allow access if any of the alternatives would allow access. If the policy contains no alternatives, the default effect is to deny access.

Examples

Deny all requests

use aliri::Policy;
use aliri_oauth2::{Scopes, ScopesPolicy};

let policy = ScopesPolicy::deny_all();

let request = Scopes::single("admin");
assert!(policy.evaluate(&request).is_err());

Allow all requests

use aliri::Policy;
use aliri_oauth2::{Scopes, ScopesPolicy};

let policy = ScopesPolicy::allow_all();

let request = Scopes::empty();
assert!(policy.evaluate(&request).is_ok());

Allow requests with a single scope

use aliri::Policy;
use aliri_oauth2::{Scopes, ScopesPolicy};

let policy = ScopesPolicy::allow_one(
    Scopes::single("admin")
);

let request = Scopes::from_scopes(vec![
    "admin",
    "user",
]);
assert!(policy.evaluate(&request).is_ok());

let user_request = Scopes::from_scopes(vec![
    "user",
]);
assert!(policy.evaluate(&user_request).is_err());

Allow requests with multiple potential sets of scopes

use aliri::Policy;
use aliri_oauth2::{Scopes, ScopesPolicy};

let mut policy = ScopesPolicy::deny_all();
policy.allow(Scopes::single("admin"));
policy.allow(Scopes::from_scopes(vec![
    "special",
    "user",
]));

let admin_request = Scopes::from_scopes(vec![
    "admin",
]);
assert!(policy.evaluate(&admin_request).is_ok());

let user_request = Scopes::from_scopes(vec![
    "user",
]);
assert!(policy.evaluate(&user_request).is_err());

let special_user_request = Scopes::from_scopes(vec![
    "special",
    "user",
]);
assert!(policy.evaluate(&special_user_request).is_ok());

Implementations

impl ScopesPolicy[src]

pub fn deny_all() -> Self[src]

Constructs a policy that has no permissible alternatives

By default, this policy will deny all requests

pub fn allow_all() -> Self[src]

Constructs a policy that does not require any scopes (allow)

pub fn allow_one(scopes: Scopes) -> Self[src]

Constructs a policy that requires this set of scopes

pub fn allow(&mut self, scopes: Scopes)[src]

Add an alternative set of required scopes

Trait Implementations

impl Clone for ScopesPolicy[src]

impl Debug for ScopesPolicy[src]

impl Default for ScopesPolicy[src]

impl Eq for ScopesPolicy[src]

impl Extend<Scopes> for ScopesPolicy[src]

impl FromIterator<Scopes> for ScopesPolicy[src]

impl IntoIterator for ScopesPolicy[src]

type Item = Scopes

The type of the elements being iterated over.

type IntoIter = <Vec<Scopes> as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?

impl<'a> IntoIterator for &'a ScopesPolicy[src]

type Item = &'a Scopes

The type of the elements being iterated over.

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?

impl PartialEq<ScopesPolicy> for ScopesPolicy[src]

impl Policy for ScopesPolicy[src]

type Request = Scopes

The request type evaluated by this policy

type Denial = InsufficientScopes

The error returned when this policy denies a request

impl StructuralEq for ScopesPolicy[src]

impl StructuralPartialEq for ScopesPolicy[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> WithSubscriber for T[src]