Skip to main content

RefreshTokenSource

Struct RefreshTokenSource 

Source
pub struct RefreshTokenSource<P: PasAuthPort, T: TokenStore, Sc: ConsentScopes> { /* private fields */ }
Expand description

A renewing TokenSource: mints access tokens via the OAuth refresh_token grant and persists the rotated refresh token through a TokenStore.

Depends on the PasAuthPort port (not the concrete AuthClient), so it is unit-tested against an in-memory adapter with no HTTP. Wire it into a ppoppo_sdk_core::token_cache::TokenCache so the cache renews on lapse.

§The scope parameter — a per-refresh check, not a construction-time one

Sc is the tier this credential is expected to carry. Every refresh validates the server’s scope echo against it (ensure_covers) before handing the access token back, so a grant that narrows mid-session — which OAuth 2.1 §1.3.2 explicitly permits — surfaces as a terminal error rather than as an unexplained 403 from the resource server later.

This is why the check lives here and not in a wrapper: TokenSource::fetch_token returns only (String, Duration), so nothing composed around this type can ever see the scope echo. The seam has to be inside.

That also makes ScopedTokenSource<Sc> a stronger witness than a construction-time check would be. The marker holds for every instance because the guarantee is intrinsic to use: any token this source yields has just been checked. new therefore needs no proof from its caller — there is no window in which an unchecked token escapes.

Implementations§

Source§

impl<P: PasAuthPort, T: TokenStore, Sc: ConsentScopes> RefreshTokenSource<P, T, Sc>

Source

pub fn new(auth: P, store: T) -> Self

auth performs the refresh grant (typically an AuthClient carrying the token endpoint + client_id + RFC 8707 resource); store holds the durable refresh token (seed it with the initial token first).

Sc is usually inferred from the surrounding binding; give it explicitly (RefreshTokenSource::<_, _, Notify>::new(..)) where it is not.

Most consumers do not call this directly — AuthClient cannot be constructed outside this crate, so a native client obtains a ready source from NativeAuthFlow::token_source or NativeAuthFlow::complete. This constructor is for consumers supplying their own PasAuthPort.

Trait Implementations§

Source§

impl<P: PasAuthPort, T: TokenStore, Sc: ConsentScopes> Debug for RefreshTokenSource<P, T, Sc>

Source§

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

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

impl<P: PasAuthPort, T: TokenStore, Sc: ConsentScopes> ScopedTokenSource<Sc> for RefreshTokenSource<P, T, Sc>

The witness: every token this source yields has passed ensure_covers against Sc. See the type’s docs for why the guarantee attaches to use rather than construction.

Source§

impl<P: PasAuthPort, T: TokenStore, Sc: ConsentScopes> TokenSource for RefreshTokenSource<P, T, Sc>

Source§

fn fetch_token<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(String, Duration), TokenCacheError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Fetch a fresh token. Returns the raw JWT string and its lifetime. The cache subtracts TokenCacheConfig::refresh_skew from the TTL before storing the expiry, so the token is treated as stale slightly before the server considers it expired.

Auto Trait Implementations§

§

impl<P, T, Sc> Freeze for RefreshTokenSource<P, T, Sc>
where P: Freeze, T: Freeze,

§

impl<P, T, Sc> RefUnwindSafe for RefreshTokenSource<P, T, Sc>

§

impl<P, T, Sc> Send for RefreshTokenSource<P, T, Sc>

§

impl<P, T, Sc> Sync for RefreshTokenSource<P, T, Sc>

§

impl<P, T, Sc> Unpin for RefreshTokenSource<P, T, Sc>
where P: Unpin, T: Unpin, Sc: Unpin,

§

impl<P, T, Sc> UnsafeUnpin for RefreshTokenSource<P, T, Sc>
where P: UnsafeUnpin, T: UnsafeUnpin,

§

impl<P, T, Sc> UnwindSafe for RefreshTokenSource<P, T, Sc>
where P: UnwindSafe, T: UnwindSafe, Sc: UnwindSafe,

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