Struct TokenMap

Source
pub struct TokenMap<G: TagGrant = Box<dyn TagGrant + Send + Sync + 'static>> { /* private fields */ }
Expand description

Keeps track of access and refresh tokens by a hash-map.

The generator is itself trait based and can be chosen during construction. It is assumed to not be possible (or at least very unlikely during their overlapping lifetime) for two different grants to generate the same token in the grant tagger.

Implementations§

Source§

impl<G: TagGrant> TokenMap<G>

Source

pub fn new(generator: G) -> Self

Construct a TokenMap from the given generator.

Source

pub fn valid_for(&mut self, duration: Duration)

Set the validity of all issued grants to the specified duration.

Source

pub fn valid_for_default(&mut self)

All grants are valid for their default duration.

Source

pub fn revoke(&mut self, token: &str)

Unconditionally delete grant associated with the token.

This is the main advantage over signing tokens. By keeping internal state of allowed grants, the resource owner or other instances can revoke a token before it expires naturally. There is no differentiation between access and refresh tokens since these should have a marginal probability of colliding.

Source

pub fn import_grant(&mut self, token: String, grant: Grant)

Directly associate token with grant.

No checks on the validity of the grant are performed but the expiration time of the grant is modified (if a duration was previously set).

Trait Implementations§

Source§

impl<G: TagGrant> Issuer for TokenMap<G>

Source§

fn issue(&mut self, grant: Grant) -> Result<IssuedToken, ()>

Create a token authorizing the request parameters
Source§

fn refresh(&mut self, refresh: &str, grant: Grant) -> Result<RefreshedToken, ()>

Refresh a token.
Source§

fn recover_token<'a>(&'a self, token: &'a str) -> Result<Option<Grant>, ()>

Get the values corresponding to a bearer token
Source§

fn recover_refresh<'a>(&'a self, token: &'a str) -> Result<Option<Grant>, ()>

Get the values corresponding to a refresh token

Auto Trait Implementations§

§

impl<G> Freeze for TokenMap<G>
where G: Freeze,

§

impl<G> RefUnwindSafe for TokenMap<G>
where G: RefUnwindSafe,

§

impl<G> Send for TokenMap<G>
where G: Send,

§

impl<G> Sync for TokenMap<G>
where G: Sync,

§

impl<G> Unpin for TokenMap<G>
where G: Unpin,

§

impl<G> UnwindSafe for TokenMap<G>
where G: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OptIssuer for T
where T: Issuer,

Source§

fn opt_mut(&mut self) -> Option<&mut dyn Issuer>

Reference this mutably as an Issuer or Option::None.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,