Skip to main content

TokenExchangeRequest

Struct TokenExchangeRequest 

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

The parameters of one RFC 8693 token exchange request (RFC 8693 §2.1).

Build one with TokenExchangeRequest::new, which takes the two REQUIRED parameters, then chain the optional ones. Supplying only the subject token requests an impersonation token; adding actor_token makes it a delegation exchange (RFC 8693 §1.1).

Debug redacts the subject and actor tokens so they cannot leak into logs (#24); their presence is still visible.

use rs_identity_model::{TokenExchangeRequest, TOKEN_TYPE_ACCESS_TOKEN, TOKEN_TYPE_JWT};

// Delegation: an actor acting on behalf of the subject, scoped to one API.
let request = TokenExchangeRequest::new("subject.tok", TOKEN_TYPE_ACCESS_TOKEN)
    .actor_token("actor.tok", TOKEN_TYPE_JWT)
    .audience("https://api.example.com")
    .scope("https://api.example.com/read");

Implementations§

Source§

impl TokenExchangeRequest

Source

pub fn new( subject_token: impl Into<String>, subject_token_type: impl Into<String>, ) -> Self

Starts an impersonation exchange of subject_token, whose type is named by subject_token_type — one of the TOKEN_TYPE_URIS (RFC 8693 §3). Both are REQUIRED (RFC 8693 §2.1).

Source

pub fn actor_token( self, token: impl Into<String>, token_type: impl Into<String>, ) -> Self

Attaches the acting party’s token, turning the request into a delegation exchange (RFC 8693 §1.1, §2.1). token_type is one of the TOKEN_TYPE_URIS and is REQUIRED whenever an actor token is present.

Both arguments must be non-empty: an empty one is rejected when the exchange is validated, so an accidental empty actor token cannot quietly turn a delegation into an impersonation. Simply do not call this method to request impersonation.

Source

pub fn requested_token_type(self, uri: impl Into<String>) -> Self

Names the desired type of the issued token (RFC 8693 §2.1). The server MAY issue a different type, which it reports in issued_token_type.

Source

pub fn scope(self, scope: impl Into<String>) -> Self

Requests scope, sent as a single space-delimited scope parameter (RFC 6749 §3.3). When unset, no scope parameter is sent.

Source

pub fn resource(self, resource: impl Into<String>) -> Self

Adds a target resource URI (RFC 8693 §2.1). resource MAY appear more than once, so repeated calls accumulate rather than replace.

Source

pub fn audience(self, audience: impl Into<String>) -> Self

Adds a target audience (RFC 8693 §2.1). audience MAY appear more than once, so repeated calls accumulate rather than replace.

Trait Implementations§

Source§

impl Clone for TokenExchangeRequest

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 TokenExchangeRequest

Source§

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

Formats the value using the given formatter. 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> 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> 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 = !

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