Skip to main content

TokenManager

Struct TokenManager 

Source
pub struct TokenManager { /* private fields */ }

Implementations§

Source§

impl TokenManager

Source

pub fn new(secret: &[u8], issuer: Option<String>) -> Self

Creates a TokenManager for symmetric signing (HS256).

Source

pub fn new_asymmetric( private_key_pem: &[u8], issuer: Option<String>, kid: Option<String>, ) -> Result<Self, AuthError>

Creates a TokenManager for asymmetric signing (RS256). private_key_pem must be a valid RSA private key in PEM format. OP/external verification should use this path; internal resource servers can continue to use new (HS256).

Source

pub fn public_jwk(&self) -> Option<Jwk>

Source

pub fn with_issuer(self, issuer: String) -> Self

Source

pub fn issue_user_token( &self, identity: Identity, expires_in_secs: u64, scope: Option<String>, aud: Option<String>, ) -> Result<String, AuthError>

Issues a token for a user identity.

Source

pub fn issue_user_token_with_extra( &self, identity: Identity, expires_in_secs: u64, scope: Option<String>, aud: Option<String>, extra: HashMap<String, Value>, ) -> Result<String, AuthError>

Issues a token for a user identity, stamping the given extra claims onto the token in addition to the standard/core claims.

This lets a host application (e.g. a resource server built on top of this engine) attach domain-specific claims — such as api_key_id, project_id, or roles — so downstream consumers (an API gateway or authorization proxy) can read them directly off the token without a database round-trip. Keys in extra take precedence over any same-named field set elsewhere in extra by this method; they cannot override the top-level standard claims (sub, aud, exp, etc.) since those are not part of the flattened map.

Source

pub fn issue_id_token( &self, identity: Identity, client_id: &str, nonce: Option<String>, expires_in_secs: u64, ) -> Result<String, AuthError>

Issues an OIDC-conformant ID token.

Source

pub fn issue_id_token_with_extra( &self, identity: Identity, client_id: &str, nonce: Option<String>, expires_in_secs: u64, extra: HashMap<String, Value>, ) -> Result<String, AuthError>

Issues an OIDC-conformant ID token, stamping the given extra claims onto the token in addition to the standard/core claims.

nonce is a reserved claim key: extra is merged into the token first, then the explicit nonce parameter is applied on top. So if nonce is Some(_), it always wins over any "nonce" entry passed in extra. If nonce is None, an extra["nonce"] value (if any) is left as-is. This preserves OIDC nonce semantics — it reflects what the client sent in the authorization request — and keeps it from being accidentally clobbered by unrelated custom claims.

Source

pub fn issue_client_token( &self, client_id: &str, expires_in_secs: u64, scope: Option<String>, aud: Option<String>, ) -> Result<String, AuthError>

Issues a machine-to-machine (M2M) token for a client.

Source

pub fn issue_client_token_with_extra( &self, client_id: &str, expires_in_secs: u64, scope: Option<String>, aud: Option<String>, extra: HashMap<String, Value>, ) -> Result<String, AuthError>

Issues a machine-to-machine (M2M) token for a client, stamping the given extra claims onto the token in addition to the standard/core claims. See Self::issue_user_token_with_extra for the rationale.

Source

pub fn issue_custom_token( &self, sub: String, expires_in_secs: u64, typ: &str, extra: HashMap<String, Value>, ) -> Result<String, AuthError>

Issues a token with an explicit typ header and no aud, for callers minting something that is not a standard OIDC ID/access/user token and needs its own wire-format typ so verifiers can tell it apart from those (e.g. authkestra-op’s device/service attestations, whose contract requires typ: "webank-attest+jws" rather than the default "JWT"). Additive alongside the issue_*_token* family above; those are unchanged.

Source

pub fn validate_token( &self, token: &str, expected_aud: Option<&str>, ) -> Result<Claims, AuthError>

Trait Implementations§

Source§

impl Clone for TokenManager

Source§

fn clone(&self) -> TokenManager

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

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