Trait oxide_auth::endpoint::Scopes
source · 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 Scope
s 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§
sourcefn scopes(&mut self, request: &mut Request) -> &[Scope]
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.