Struct TokenSigner

Source
pub struct TokenSigner { /* private fields */ }
Expand description

Signs grants instead of storing them.

Although this token instance allows preservation of memory it also implies that tokens, once issued, are impossible to revoke.

Implementations§

Source§

impl TokenSigner

Source

pub fn new(secret: Assertion) -> TokenSigner

Construct a signing instance from a private signing key.

Security notice: Never use a password alone to construct the signing key. Instead, generate a new key using a utility such as openssl rand that you then store away securely.

Source

pub fn ephemeral() -> TokenSigner

Construct a signing instance whose tokens only live for the program execution.

Useful for rapid prototyping where tokens need not be stored in a persistent database and can be invalidated at any time. This interface is provided with simplicity in mind, using the default system random generator (ring::rand::SystemRandom).

Source

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

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

This only affects tokens issued after this call. The default duration is 1 (ONE) hour for tokens issued for the authorization code grant method. For many users this may seem to short but should be secure-by-default. You may want to increase the duration, or instead use long lived refresh token instead (although you currently need to handle refresh tokens yourself, coming soonish).

Source

pub fn valid_for_default(&mut self)

Set all grants to be valid for their default duration.

This only affects tokens issued after this call. The default duration is 1 (ONE) hour for tokens issued for the authorization code grant method.

Source

pub fn generate_refresh_tokens(&mut self, refresh: bool)

Determine whether to generate refresh tokens.

By default, this option is off. Since the TokenSigner can on its own not revoke any tokens it should be considered carefullly whether to issue very long-living and powerful refresh tokens. On instance where this might be okay is as a component of a grander token architecture that adds a revocation mechanism.

Trait Implementations§

Source§

impl<'a> Issuer for &'a TokenSigner

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<'t>(&'t self, token: &'t str) -> Result<Option<Grant>, ()>

Get the values corresponding to a bearer token
Source§

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

Get the values corresponding to a refresh token
Source§

impl Issuer for TokenSigner

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§

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,