Skip to main content

BearerAuthenticator

Enum BearerAuthenticator 

Source
pub enum BearerAuthenticator {
    Ephemeral {
        user_key_pair: KeyPair,
        cache: Mutex<HashMap<LexeScope, TokenWithExpiration>>,
    },
    Static {
        token: BearerAuthToken,
        scope: LexeScope,
    },
}
Expand description

Hands out fresh BearerAuthTokens for a given LexeScope, caching them until they expire. See the module docs for the two variants.

Variants§

§

Ephemeral

Our standard authenticator, which mints a fresh short-lived token whenever the cached one for a given scope expires.

Fields

§user_key_pair: KeyPair

The ed25519::KeyPair for the UserPk, used to authenticate with the lexe backend.

§cache: Mutex<HashMap<LexeScope, TokenWithExpiration>>

The latest fresh token for each LexeScope we’ve requested, behind a tokio mutex so that at most one task auths at a time.

§

Static

A single pre-minted, long-lived token of a fixed scope, which can serve any request whose scope it covers but cannot mint new tokens.

Fields

§token: BearerAuthToken

The fixed, long-lived auth token.

§scope: LexeScope

The scope that was passed in alongside the token when this BearerAuthenticator was created, i.e. the scope the caller expects was granted to the token. The actual authorization scope is ultimately determined by the verifying server.

Implementations§

Source§

impl BearerAuthenticator

Source

pub fn new(user_key_pair: KeyPair) -> Self

Create an Ephemeral authenticator that signs auth requests with user_key_pair and mints tokens on demand.

Source

pub fn new_static_token(token: BearerAuthToken, scope: LexeScope) -> Self

Create a Static authenticator that always returns the same long-lived token. Pass the scope that the token was granted.

Source

pub fn user_key_pair(&self) -> Option<&KeyPair>

Source

pub async fn get_token<T: BearerAuthBackendApi + ?Sized>( &self, api: &T, now: SystemTime, scope: LexeScope, ) -> Result<BearerAuthToken, BackendApiError>

Get a fresh token for the requested scope: either a still-fresh cached token, or a newly authenticated one (which is then cached).

Source

pub async fn get_token_with_exp<T: BearerAuthBackendApi + ?Sized>( &self, api: &T, now: SystemTime, scope: LexeScope, ) -> Result<TokenWithExpiration, BackendApiError>

get_token, but also returns the token’s expiration.

Source

pub async fn mint_long_lived_gateway_proxy_token<T>( &self, api: &T, now: SystemTime, ) -> Result<BearerAuthToken, BackendApiError>

Mint a fresh, long-lived LexeScope::GatewayProxy token, typically for use by a SDK client using client credentials.

Requires an Ephemeral authenticator; a Static one cannot mint new tokens.

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<F, T, U> Apply<F, U> for T
where F: FnOnce(T) -> U,

Source§

fn apply(self, f: F) -> U

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more