pub trait Scopes<Request: WebRequest> {
    // Required method
    fn scopes(&mut self, request: &mut Request) -> &[Scope];
}
Expand description

Determine the scopes applying to a request of a resource.

It is possible to use a slice of Scopes as an implementation of this trait. You can inspect the request that was used to access the resource for which the scopes are to be determined but should generally avoid doing so. Sometimes the scope depends on external parameters and this is unavoidable, e.g. if the scope is created dynamically from the path of the resource.

Example

Here’s a possible new implementation that allows you to update your scope list at runtime:

use oxide_auth::primitives::scope::Scope;
use std::sync::{Arc, RwLock};

struct MyScopes {
    update: RwLock<Arc<[Scope]>>,
    current: Arc<[Scope]>,
};

impl<R: WebRequest> Scopes<R> for MyScopes {
    fn scopes(&mut self, _: &mut R) -> &[Scope] {
        let update = self.update.read().unwrap();
        if !Arc::ptr_eq(&update, &self.current) {
            self.current = update.clone();
        }
        &self.current
    }
}

Required Methods§

source

fn scopes(&mut self, request: &mut Request) -> &[Scope]

A list of alternative scopes.

One of the scopes needs to be fulfilled by the access token in the request to grant access. A scope is fulfilled if the set of its part is a subset of the parts in the grant. If the slice is empty, then no scope can be fulfilled and the request is always blocked.

Implementations on Foreign Types§

source§

impl<'a, W: WebRequest, S: Scopes<W> + 'a + ?Sized> Scopes<W> for &'a mut S

source§

fn scopes(&mut self, request: &mut W) -> &[Scope]

source§

impl<'a, W: WebRequest> Scopes<W> for &'a [Scope]

source§

fn scopes(&mut self, _: &mut W) -> &[Scope]

source§

impl<'a, W: WebRequest, S: Scopes<W> + 'a + ?Sized> Scopes<W> for Box<S>

source§

fn scopes(&mut self, request: &mut W) -> &[Scope]

source§

impl<W: WebRequest> Scopes<W> for [Scope]

source§

fn scopes(&mut self, _: &mut W) -> &[Scope]

source§

impl<W: WebRequest> Scopes<W> for Vec<Scope>

source§

fn scopes(&mut self, _: &mut W) -> &[Scope]

Implementors§