Skip to main content

TokenRequestContext

Struct TokenRequestContext 

Source
#[non_exhaustive]
pub struct TokenRequestContext<'a> { pub credential: ClientCredential<'a>, pub resources: &'a [String], pub authorization_details: Option<&'a str>, pub dpop_proof: Option<&'a str>, }
Expand description

Everything about a token request that is not part of the grant itself.

Passed by reference to AuthorizationServer::token_with_context. Growing this struct is cheap; growing TokenRequest is not, because a host copies that around and tests/allocation.rs holds it to a size budget. #[non_exhaustive]: rar and dpop each add a field, and this is the type a host assembles on EVERY token request, so it is the single most likely struct literal in a host’s codebase and the most expensive one to break. “Growing this struct is cheap” above is only true while growing it is not a semver-major change, which is what the attribute buys.

Build it with TokenRequestContext::new and assign what the request carried; Default is still there for a request with no credential at all, though the credential is the one thing every request has an answer for, which is why it is the constructor’s only argument.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§credential: ClientCredential<'a>

How the client is authenticating.

§resources: &'a [String]

The RFC 8707 resource parameters, in wire order.

§authorization_details: Option<&'a str>

The RFC 9396 authorization_details parameter, raw and unparsed.

Here rather than on each TokenRequest variant for the reason resources is here: section 6 defines it as a parameter of the token REQUEST, independent of grant_type. What it MEANS does depend on the grant, and section 6 is what decides: authorization_code and refresh_token may narrow what the authorization request obtained and never widen it; client_credentials has no prior authorization request, so its details are checked against the supported types and used; and the device grant refuses any at all, because the RFC 8628 section 3.1 request cannot carry them in this crate and so granted nothing for a poll to narrow to.

NOT FEATURE GATED, for the reason crate::authorization::AuthorizationRequest::authorization_details is not: a build without rar still has to be TOLD the parameter arrived, because refusing it is what RFC 9396 section 5 requires of exactly that build. Setting it in such a build makes the request an error rather than making the field meaningless.

§dpop_proof: Option<&'a str>
Available on crate feature dpop only.

The RFC 9449 DPoP request header, verbatim and unparsed.

None means the client sent none, which is refused only when ServerConfig::require_dpop is set. When it is present and valid, the issued token is BOUND to the proof’s key: token_type becomes DPoP and RFC 7662 introspection reports cnf.jkt.

Implementations§

Source§

impl<'a> TokenRequestContext<'a>

Source

pub fn new(credential: ClientCredential<'a>) -> Self

The context of a request that carried nothing but its client authentication, which is every request in a deployment that has enabled none of the parameters the other fields exist for.

The RFC 8707 resource list, the RFC 9396 authorization_details and the RFC 9449 DPoP header are public fields on the returned value, so a host’s token endpoint reads as the sequence of parameters it actually found on the wire.

Source

pub fn with_resources(self, resources: &'a [String]) -> Self

The RFC 8707 resource parameters the request carried, in wire order.

Source

pub fn with_authorization_details(self, authorization_details: &'a str) -> Self

The RFC 9396 authorization_details parameter, raw and unparsed. Available in every build: without rar what it buys is a REFUSAL rather than a grant, which is what RFC 9396 section 5 asks of a server that supports no detail type.

Source

pub fn with_dpop_proof(self, dpop_proof: &'a str) -> Self

Available on crate feature dpop only.

The RFC 9449 DPoP request header, verbatim.

Trait Implementations§

Source§

impl<'a> Clone for TokenRequestContext<'a>

Source§

fn clone(&self) -> TokenRequestContext<'a>

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<'a> Copy for TokenRequestContext<'a>

Source§

impl<'a> Debug for TokenRequestContext<'a>

Source§

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

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

impl<'a> Default for TokenRequestContext<'a>

Source§

fn default() -> TokenRequestContext<'a>

Returns the “default value” for a type. Read more

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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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

Source§

type Output = T

Should always be Self
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 = 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.