Skip to main content

TokenDelegateHook

Struct TokenDelegateHook 

Source
pub struct TokenDelegateHook;
Expand description

Token-delegation hook.

Payload (DelegationPayload) — unified input + accumulator. The outbound caller (typically a forwarding-proxy plugin) populates the input fields (bearer_token, target_name, target_audience, required_permissions, …) and invokes the hook; handlers populate the output fields (delegated_token, delegation_update, metadata) on clones of the running payload. Input fields are private and read through accessors — handlers cannot mutate them even on a clone, so the delegation context is canonical across the chain.

Result (PluginResult<DelegationPayload>) — the executor’s standard envelope. modified_payload carries the updated payload. continue_processing = false halts the pipeline (handler decided no credential can be minted — e.g. the inbound token’s scopes don’t cover the target’s required permissions).

Threading. Sequential-phase semantics already thread handler N’s modified_payload into handler N+1’s input, so the chain’s natural behavior is “each handler sees the prior handler’s contributions in the running payload.” Most deployments will register exactly one TokenDelegate handler (RFC 8693 exchanger, UCAN minter, …), but chaining works for hybrid setups — e.g. a passthrough fallback that fires only when the primary exchanger declined.

Handler signature:

impl HookHandler<TokenDelegateHook> for RfcExchanger {
    async fn handle(
        &self,
        payload: &DelegationPayload,
        _ext: &Extensions,
        _ctx: &mut PluginContext,
    ) -> PluginResult<DelegationPayload> {
        let minted = self
            .exchange(payload.bearer_token(), payload.target_audience())
            .await?;
        let mut updated = payload.clone();
        updated.delegated_token = Some(minted);
        PluginResult::modify_payload(updated)
    }
}

Registration: manager.register_handler_for_names::<TokenDelegateHook, _>(plugin, config, &["token.delegate"]). register_handler::<TokenDelegateHook, _> alone registers under the marker’s NAME (“token”) which is the hook family, not the specific hook name — register_handler_for_names (or the unified-name path) is the right call.

Trait Implementations§

Source§

impl HookTypeDef for TokenDelegateHook

Source§

const NAME: &'static str = "token.delegate"

Hook name — used as the registry key and in config YAML. Read more
Source§

type Payload = DelegationPayload

The typed payload that handlers receive. Must implement PluginPayload (Clone + Send + Sync + ’static).
Source§

type Result = PluginResult<DelegationPayload>

The typed result that handlers return.

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> 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, 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