Skip to main content

ClientCredentialsFlow

Struct ClientCredentialsFlow 

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

Orchestrates the Client Credentials Flow (RFC 6749 Section 4.4).

This flow is used by clients to obtain an access token outside of the context of a user. This is typically used for client-to-client communication.

Implementations§

Source§

impl ClientCredentialsFlow

Source

pub fn new(client_id: String, client_secret: String, token_url: String) -> Self

Creates a new ClientCredentialsFlow instance authenticating with a shared client_secret (RFC 6749 §2.3.1).

§Arguments
  • client_id - The client ID assigned to the client.
  • client_secret - The client secret assigned to the client.
  • token_url - The URL of the token endpoint.
Source

pub fn new_private_key_jwt( client_id: String, signing_key: EncodingKey, alg: Algorithm, token_url: String, ) -> Self

Creates a new ClientCredentialsFlow instance authenticating with private_key_jwt (RFC 7523 §2.2) instead of a shared secret.

Use this when the client cannot hold a shared secret at all — e.g. a backend service that only ever authenticates from a keystore holding an asymmetric keypair, with just the public half registered against this client_id at the authorization server. get_token mints a fresh assertion JWT (iss/sub = client_id, aud = token_url, a new jti, and exp bounded by crate::client_assertion::MAX_CLIENT_ASSERTION_LIFETIME_SECS) on every call and sends it as client_assertion alongside client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer, in place of client_secret.

§Arguments
  • client_id - The client ID assigned to the client.
  • signing_key - The private key to sign assertions with. Must match alg (e.g. an Ed25519 key for Algorithm::EdDSA).
  • alg - The signature algorithm signing_key signs with. This crate’s own OP (authkestra_op::client_assertion) derives the algorithm it will accept from the client’s registered public key, never from this header, so alg here must agree with whatever key type was registered.
  • token_url - The URL of the token endpoint; also the aud claim minted into every assertion.
Source

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

Stamps kid onto the header of every assertion minted by private_key_jwt authentication, so a server with several keys registered for this client can tell which one signed it (see authkestra_op::client_assertion::select_key).

A no-op when this flow was constructed via Self::new — there is no assertion to stamp a kid onto when authenticating with a shared secret.

Source

pub async fn get_token( &self, scopes: Option<&[&str]>, ) -> Result<OAuthToken, AuthError>

Obtains an access token using the client credentials.

§Arguments
  • scopes - An optional list of scopes to request.
§Returns

A Result containing the OAuthToken if successful, or an AuthError otherwise.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, <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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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