Skip to main content

StaticTokenMatch

Struct StaticTokenMatch 

Source
#[non_exhaustive]
pub struct StaticTokenMatch { /* private fields */ }
Expand description

Which StaticTokens entry accepted a request: returned by authenticate_with_static_tokens next to Credential::StaticToken, and inserted into request extensions by the layers (features axum and tower) whenever they insert Credential::StaticToken — with the axum feature it is also an extractor. It carries the entry’s label only; nothing in it exposes the secret.

A layer configured with a single static_token inserts one too, with no label.

Implementations§

Source§

impl StaticTokenMatch

Source

pub fn label(&self) -> Option<&str>

The matched entry’s label, as given to StaticTokens::with; None for an unlabeled entry.

Trait Implementations§

Source§

impl Clone for StaticTokenMatch

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StaticTokenMatch

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for StaticTokenMatch

Source§

impl<S: Send + Sync> FromRequestParts<S> for StaticTokenMatch

Available on crate feature axum only.

Extracts which static token an AuthLayer accepted — its label, for an audit log or a per-client decision.

Refuses, fail-closed, exactly as the AuthorizedToken extractor does: with the layer’s own 401 and WWW-Authenticate challenge when the layer inserted none (an OAuth token was accepted, or an optional or allow_unauthenticated layer passed the request through), logged at error when the layer has no static token at all, and with 500 (logged at error) on a route no AuthLayer covers. The layer inserts one next to every Credential::StaticToken — unlabeled for a single static_token — and removes an outer layer’s whenever it accepts an OAuth token, so it always describes the innermost accepted Credential.

§Examples

use axum::{Router, routing::get};
use oauth_resource_server::StaticTokenMatch;

async fn audit(matched: StaticTokenMatch) -> String {
    format!("static key {:?}", matched.label())
}
Source§

type Rejection = Response<Body>

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

async fn from_request_parts( parts: &mut Parts, _state: &S, ) -> Result<Self, Response>

Perform the extraction.
Source§

impl<S: Send + Sync> OptionalFromRequestParts<S> for StaticTokenMatch

Available on crate feature axum only.

Option<StaticTokenMatch>: None when an AuthLayer ran and accepted no static token (an OAuth token was accepted, or nothing was presented to an optional or allow_unauthenticated layer). On a route no AuthLayer covers it still refuses with 500, logged at error, rather than reading as anonymous.

Source§

type Rejection = Response<Body>

If the extractor fails, it will use this “rejection” type. Read more
Source§

async fn from_request_parts( parts: &mut Parts, _state: &S, ) -> Result<Option<Self>, Response>

Perform the extraction.
Source§

impl PartialEq for StaticTokenMatch

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for StaticTokenMatch

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<S, T> FromRequest<S, ViaParts> for T
where S: Send + Sync, T: FromRequestParts<S>,

Source§

type Rejection = <T as FromRequestParts<S>>::Rejection

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>

Perform the extraction.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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